Table of Contents

Class RecipeBase

Namespace
Vintagestory.API.Common
Assembly
VintagestoryAPI.dll

Creates a new base recipe type. Almost all recipe types extend from this. Open in GitHub

[DocumentAsJson]
public abstract class RecipeBase : IRecipeBase, IByteSerializable, IConcreteCloneable<RecipeBase>, ICloneable
Inheritance
RecipeBase
Implements
Derived
Inherited Members
Extension Methods

Fields

CollectiblePreSearchResultsCache

public static readonly CollectiblePreSearchResultsCache CollectiblePreSearchResultsCache

Field Value

CollectiblePreSearchResultsCache

Properties

AllowedVariants

If '{code}' is used in ingredient code, allowed variants for this code should be specified in this map

[DocumentAsJson("Optional", "None", false)]
public Dictionary<string, string[]> AllowedVariants { get; set; }

Property Value

Dictionary<string, string[]>

Attributes

Optional attribute data that you can attach any data to. Useful for code mods, but also required when using liquid ingredients.
See dough.json grid recipe file for example.

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

Property Value

JsonObject

AverageDurability

If true, the output item will have its durability averaged over the input items

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

Property Value

bool

CopyAttributesFrom

If set, it will copy over the itemstack attributes from given ingredient code

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

Property Value

string

Enabled

If set to false, the recipe will never be loaded. If loaded, you can use this field to disable recipes during runtime.

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

Property Value

bool

MergeAttributesFrom

Attributes from these ingredients will be merged into output itemstack

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

Property Value

string[]

Name

Adds a name to this. Used for logging, and determining helve hammer workability for smithing recipes. Recipes for repairing objects must contain 'repair' in the name.

[DocumentAsJson("Optional", "Asset Path", false)]
public AssetLocation? Name { get; set; }

Property Value

AssetLocation

RecipeId

The ID of the Automatically generated when the recipe is loaded.

public int RecipeId { get; set; }

Property Value

int

RecipeIngredients

public abstract IEnumerable<IRecipeIngredient> RecipeIngredients { get; }

Property Value

IEnumerable<IRecipeIngredient>

RecipeOutput

public abstract IRecipeOutput RecipeOutput { get; }

Property Value

IRecipeOutput

RequiresTrait

If set, only players with given trait can use this See config/traits.json for a list of traits.

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

Property Value

string

ShowInCreatedBy

Used by the handbook. If false, will not appear in the "Created by" section

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

Property Value

bool

SkipVariants

If '{code}' is used in ingredient code, skip variants for this code should be specified in this map

[DocumentAsJson("Optional", "None", false)]
public Dictionary<string, string[]> SkipVariants { get; set; }

Property Value

Dictionary<string, string[]>

Methods

AddVariantCombination(Dictionary<string, HashSet<string>>, Dictionary<string, string>)

protected virtual void AddVariantCombination(Dictionary<string, HashSet<string>> variantValues, Dictionary<string, string> combination)

Parameters

variantValues Dictionary<string, HashSet<string>>
combination Dictionary<string, string>

AddVariantValuesToMapping(Dictionary<string, HashSet<string>>, Dictionary<string, HashSet<string>>)

protected virtual void AddVariantValuesToMapping(Dictionary<string, HashSet<string>> mappings, Dictionary<string, HashSet<string>> variantValues)

Parameters

mappings Dictionary<string, HashSet<string>>
variantValues Dictionary<string, HashSet<string>>

Clone()

public abstract RecipeBase Clone()

Returns

RecipeBase

CloneTo(object)

protected virtual void CloneTo(object recipe)

Parameters

recipe object

CollectVariantValues(Match, List<string>, Dictionary<string, HashSet<string>>)

protected virtual void CollectVariantValues(Match match, List<string> variants, Dictionary<string, HashSet<string>> variantCodes)

Parameters

match Match
variants List<string>
variantCodes Dictionary<string, HashSet<string>>

ConsumeExactMatchIngredient(ItemStack, ItemSlot, ItemSlot[], List<IRecipeIngredient>, IPlayer)

protected virtual void ConsumeExactMatchIngredient(ItemStack inputStack, ItemSlot inputSlot, ItemSlot[] inputSlots, List<IRecipeIngredient> exactMatchIngredients, IPlayer byPlayer)

Parameters

inputStack ItemStack
inputSlot ItemSlot
inputSlots ItemSlot[]
exactMatchIngredients List<IRecipeIngredient>
byPlayer IPlayer

