tModLoader v2024.03
A mod to make and play Terraria mods
Recipe Class Reference

A Recipe is a collection of ingredients, tiles, and a resulting Item. This is how players can craft items in the game.
The Basic Recipes Guideteaches how to add new recipes to the game and how to manipulate existing recipes.
Use Recipe.Create(int, int) to create a Recipe instance resulting in the specified item. Use AddIngredient(int, int) to add ingredients and AddTile(int) to add crafting stations. Finally, use Register to complete the recipe and register it to the game.
Recipes can only be added in ModSystem.AddRecipes, ModItem.AddRecipes, and GlobalItem.AddRecipes.
Recipes should be edited only in ModSystem.PostAddRecipes. More...

Classes

class  ConsumptionRules
 

Public Member Functions

bool AcceptedByItemGroups (int invType, int reqType)
 
bool AcceptsGroup (int groupId)
 
Recipe AddCondition (Condition condition)
 
Recipe AddCondition (IEnumerable< Condition > conditions)
 Adds a collection of conditions that will determine whether or not the recipe will be to be available for the player to use. The conditions can be unrelated to items or tiles (for example, biome or time). More...
 
Recipe AddCondition (LocalizedText description, Func< bool > condition)
 Sets a condition delegate that will determine whether or not the recipe will be to be available for the player to use. The condition can be unrelated to items or tiles (for example, biome or time). More...
 
Recipe AddCondition (params Condition[] conditions)
 Adds an array of conditions that will determine whether or not the recipe will be to be available for the player to use. The conditions can be unrelated to items or tiles (for example, biome or time). More...
 
Recipe AddConsumeItemCallback (ConsumeItemCallback callback)
 Sets a callback that allows you to determine how many of a certain ingredient is consumed when this recipe is used. Return the number of ingredients that will actually be consumed. By default returns numRequired.
 
Recipe AddCustomShimmerResult (int itemType, int itemStack=1)
 
Recipe AddDecraftCondition (Condition condition)
 
Recipe AddDecraftCondition (IEnumerable< Condition > conditions)
 Adds a collection of conditions that will determine whether or not the recipe can be shimmered/decrafted. The conditions can be unrelated to items or tiles (for example, biome or time). More...
 
Recipe AddDecraftCondition (LocalizedText description, Func< bool > condition)
 Sets a condition delegate that will determine whether or not the recipe can be shimmered/decrafted. The condition can be unrelated to items or tiles (for example, biome or time). More...
 
Recipe AddDecraftCondition (params Condition[] conditions)
 Adds an array of conditions that will determine whether or not the recipe can be shimmered/decrafted. The conditions can be unrelated to items or tiles (for example, biome or time). More...
 
Recipe AddIngredient (int itemID, int stack=1)
 Adds an ingredient to this recipe with the given item type and stack size. Ex: recipe.AddIngredient(ItemID.IronAxe) More...
 
Recipe AddIngredient (Mod mod, string itemName, int stack=1)
 Adds an ingredient to this recipe with the given item name from the given mod, and with the given stack stack. If the mod parameter is null, then it will automatically use an item from the mod creating this recipe. More...
 
Recipe AddIngredient (ModItem item, int stack=1)
 Adds an ingredient to this recipe of the given type of item and stack size. More...
 
Recipe AddIngredient< T > (int stack=1)
 Adds an ingredient to this recipe of the given type of item and stack size. More...
 
Recipe AddOnCraftCallback (OnCraftCallback callback)
 Sets a callback that will allow you to make anything happen when the recipe is used to create an item.
 
Recipe AddRecipeGroup (int recipeGroupId, int stack=1)
 Adds a recipe group ingredient to this recipe with the given RecipeGroupID and stack size.
