Table of Contents

Class CraftingRecipeIngredient

Namespace
Vintagestory.API.Common
Assembly
VintagestoryAPI.dll

A crafting recipe ingredient Open in GitHub

[DocumentAsJson]
public class CraftingRecipeIngredient : IRecipeIngredient, IRecipeIngredientBase, IRecipeOutput, IByteSerializable, ICloneable
Inheritance
CraftingRecipeIngredient
Implements
Inherited Members
Extension Methods

Fields

ResolvedAttributes

public ITreeAttribute? ResolvedAttributes

Field Value

ITreeAttribute

defaultEmptyAttributes

public static ITreeAttribute defaultEmptyAttributes

Field Value

ITreeAttribute

resolvedItemStack

Only used if we have not de-duplicated this CraftingRecipeIngredient (e.g. for RightClickConstruction ingredients)

protected ItemStack? resolvedItemStack

Field Value

ItemStack

Properties

AllowedVariants

When using a wildcard in the item/block code, setting this field will limit the allowed variants

[DocumentAsJson("Optional", "Allow All", false)]
public string[]? AllowedVariants { get; set; }

Property Value

string[]

Attributes

What attributes this itemstack must have to be a valid ingredient

[JsonProperty]
[JsonConverter(typeof(JsonAttributesConverter))]
[DocumentAsJson("Optional", "None", false)]
public JsonObject? Attributes { get; set; }

Property Value

JsonObject

Break

Determines if and item will be destroyed when reaching zero durability.

[DocumentAsJson("Optional", "True", false)]
public bool Break { get; set; }

Property Value

bool

Code

The code of the item or block.

[DocumentAsJson("Optional", "All", false)]
public AssetLocation? Code { get; set; }

Property Value

AssetLocation

Consume

Defines if recipe ingredient should be consumed on crafting.
Is equal to 'not IsTool'. Use this property instead of 'IsTool'.

[DocumentAsJson("Optional", "True", false)]
public bool Consume { get; set; }

Property Value

bool

ConsumeProperties

public RecipeIngredientConsumeProperties ConsumeProperties { get; }

Property Value

RecipeIngredientConsumeProperties

DurabilityChange

Defines how item durability will be changed. Durability will be capped at maximum item durability, and wont reduce below 0, unless specific item class changes this behavior.

[DocumentAsJson("Optional", "-1", false)]
public int DurabilityChange { get; set; }

Property Value

int

Id

Is used to reference recipe ingredient in the recipe, for example to specify where to copy attributes from.
If not specified will be set to the index of this ingredient in the array (starting from 1), or key of this ingredient in the object.

[DocumentAsJson("Optional", "None", false)]
public string Id { get; set; }

Property Value

string

IsTool

Whether this crafting recipe ingredient should be regarded as a tool required to build this item. If true, the recipe will not consume the item but reduce its durability.

[DocumentAsJson("Optional", "False", false)]
public bool IsTool { get; set; }

Property Value

bool

IsWildCard

[Obsolete("Use MatchingType")]
public bool IsWildCard { get; set; }

Property Value

bool

MatchingType

Defines how Code will be used to match

public EnumRecipeMatchType MatchingType { get; set; }

Property Value

EnumRecipeMatchType

Name

Attaches a name to a wildcard in an ingredient. This is used to substitute the value into the output. Only required if using a wildcard.

[DocumentAsJson("Required", "", false)]
public string? Name { get; set; }

Property Value

string

Quantity

The quantity of the itemstack required for the recipe. Alias of StackSize.

[DocumentAsJson("Recommended", "1", false)]
public int Quantity { get; set; }

Property Value

int

RecipeAttributes

Optional attribute data that you can attach any data to. Used for some specific instances in code mods.

[JsonProperty]
[JsonConverter(typeof(JsonAttributesConverter))]
[DocumentAsJson("Optional", "None", false)]
public JsonObject? RecipeAttributes { get; set; }

Property Value

JsonObject

ResolvedItemStack

The itemstack made from Code, Quantity and Attributes, populated by the engine. For performance, consider referencing the ResolvedAttributes or Quantity of this CraftingRecipeIngredient instead of the Attributes or StackSize of the ResolvedItemStack, it may save having to clone the ResolvedItemStack

public ItemStack? ResolvedItemStack { get; set; }

Property Value

ItemStack

