Table of Contents

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 : RecipeBase, IRecipeBase, IConcreteCloneable<RecipeBase>, IByteSerializable, IConcreteCloneable<GridRecipe>, ICloneable
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"
	}
}

Properties

Height

Required grid height for crafting this recipe

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

Property Value

int

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 separate 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("Required", "", false)]
public string? IngredientPattern { get; set; }

Property Value

string

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("Required", "", false)]
public Dictionary<string, CraftingRecipeIngredient>? Ingredients { get; set; }

Property Value

Dictionary<string, CraftingRecipeIngredient>

Output

The resulting stack when the recipe is created.

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

Property Value

CraftingRecipeIngredient

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("Optional", "0", false)]
public int RecipeGroup { get; set; }

Property Value

int

RecipeIngredients

public override IEnumerable<IRecipeIngredient> RecipeIngredients { get; }

Property Value

IEnumerable<IRecipeIngredient>

RecipeOutput

public override IRecipeOutput RecipeOutput { get; }

Property Value

IRecipeOutput

ResolvedIngredients

List of ingredients for each slot of the crafting grid

public CraftingRecipeIngredient?[]? ResolvedIngredients { get; set; }

Property Value

CraftingRecipeIngredient[]

Shapeless

Whether the order of input items should be respected

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

Property Value

bool

Width

Required grid width for crafting this recipe

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

Property Value

int

Methods

Clone()

Creates a deep copy

public override GridRecipe Clone()

Returns

GridRecipe

CloneTo(object)

protected override void CloneTo(object recipe)

Parameters

recipe object

ConsumeInput(IPlayer, ItemSlot[], int)

Puts the crafted ItemStack into the output slot and consumes the required items from the input slots

public virtual bool ConsumeInput(IPlayer byPlayer, ItemSlot[] inputSlots, int gridWidth)

Parameters

byPlayer IPlayer
inputSlots ItemSlot[]
gridWidth int

Returns

bool

FreeRAMServer()

public virtual void FreeRAMServer()

FromBytes(BinaryReader, IWorldAccessor)

Deserializes the recipe

public override void FromBytes(BinaryReader reader, IWorldAccessor resolver)

Parameters

reader BinaryReader
resolver IWorldAccessor

Matches(IPlayer, IWorldAccessor, ItemSlot[], int)

Check if this recipe matches given ingredients

public virtual bool Matches(IPlayer forPlayer, IWorldAccessor world, ItemSlot[] ingredients, int gridWidth)

Parameters

forPlayer IPlayer

The player for trait testing. Can be null.

world IWorldAccessor
ingredients ItemSlot[]
gridWidth int

Returns

bool

OnParsed(IWorldAccessor)

public override void OnParsed(IWorldAccessor world)

Parameters

world IWorldAccessor

Resolve(IWorldAccessor, string)

Turns Ingredients into IItemStacks

public override bool Resolve(IWorldAccessor world, string sourceForErrorLogging)

Parameters

world IWorldAccessor
sourceForErrorLogging string

Returns

bool

True on successful resolve

ToBytes(BinaryWriter)

Serialized the recipe

public override void ToBytes(BinaryWriter writer)

Parameters

writer BinaryWriter