Recipe groups allow a recipe to use alternate ingredients without making multiple recipes. For example the RecipeGroupID.IronBar group accepts either ItemID.IronBar or ItemID.LeadBar. The Recipe Groups wiki guidehas more information.
Vanilla recipe group IDs can be found in RecipeGroupID and modded recipe group IDs will be returned from RecipeGroup.RegisterGroup(string, RecipeGroup). AddRecipeGroup(string, int) can be used instead if the ID number is not known but the name is known. More...
 
Recipe AddRecipeGroup (RecipeGroup recipeGroup, int stack=1)
 Adds a recipe group ingredient to this recipe with the given RecipeGroup. More...
 
Recipe AddRecipeGroup (string name, int stack=1)
 Adds a recipe group ingredient to this recipe with the given RecipeGroup name and stack size.
Recipe groups allow a recipe to use alternate ingredients without making multiple recipes. For example the "IronBar" group accepts either ItemID.IronBar or ItemID.LeadBar. The Recipe Groups wiki guidehas more information.
To use a vanilla recipe group, use AddRecipeGroup(int, int) using a RecipeGroupID entry instead. More...
 
Recipe AddTile (int tileID)
 Adds a required crafting station with the given tile type to this recipe. Ex: recipe.AddTile(TileID.WorkBenches) More...
 
Recipe AddTile (Mod mod, string tileName)
 Adds a required crafting station to this recipe with the given tile name from the given mod. If the mod parameter is null, then it will automatically use a tile from the mod creating this recipe. More...
 
Recipe AddTile (ModTile tile)
 Adds a required crafting station to this recipe of the given type of tile. More...
 
Recipe AddTile< T > ()
 Adds a required crafting station to this recipe of the given type of tile. More...
 
Recipe ApplyConditionsAsDecraftConditions ()
 Adds every condition from Recipe.Conditions to Recipe.DecraftConditions, checking for duplicates.
 
Recipe Clone ()
 Returns a clone of this recipe except the source mod of the Recipe will the currently loading mod.
The clone will have to be registered after being tweaked.
 
delegate void ConsumeItemCallback (Recipe recipe, int type, ref int amount)
 
bool ContainsIngredient (int itemType)
 
void Create ()
 
Recipe DisableDecraft ()
 Sets a check that is used during load to prevent this being shimmered/decrafted. More...
 
void DisableRecipe ()
 
bool HasCondition (Condition condition)
 
bool HasIngredient (int itemID)
 
bool HasIngredient (Mod mod, string itemName)
 
bool HasIngredient (ModItem item)
 
bool HasIngredient< T > ()
 
bool HasRecipeGroup (int id)
 
bool HasRecipeGroup (RecipeGroup group)
 
bool HasRecipeGroup (string name)
 
bool HasResult (int itemID)
 
bool HasResult (Mod mod, string itemName)
 
bool HasResult (ModItem item)
 
bool HasResult< T > ()
 
bool HasShimmerCondition (Condition condition)
 
bool HasTile (int tileID)
 
bool HasTile (Mod mod, string tileName)
 
bool HasTile (ModTile tile)
 
bool HasTile< T > ()
 
delegate void OnCraftCallback (Recipe recipe, Item item, List< Item > consumedItems, Item destinationStack)
 
bool ProcessGroupsForText (int type, out string theText)
 
Recipe Register ()
 Adds this recipe to the game. Call this after you have finished setting the result, ingredients, etc. More...
 
bool RemoveCondition (Condition condition)
 
bool RemoveIngredient (int itemID)
 
bool RemoveIngredient (Item item)
 
bool RemoveRecipeGroup (int groupID)
 
bool RemoveShimmerCondition (Condition condition)
 
bool RemoveTile (int tileID)
 
void ReplaceResult (int itemID, int stack=1)
 
void ReplaceResult (Mod mod, string itemName, int stack=1)
 
void ReplaceResult (ModItem item, int stack=1)
 
void ReplaceResult< T > (int stack=1)
 
void RequireGroup (int id)
 
Recipe SortAfter (Recipe recipe)
 Sorts the recipe after the one given as parameter. Both recipes must already be registered.
 
