Class GridRecipe
- Namespace
 - Vintagestory.API.Common
 
- Assembly
 - VintagestoryAPI.dll
 
Represents a crafting recipe to be made on the crafting grid. Open in GitHub
[DocumentAsJson]
public class GridRecipe : IByteSerializable
  - Inheritance
 - 
      
      GridRecipe
 
- Implements
 
- Inherited Members
 
- Extension Methods
 
Examples
{
	"ingredientPattern": "GS,S_",
	"ingredients": {
		"G": {
			"type": "item",
			"code": "drygrass"
		},
		"S": {
			"type": "item",
			"code": "stick"
		}
	},
	"width": 2,
	"height": 2,
	"output": {
		"type": "item",
		"code": "firestarter"
	}
}
  Fields
AllowedVariants
If '{code}' is used in ingredient code, allowed variants for this code should be specified in this map
[DocumentAsJson]
public Dictionary<string, string[]> AllowedVariants
  Field 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]
public JsonObject Attributes
  Field Value
AverageDurability
If true, the output item will have its durability averaged over the input items
[DocumentAsJson]
public bool AverageDurability
  Field Value
Enabled
If set to false, the recipe will never be loaded. If loaded, you can use this field to disable recipes during runtime.
[DocumentAsJson]
public bool Enabled
  Field Value
Height
Required grid height for crafting this recipe
[DocumentAsJson]
public int Height
  Field Value
IngredientPattern
The pattern of the ingredient. Order for a 3x3 recipe:
1 2 3
4 5 6
7 8 9
Order for a 2x2 recipe:
1 2
3 4
Commas seperate each horizontal row, and an underscore ( _ ) marks a space as empty.
Note: from game version 1.20.4, this becomes null on server-side after completion of recipe resolving during server start-up phase
[DocumentAsJson]
public string IngredientPattern
  Field Value
Ingredients
The recipes ingredients in any order, including the code used in the ingredient pattern.
Note: from game version 1.20.4, this becomes null on server-side after completion of recipe resolving during server start-up phase
[DocumentAsJson]
public Dictionary<string, CraftingRecipeIngredient> Ingredients
  Field Value
MergeAttributesFrom
Attributes from thise ingredients will be merged into output itemstack
[DocumentAsJson]
public string[] MergeAttributesFrom
  Field Value
- string[]
 
Name
Name of the recipe. Used for logging, and some specific uses. Recipes for repairing objects must contain 'repair' in the name.
[DocumentAsJson]
public AssetLocation Name
  Field Value
Output
The resulting stack when the recipe is created.
[DocumentAsJson]
public CraftingRecipeIngredient Output
  Field Value
RecipeGroup
Info used by the handbook. By default, all recipes for an object will appear in a single preview. This allows you to split grid recipe previews into multiple.
[DocumentAsJson]
public int RecipeGroup
  Field Value
RequiresTrait
If set, only players with given trait can use this recipe. See config/traits.json for a list of traits.
[DocumentAsJson]
public string RequiresTrait
  Field Value
Shapeless
Whether the order of input items should be respected
[DocumentAsJson]
public bool Shapeless
  Field Value
ShowInCreatedBy
Used by the handbook. If false, will not appear in the "Created by" section
[DocumentAsJson]
public bool ShowInCreatedBy
  Field Value
SkipVariants
If '{code}' is used in ingredient code, skip variants for this code should be specified in this map
[DocumentAsJson]
public Dictionary<string, string[]> SkipVariants
  Field Value
- Dictionary<string, string[]>
 
Width
Required grid width for crafting this recipe
[DocumentAsJson]
public int Width
  Field Value
World
protected IWorldAccessor World
  Field Value
resolvedIngredients
A set of ingredients with their pattern codes resolved into a single object.
public GridRecipeIngredient[] resolvedIngredients
  Field Value
Properties
CopyAttributesFrom
If set, it will copy over the itemstack attributes from given ingredient code
[DocumentAsJson]
public string CopyAttributesFrom { get; set; }
  Property Value
Methods
Clone()
Creates a deep copy
public GridRecipe Clone()
  Returns
ConsumeInput(IPlayer, ItemSlot[], int)
Puts the crafted itemstack into the output slot and consumes the required items from the input slots
public bool ConsumeInput(IPlayer byPlayer, ItemSlot[] inputSlots, int gridWidth)
  Parameters
Returns
ConsumeInputAt(IPlayer, ItemSlot[], int, int, int)
protected bool ConsumeInputAt(IPlayer byPlayer, ItemSlot[] inputSlots, int gridWidth, int colStart, int rowStart)
  Parameters