ConsumeInputAt(IPlayer, ItemSlot[], int, int, int, int, IRecipeIngredient?[])

protected virtual bool ConsumeInputAt(IPlayer byPlayer, ItemSlot[] inputSlots, int gridWidth, int recipeWidth, int colStart, int rowStart, IRecipeIngredient?[] ingredients)

Parameters

byPlayer IPlayer
inputSlots ItemSlot[]
gridWidth int
recipeWidth int
colStart int
rowStart int
ingredients IRecipeIngredient[]

Returns

bool

ConsumeInputAt(IPlayer, ItemSlot[], IRecipeIngredient?[])

protected virtual bool ConsumeInputAt(IPlayer byPlayer, ItemSlot[] inputSlots, IRecipeIngredient?[] ingredients)

Parameters

byPlayer IPlayer
inputSlots ItemSlot[]
ingredients IRecipeIngredient[]

Returns

bool

ConsumeInputShapeLess(IPlayer, ItemSlot[], IRecipeIngredient?[])

protected virtual bool ConsumeInputShapeLess(IPlayer byPlayer, ItemSlot[] inputSlots, IRecipeIngredient?[] ingredients)

Parameters

byPlayer IPlayer
inputSlots ItemSlot[]
ingredients IRecipeIngredient[]

Returns

bool

ConsumeWildcardMatchIngredient(ItemStack, ItemSlot, ItemSlot[], List<IRecipeIngredient>, IPlayer)

protected virtual void ConsumeWildcardMatchIngredient(ItemStack inputStack, ItemSlot inputSlot, ItemSlot[] inputSlots, List<IRecipeIngredient> wildcardAndToolIngredients, IPlayer byPlayer)

Parameters

inputStack ItemStack
inputSlot ItemSlot
inputSlots ItemSlot[]
wildcardAndToolIngredients List<IRecipeIngredient>
byPlayer IPlayer

FillIngredientPlaceHolders(IRecipeIngredient, string, string)

protected virtual void FillIngredientPlaceHolders(IRecipeIngredient ingredient, string variantCode, string variantValue)

Parameters

ingredient IRecipeIngredient
variantCode string
variantValue string

FilterOutRecipesWithExactIngredientsThatDontMatchTags(IEnumerable<IRecipeBase>, IWorldAccessor)

protected virtual IEnumerable<IRecipeBase> FilterOutRecipesWithExactIngredientsThatDontMatchTags(IEnumerable<IRecipeBase> recipes, IWorldAccessor world)

Parameters

recipes IEnumerable<IRecipeBase>
world IWorldAccessor

Returns

IEnumerable<IRecipeBase>

FromBytes(BinaryReader, IWorldAccessor)

public virtual void FromBytes(BinaryReader reader, IWorldAccessor resolver)

Parameters

reader BinaryReader
resolver IWorldAccessor

GenerateAllowedVariantsCombinations(Dictionary<string, string[]>)

protected virtual List<Dictionary<string, string>> GenerateAllowedVariantsCombinations(Dictionary<string, string[]> allowedVariants)

Parameters

allowedVariants Dictionary<string, string[]>

Returns

List<Dictionary<string, string>>

GenerateAllowedVariantsCombinationsRecursive(int, string[], IEnumerable<(string variant, string value)>, Dictionary<string, string[]>, List<Dictionary<string, string>>)

protected virtual void GenerateAllowedVariantsCombinationsRecursive(int index, string[] variants, IEnumerable<(string variant, string value)> combination, Dictionary<string, string[]> allowedVariants, List<Dictionary<string, string>> combinations)

Parameters

index int
variants string[]
combination IEnumerable<(string variant, string value)>
allowedVariants Dictionary<string, string[]>
combinations List<Dictionary<string, string>>

GenerateOutputStack(ItemSlot[], ItemSlot)

public virtual void GenerateOutputStack(ItemSlot[] inputSlots, ItemSlot outputSlot)

Parameters

inputSlots ItemSlot[]
outputSlot ItemSlot

GenerateRecipesForAllIngredientCombinations(IWorldAccessor)

public virtual IEnumerable<IRecipeBase> GenerateRecipesForAllIngredientCombinations(IWorldAccessor world)

Parameters

world IWorldAccessor

Returns

IEnumerable<IRecipeBase>

GenerateRecipesForTagOnlyIngredient(IWorldAccessor, IRecipeBase, IRecipeIngredient)