Recipe SortAfterFirstRecipesOf (int itemId)
 Sorts the recipe after the first one creating the item of the ID given as parameter.
 
Recipe SortBefore (Recipe recipe)
 Sorts the recipe before the one given as parameter. Both recipes must already be registered.
 
Recipe SortBeforeFirstRecipesOf (int itemId)
 Sorts the recipe before the first one creating the item of the ID given as parameter.
 
bool TryGetIngredient (int itemID, out Item ingredient)
 
bool TryGetIngredient (Mod mod, string itemName, out Item ingredient)
 
bool TryGetIngredient (ModItem item, out Item ingredient)
 
bool TryGetIngredient< T > (out Item ingredient)
 
bool TryGetResult (int itemID, out Item result)
 
bool TryGetResult (Mod mod, string itemName, out Item result)
 
bool TryGetResult (ModItem item, out Item result)
 
bool TryGetResult< T > (out Item result)
 

Static Public Member Functions

static void ClearAvailableRecipes ()
 
static bool CollectedEnoughItemsToCraftRecipeNew (Recipe tempRec)
 
static bool CollectedEnoughItemsToCraftRecipeOld (Recipe tempRec)
 
static Recipe Create (int result, int amount=1)
 Creates a recipe resulting in the given item and amount but does not yet register it into the game. Call this at the very beginning when creating a new craft. More...
 
static void FindRecipes (bool canDelayCheck=false)
 
static int GetRequiredTileStyle (int tileID)
 
static void GetThroughDelayedFindRecipes ()
 
static void SetupRecipeGroups ()
 
static void SetupRecipes ()
 
static void UpdateItemVariants ()
 
static void UpdateWhichItemsAreCrafted ()
 
static void UpdateWhichItemsAreMaterials ()
 

Public Attributes

List< int > acceptedGroups = new()
 
readonly List< Condition > Conditions = new List<Condition>()
 
Item createItem = new Item()
 
List< ItemcustomShimmerResults
 
readonly List< Condition > DecraftConditions = new List<Condition>()
 
readonly Mod Mod
 
List< ItemrequiredItem = new()
 
List< int > requiredTile = new()
 
Recipe target
 

Static Public Attributes

static int maxRecipes = 3000
 
static int numRecipes
 

Properties

bool Disabled [get]
 Any recipe with this flag won't be shown in game.
 
Recipe bool after Ordering [get, set]
 
int RecipeIndex [get, set]
 The index of the recipe in the Main.recipe array.
 

Detailed Description

A Recipe is a collection of ingredients, tiles, and a resulting Item. This is how players can craft items in the game.
The Basic Recipes Guide

teaches how to add new recipes to the game and how to manipulate existing recipes.
Use Recipe.Create(int, int) to create a Recipe instance resulting in the specified item. Use AddIngredient(int, int) to add ingredients and AddTile(int) to add crafting stations. Finally, use Register to complete the recipe and register it to the game.
Recipes can only be added in ModSystem.AddRecipes, ModItem.AddRecipes, and GlobalItem.AddRecipes.
Recipes should be edited only in ModSystem.PostAddRecipes.

Member Function Documentation

◆ AddCondition() [1/3]

Recipe Recipe.AddCondition ( IEnumerable< Condition >  conditions)

Adds a collection of conditions that will determine whether or not the recipe will be to be available for the player to use. The conditions can be unrelated to items or tiles (for example, biome or time).

Parameters
conditionsA collection of conditions.

◆ AddCondition() [2/3]

Recipe Recipe.AddCondition ( LocalizedText  description,
Func< bool >  condition 
)

Sets a condition delegate that will determine whether or not the recipe will be to be available for the player to use. The condition can be unrelated to items or tiles (for example, biome or time).

Parameters
descriptionA description of this condition.
conditionA function returning whether the condition is met.

◆ AddCondition() [3/3]

Recipe Recipe.AddCondition ( params Condition[]  conditions)