ReturnedStack

If set, the crafting recipe will give back the consumed stack to be player upon crafting. Can also be used to produce multiple outputs for a recipe.

[DocumentAsJson("Optional", "None", false)]
public JsonItemStack? ReturnedStack { get; set; }

Property Value

JsonItemStack

SkipVariants

When using a wildcard in the item/block code, setting this field will skip these variants

[DocumentAsJson("Optional", "Skip None", false)]
public string[]? SkipVariants { get; set; }

Property Value

string[]

StackSize

Amount of items in this stacks

[ProtoMember(3)]
[DocumentAsJson("Optional", "1", false)]
public int StackSize { get; set; }

Property Value

int

Tags

[DocumentAsJson("Optional", "None", false)]
public ComplexTagCondition<TagSet> Tags { get; set; }

Property Value

ComplexTagCondition<TagSet>

ToolDurabilityCost

If Consume is set to False, this is the durability cost when the recipe is created.

[DocumentAsJson("Optional", "1", false)]
public int ToolDurabilityCost { get; set; }

Property Value

int

Type

Is the itemstack an item or a block?

[DocumentAsJson("Recommended", "Block", false)]
public EnumItemClass Type { get; set; }

Property Value

EnumItemClass

Methods

CheckTags(ItemStack, CollectibleObject)

public virtual bool CheckTags(ItemStack inputStack, CollectibleObject collectible)

Parameters

inputStack ItemStack
collectible CollectibleObject

Returns

bool

CheckTags(ComplexTagCondition<TagSet>, ItemStack, CollectibleObject)

public static bool CheckTags(ComplexTagCondition<TagSet> tags, ItemStack inputStack, CollectibleObject collectible)

Parameters

tags ComplexTagCondition<TagSet>
inputStack ItemStack
collectible CollectibleObject

Returns

bool

Clone()

public virtual CraftingRecipeIngredient Clone()

Returns

CraftingRecipeIngredient

CloneTo(object)

protected virtual void CloneTo(object cloneTo)

Parameters

cloneTo object

CloneTo<TResult>()

[Obsolete("Use 'Clone()' instead")]
public TResult CloneTo<TResult>() where TResult : CraftingRecipeIngredient, new()

Returns

TResult

Type Parameters

TResult

FillPlaceHolder(string, string)

Replaces {key} placeholders with value in code an attributes

public virtual void FillPlaceHolder(string key, string value)

Parameters

key string
value string

FromBytes(BinaryReader, IWorldAccessor)

public virtual void FromBytes(BinaryReader reader, IWorldAccessor resolver)

Parameters

reader BinaryReader
resolver IWorldAccessor

GetConsumeProperties()

public virtual RecipeIngredientConsumeProperties GetConsumeProperties()

Returns

RecipeIngredientConsumeProperties

Resolve(IWorldAccessor, string)

For INPUT slots you should normally call the overload Resolve(IWorldAccessor world, string sourceForErrorLogging, IRecipeBase recipe) otherwise you risk this ingredient/recipe being missed in the Handbook and in grid crafting.
However, it's totally fine to use this overload for OUTPUT slots or for special situations (e.g. RightClickConstruction in the world)

public virtual bool Resolve(IWorldAccessor world, string sourceForErrorLogging)

Parameters

world IWorldAccessor
sourceForErrorLogging string

Returns

bool

Resolve(IWorldAccessor, string, IRecipeBase)

For INPUT ingredients this should be used in place of the overload Resolve(IWorldAccessor world, string sourceForErrorLogging), to make use of the de-duplication / fast-search system for ingredients, essential for GridRecipes in the Handbook and in the Crafting Grid

public virtual bool Resolve(IWorldAccessor world, string sourceForErrorLogging, IRecipeBase recipe)

Parameters

world IWorldAccessor
sourceForErrorLogging string
recipe IRecipeBase

Returns

bool

SatisfiesAsIngredient(ItemStack, bool)

public virtual bool SatisfiesAsIngredient(ItemStack inputStack, bool checkStackSize = true)

Parameters

inputStack ItemStack
checkStackSize bool

Returns

bool

ToBytes(BinaryWriter)

public virtual void ToBytes(BinaryWriter writer)

Parameters

writer BinaryWriter

ToString()

Returns a string that represents the current object.

public override string ToString()

Returns

string

A string that represents the current object.