protected virtual IEnumerable<IRecipeBase> GenerateRecipesForTagOnlyIngredient(IWorldAccessor world, IRecipeBase recipe, IRecipeIngredient ingredient)

Parameters

world IWorldAccessor
recipe IRecipeBase
ingredient IRecipeIngredient

Returns

IEnumerable<IRecipeBase>

GenerateRecipesForTagOnlyIngredients(IWorldAccessor, IRecipeBase)

protected virtual IEnumerable<IRecipeBase> GenerateRecipesForTagOnlyIngredients(IWorldAccessor world, IRecipeBase recipe)

Parameters

world IWorldAccessor
recipe IRecipeBase

Returns

IEnumerable<IRecipeBase>

GetElementInGrid<TGridCellElement>(int, int, TGridCellElement[], int)

public virtual TGridCellElement? GetElementInGrid<TGridCellElement>(int row, int column, TGridCellElement[] cells, int gridWidth)

Parameters

row int
column int
cells TGridCellElement[]
gridWidth int

Returns

TGridCellElement

Type Parameters

TGridCellElement

GetGridIndex<TGridCellElement>(int, int, TGridCellElement[], int)

public virtual int GetGridIndex<TGridCellElement>(int row, int col, TGridCellElement[] cells, int gridWidth)

Parameters

row int
col int
cells TGridCellElement[]
gridWidth int

Returns

int

Type Parameters

TGridCellElement

GetIngredientById(string)

protected virtual IRecipeIngredient? GetIngredientById(string id)

Parameters

id string

Returns

IRecipeIngredient

GetInputStackForIngredientId(string, ItemSlot[])

protected virtual ItemStack? GetInputStackForIngredientId(string id, ItemSlot[] inputSlots)

Parameters

id string
inputSlots ItemSlot[]

Returns

ItemStack

GetMatchType(string?, bool)

public static EnumRecipeMatchType GetMatchType(string? code, bool named = false)

Parameters

code string
named bool

Returns

EnumRecipeMatchType

GetNameToCodeMapping(IWorldAccessor)

protected virtual Dictionary<string, HashSet<string>> GetNameToCodeMapping(IWorldAccessor world)

Parameters

world IWorldAccessor

Returns

Dictionary<string, HashSet<string>>

GetNameToCodeMappingForAdvancedWildcard(IWorldAccessor, IRecipeIngredient, Dictionary<string, HashSet<string>>)

protected virtual void GetNameToCodeMappingForAdvancedWildcard(IWorldAccessor world, IRecipeIngredient ingredient, Dictionary<string, HashSet<string>> mappings)

Parameters

world IWorldAccessor
ingredient IRecipeIngredient
mappings Dictionary<string, HashSet<string>>

GetNameToCodeMappingForBasicWildcard(IWorldAccessor, IRecipeIngredient, Dictionary<string, HashSet<string>>)

protected virtual void GetNameToCodeMappingForBasicWildcard(IWorldAccessor world, IRecipeIngredient ingredient, Dictionary<string, HashSet<string>> mappings)

Parameters

world IWorldAccessor
ingredient IRecipeIngredient
mappings Dictionary<string, HashSet<string>>

GetVariantValuesFromAdvancedWildcard(IRecipeIngredient, IEnumerable<CollectibleObject>, Dictionary<string, string>)

protected virtual Dictionary<string, HashSet<string>> GetVariantValuesFromAdvancedWildcard(IRecipeIngredient ingredient, IEnumerable<CollectibleObject> collectibles, Dictionary<string, string> allowedVariantsCombination)

Parameters

ingredient IRecipeIngredient
collectibles IEnumerable<CollectibleObject>
allowedVariantsCombination Dictionary<string, string>

Returns

Dictionary<string, HashSet<string>>

IsAdvancedWildcard(string)

public static bool IsAdvancedWildcard(string code)

Parameters

code string

Returns

bool

IsBasicWildcard(string)

public static bool IsBasicWildcard(string code)

Parameters

code string

Returns

bool

IsExactMatch(string)

public static bool IsExactMatch(string code)

Parameters

code string

Returns

bool

IsRegex(string)

public static bool IsRegex(string code)

Parameters

code string

Returns

bool

MatchIngredientStacks(List<(ItemStack stack, IRecipeIngredient ingredient)>, List<ItemStack>)

protected virtual bool MatchIngredientStacks(List<(ItemStack stack, IRecipeIngredient ingredient)> ingredientStacks, List<ItemStack> suppliedStacks)