Adds an array of conditions that will determine whether or not the recipe will be to be available for the player to use. The conditions can be unrelated to items or tiles (for example, biome or time).

Parameters
conditionsAn array of conditions.

◆ AddDecraftCondition() [1/3]

Recipe Recipe.AddDecraftCondition ( IEnumerable< Condition >  conditions)

Adds a collection of conditions that will determine whether or not the recipe can be shimmered/decrafted. The conditions can be unrelated to items or tiles (for example, biome or time).

Parameters
conditionsA collection of conditions.

◆ AddDecraftCondition() [2/3]

Recipe Recipe.AddDecraftCondition ( LocalizedText  description,
Func< bool >  condition 
)

Sets a condition delegate that will determine whether or not the recipe can be shimmered/decrafted. The condition can be unrelated to items or tiles (for example, biome or time).

Parameters
descriptionA description of this condition.
conditionThe predicate delegate condition.

◆ AddDecraftCondition() [3/3]

Recipe Recipe.AddDecraftCondition ( params Condition[]  conditions)

Adds an array of conditions that will determine whether or not the recipe can be shimmered/decrafted. The conditions can be unrelated to items or tiles (for example, biome or time).

Parameters
conditionsAn array of conditions.

◆ AddIngredient() [1/3]

Recipe Recipe.AddIngredient ( int  itemID,
int  stack = 1 
)

Adds an ingredient to this recipe with the given item type and stack size. Ex: recipe.AddIngredient(ItemID.IronAxe)

Parameters
itemIDThe item identifier.
stackThe stack.

◆ AddIngredient() [2/3]

Recipe Recipe.AddIngredient ( Mod  mod,
string  itemName,
int  stack = 1 
)

Adds an ingredient to this recipe with the given item name from the given mod, and with the given stack stack. If the mod parameter is null, then it will automatically use an item from the mod creating this recipe.

Parameters
modThe mod.
itemNameName of the item.
stackThe stack.
Exceptions
RecipeExceptionThe item " + itemName + " does not exist in mod " + mod.Name + ". If you are trying to use a vanilla item, try removing the first argument.

◆ AddIngredient() [3/3]

Recipe Recipe.AddIngredient ( ModItem  item,
int  stack = 1 
)

Adds an ingredient to this recipe of the given type of item and stack size.

Parameters
itemThe item.
stackThe stack.

◆ AddIngredient< T >()

Recipe Recipe.AddIngredient< T > ( int  stack = 1)

Adds an ingredient to this recipe of the given type of item and stack size.

Parameters
stackThe stack.
Type Constraints
T :ModItem 
T :AddIngredient 
T :ModContent.ItemType<T>() 
T :stack 

◆ AddRecipeGroup() [1/3]

Recipe Recipe.AddRecipeGroup ( int  recipeGroupId,
int  stack = 1 
)

Adds a recipe group ingredient to this recipe with the given RecipeGroupID and stack size.
Recipe groups allow a recipe to use alternate ingredients without making multiple recipes. For example the RecipeGroupID.IronBar group accepts either ItemID.IronBar or ItemID.LeadBar. The Recipe Groups wiki guidehas more information.
Vanilla recipe group IDs can be found in RecipeGroupID and modded recipe group IDs will be returned from RecipeGroup.RegisterGroup(string, RecipeGroup). AddRecipeGroup(string, int) can be used instead if the ID number is not known but the name is known.

Parameters
recipeGroupIdThe RecipeGroupID.
stackThe stack.
Exceptions
RecipeExceptionA recipe group with the ID " + recipeGroupID + " does not exist.

◆ AddRecipeGroup() [2/3]

Recipe Recipe.AddRecipeGroup ( RecipeGroup  recipeGroup,
int  stack = 1 
)

Adds a recipe group ingredient to this recipe with the given RecipeGroup.

Parameters
recipeGroupThe RecipeGroup.
stack

◆ AddRecipeGroup() [3/3]

Recipe Recipe.AddRecipeGroup ( string  name,
int  stack = 1 
)