Returns
ConsumeInputShapeLess(IPlayer, ItemSlot[])
protected bool ConsumeInputShapeLess(IPlayer byPlayer, ItemSlot[] inputSlots)
  Parameters
Returns
FreeRAMServer()
public virtual void FreeRAMServer()
  FromBytes(BinaryReader, IWorldAccessor)
Deserializes the recipe
public void FromBytes(BinaryReader reader, IWorldAccessor resolver)
  Parameters
readerBinaryReaderresolverIWorldAccessor
GenerateOutputStack(ItemSlot[], ItemSlot)
public void GenerateOutputStack(ItemSlot[] inputSlots, ItemSlot outputSlot)
  Parameters
GetElementInGrid<T>(int, int, T[], int)
public T GetElementInGrid<T>(int row, int col, T[] stacks, int gridwidth)
  Parameters
Returns
- T
 
Type Parameters
T
GetGridIndex<T>(int, int, T[], int)
public int GetGridIndex<T>(int row, int col, T[] stacks, int gridwidth)
  Parameters
Returns
Type Parameters
T
GetInputStackForPatternCode(string, ItemSlot[])
Returns only the first matching itemstack, there may be multiple
public ItemStack GetInputStackForPatternCode(string patternCode, ItemSlot[] inputSlots)
  Parameters
Returns
GetNameToCodeMapping(IWorldAccessor)
Resolves Wildcards in the ingredients
public Dictionary<string, string[]> GetNameToCodeMapping(IWorldAccessor world)
  Parameters
worldIWorldAccessor
Returns
- Dictionary<string, string[]>
 
GetNameToCodeMappingForAdvancedWildcard(IWorldAccessor, CraftingRecipeIngredient, Dictionary<string, string[]>)
protected void GetNameToCodeMappingForAdvancedWildcard(IWorldAccessor world, CraftingRecipeIngredient ingredient, Dictionary<string, string[]> mappings)
  Parameters
worldIWorldAccessoringredientCraftingRecipeIngredientmappingsDictionary<string, string[]>
GetNameToCodeMappingForBasicWildcard(IWorldAccessor, CraftingRecipeIngredient, Dictionary<string, string[]>)
protected void GetNameToCodeMappingForBasicWildcard(IWorldAccessor world, CraftingRecipeIngredient ingredient, Dictionary<string, string[]> mappings)
  Parameters
worldIWorldAccessoringredientCraftingRecipeIngredientmappingsDictionary<string, string[]>
IsAdvancedWildcard(string)
public static bool IsAdvancedWildcard(string code)
  Parameters
codestring
Returns
IsBasicWildcard(string)
public static bool IsBasicWildcard(string code)
  Parameters
codestring
Returns
IsRegex(string)
public static bool IsRegex(string code)
  Parameters
codestring
Returns
MatchCollectibleCode(AssetLocation, Regex, List<string>, Dictionary<string, List<string>>)
protected void MatchCollectibleCode(AssetLocation code, Regex regex, List<string> variants, Dictionary<string, List<string>> variantCodes)
  Parameters
codeAssetLocationregexRegexvariantsList<string>variantCodesDictionary<string, List<string>>
Matches(IPlayer, ItemSlot[], int)
Check if this recipe matches given ingredients
public bool Matches(IPlayer forPlayer, ItemSlot[] ingredients, int gridWidth)
  Parameters
Returns
MatchesAtPosition(int, int, ItemSlot[], int)
public bool MatchesAtPosition(int colStart, int rowStart, ItemSlot[] inputSlots, int gridWidth)
  Parameters
Returns
MatchesShapeLess(ItemSlot[], int)
protected bool MatchesShapeLess(ItemSlot[] suppliedSlots, int gridWidth)
  Parameters
Returns
ReplaceVariantsToRegex(string, out List<string>)
protected static string ReplaceVariantsToRegex(string value, out List<string> variants)
  Parameters
Returns
ResolveIngredients(IWorldAccessor)
Turns Ingredients into IItemStacks
public bool ResolveIngredients(IWorldAccessor world)
  Parameters
worldIWorldAccessor
Returns
- bool
 True on successful resolve
ToBytes(BinaryWriter)
Serialized the recipe
public void ToBytes(BinaryWriter writer)
  Parameters
writerBinaryWriter
WildCardToRegex(string)
protected static string WildCardToRegex(string value)
  Parameters
valuestring