Parameters

ingredientStacks List<(ItemStack stack, IRecipeIngredient ingredient)>
suppliedStacks List<ItemStack>

Returns

bool

MatchResolvedStackToIngredientTags(IRecipeIngredient, IWorldAccessor)

protected virtual bool MatchResolvedStackToIngredientTags(IRecipeIngredient ingredient, IWorldAccessor world)

Parameters

ingredient IRecipeIngredient
world IWorldAccessor

Returns

bool

MatchStackToIngredient(ItemStack?, IRecipeIngredient?)

protected virtual bool MatchStackToIngredient(ItemStack? inputStack, IRecipeIngredient? ingredient)

Parameters

inputStack ItemStack
ingredient IRecipeIngredient

Returns

bool

MatchWildcardIngredients(List<ItemStack>, IRecipeIngredient?[])

protected virtual bool MatchWildcardIngredients(List<ItemStack> suppliedStacks, IRecipeIngredient?[] ingredients)

Parameters

suppliedStacks List<ItemStack>
ingredients IRecipeIngredient[]

Returns

bool

MatchesAtPosition(int, int, ItemSlot[], int, int, IRecipeIngredient?[])

protected virtual bool MatchesAtPosition(int colStart, int rowStart, ItemSlot[] inputSlots, int gridWidth, int recipeWidth, IRecipeIngredient?[] ingredients)

Parameters

colStart int
rowStart int
inputSlots ItemSlot[]
gridWidth int
recipeWidth int
ingredients IRecipeIngredient[]

Returns

bool

MatchesAtPosition(ItemSlot[], IRecipeIngredient?[])

protected virtual bool MatchesAtPosition(ItemSlot[] inputSlots, IRecipeIngredient?[] ingredients)

Parameters

inputSlots ItemSlot[]
ingredients IRecipeIngredient[]

Returns

bool

MatchesShapeLess(ItemSlot[], IWorldAccessor, IRecipeIngredient?[])

protected virtual bool MatchesShapeLess(ItemSlot[] suppliedSlots, IWorldAccessor world, IRecipeIngredient?[] ingredients)

Parameters

suppliedSlots ItemSlot[]
world IWorldAccessor
ingredients IRecipeIngredient[]

Returns

bool

MergeIngredientStacks(ItemSlot[], List<(ItemStack stack, IRecipeIngredient ingredient)>, IRecipeIngredient?[], IWorldAccessor)

protected virtual void MergeIngredientStacks(ItemSlot[] slots, List<(ItemStack stack, IRecipeIngredient ingredient)> stacks, IRecipeIngredient?[] ingredients, IWorldAccessor world)

Parameters

slots ItemSlot[]
stacks List<(ItemStack stack, IRecipeIngredient ingredient)>
ingredients IRecipeIngredient[]
world IWorldAccessor

MergeStacks(ItemSlot[], List<ItemStack>)

protected virtual void MergeStacks(ItemSlot[] slots, List<ItemStack> stacks)

Parameters

slots ItemSlot[]
stacks List<ItemStack>

OnParsed(IWorldAccessor)

public virtual void OnParsed(IWorldAccessor world)

Parameters

world IWorldAccessor

ReplaceVariantsToRegex(string, out List<string>, Dictionary<string, string>?)

public static string ReplaceVariantsToRegex(string value, out List<string> variants, Dictionary<string, string>? allowedVariants = null)

Parameters

value string
variants List<string>
allowedVariants Dictionary<string, string>

Returns

string

Resolve(IWorldAccessor, string)

public abstract bool Resolve(IWorldAccessor world, string sourceForErrorLogging)

Parameters

world IWorldAccessor
sourceForErrorLogging string

Returns

bool

SeparateAndMergeIngredients(IRecipeIngredient?[], List<IRecipeIngredient>, List<IRecipeIngredient>)

protected virtual void SeparateAndMergeIngredients(IRecipeIngredient?[] ingredients, List<IRecipeIngredient> exactMatchIngredients, List<IRecipeIngredient> wildcardAndToolIngredients)

Parameters

ingredients IRecipeIngredient[]
exactMatchIngredients List<IRecipeIngredient>
wildcardAndToolIngredients List<IRecipeIngredient>

ToBytes(BinaryWriter)

public virtual void ToBytes(BinaryWriter writer)

Parameters

writer BinaryWriter

WildCardToRegex(string)

public static string WildCardToRegex(string value)

Parameters

value string

Returns

string