Adds a recipe group ingredient to this recipe with the given RecipeGroup name and stack size.
Recipe groups allow a recipe to use alternate ingredients without making multiple recipes. For example the "IronBar" group accepts either ItemID.IronBar or ItemID.LeadBar. The Recipe Groups wiki guidehas more information.
To use a vanilla recipe group, use AddRecipeGroup(int, int) using a RecipeGroupID entry instead.

Parameters
nameThe name.
stackThe stack.
Exceptions
RecipeExceptionA recipe group with the name " + name + " does not exist.

◆ AddTile() [1/3]

Recipe Recipe.AddTile ( int  tileID)

Adds a required crafting station with the given tile type to this recipe. Ex: recipe.AddTile(TileID.WorkBenches)

Parameters
tileIDThe tile identifier.
Exceptions
RecipeExceptionNo tile has ID " + tileID

◆ AddTile() [2/3]

Recipe Recipe.AddTile ( Mod  mod,
string  tileName 
)

Adds a required crafting station to this recipe with the given tile name from the given mod. If the mod parameter is null, then it will automatically use a tile from the mod creating this recipe.

Parameters
modThe mod.
tileNameName of the tile.
Exceptions
RecipeExceptionThe tile " + tileName + " does not exist in mod " + mod.Name + ". If you are trying to use a vanilla tile, try using Recipe.AddTile(tileID).

◆ AddTile() [3/3]

Recipe Recipe.AddTile ( ModTile  tile)

Adds a required crafting station to this recipe of the given type of tile.

Parameters
tileThe tile.

◆ AddTile< T >()

Adds a required crafting station to this recipe of the given type of tile.

Type Constraints
T :ModTile 
T :AddTile 
T :ModContent.TileType<T>() 

◆ Create()

static Recipe Recipe.Create ( int  result,
int  amount = 1 
)
static

Creates a recipe resulting in the given item and amount but does not yet register it into the game. Call this at the very beginning when creating a new craft.

Parameters
resultWhat item will be given when the craft has been completed
amountThe stack -> how many result items given when the recipe is crafted. (eg. 1 wood -> 4 wood platform)
Exceptions
RecipeExceptionA Recipe can only be created inside recipe related methods

◆ DisableDecraft()

Recipe Recipe.DisableDecraft ( )

Sets a check that is used during load to prevent this being shimmered/decrafted.

Exceptions
RecipeExceptionA Recipe can only be disabled inside Recipe related methods.

◆ HasIngredient< T >()

bool Recipe.HasIngredient< T > ( )
Type Constraints
T :ModItem 
T :HasIngredient 
T :ModContent.ItemType<T>() 

◆ HasResult< T >()

bool Recipe.HasResult< T > ( )
Type Constraints
T :ModItem 
T :HasResult 
T :ModContent.ItemType<T>() 

◆ HasTile< T >()

bool Recipe.HasTile< T > ( )
Type Constraints
T :ModTile 
T :HasTile 
T :ModContent.TileType<T>() 

◆ Register()

Recipe Recipe.Register ( )

Adds this recipe to the game. Call this after you have finished setting the result, ingredients, etc.

Exceptions
RecipeExceptionA recipe without any result has been added.

◆ ReplaceResult< T >()

void Recipe.ReplaceResult< T > ( int  stack = 1)
Type Constraints
T :ModItem 
T :ReplaceResult 
T :ModContent.ItemType<T>() 
T :stack 

◆ TryGetIngredient< T >()

bool Recipe.TryGetIngredient< T > ( out Item  ingredient)
Type Constraints
T :ModItem 
T :TryGetIngredient 
T :ModContent.ItemType<T>() 
T :out 
T :ingredient 

◆ TryGetResult< T >()

bool Recipe.TryGetResult< T > ( out Item  result)
Type Constraints
T :ModItem 
T :TryGetResult 
T :ModContent.ItemType<T>() 
T :out 
T :result