Terraria ModLoader  0.11.7.7
A mod to make and play Terraria mods
Terraria.ModLoader.ModRecipe Class Reference

This class extends Terraria.Recipe, meaning you can use it in a similar manner to vanilla recipes. However, it provides methods that simplify recipe creation. Recipes are added by creating new instances of ModRecipe, then calling the AddRecipe method. More...

+ Inheritance diagram for Terraria.ModLoader.ModRecipe:
+ Collaboration diagram for Terraria.ModLoader.ModRecipe:

Public Member Functions

 ModRecipe (Mod mod)
 Constructor More...
 
void 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...
 
void 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...
 
void AddIngredient (ModItem item, int stack=1)
 Adds an ingredient to this recipe of the given type of item and stack size. More...
 
void AddRecipe ()
 Adds this recipe to the game. Call this after you have finished setting the result, ingredients, etc. More...
 
void AddRecipeGroup (string name, int stack=1)
 Adds a recipe group ingredient to this recipe with the given RecipeGroup name and stack size. Vanilla recipe groups consist of "Wood", "IronBar", "PresurePlate", "Sand", and "Fragment". More...
 
void AddRecipeGroup (int recipeGroupID, int stack=1)
 Adds a recipe group ingredient to this recipe with the given RecipeGroupID and stack size. Vanilla recipe group IDs can be found in Terraria.ID.RecipeGroupID and modded recipe group IDs will be returned from RecipeGroup.RegisterGroup. More...
 
void AddTile (int tileID)
 Adds a required crafting station with the given tile type to this recipe. Ex: recipe.AddTile(TileID.WorkBenches) More...
 
void 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...
 
void AddTile (ModTile tile)
 Adds a required crafting station to this recipe of the given type of tile. More...
 
virtual int ConsumeItem (int type, int numRequired)
 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. More...
 
virtual void OnCraft (Item item)
 Allows you to make anything happen when the player uses this recipe. The item parameter is the item the player has just crafted. More...
 
virtual bool RecipeAvailable ()
 Whether or not the conditions are met for this recipe to be available for the player to use. This hook can be used for conditions unrelated to items or tiles (for example, biome or time). More...
 
void SetResult (int itemID, int stack=1)
 Sets the result of this recipe with the given item type and stack size. More...
 
void SetResult (Mod mod, string itemName, int stack=1)
 Sets the result of 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...
 
void SetResult (ModItem item, int stack=1)
 Sets the result of this recipe to the given type of item and stack size. Useful in ModItem.AddRecipes. More...
 

Public Attributes

readonly Mod mod
 

Properties

int RecipeIndex [get, private set]
 The index of the recipe in the Main.recipe array. More...
 

Private Attributes

int numIngredients = 0
 
int numTiles = 0
 

Detailed Description

This class extends Terraria.Recipe, meaning you can use it in a similar manner to vanilla recipes. However, it provides methods that simplify recipe creation. Recipes are added by creating new instances of ModRecipe, then calling the AddRecipe method.

Definition at line 10 of file ModRecipe.cs.

Constructor & Destructor Documentation

Terraria.ModLoader.ModRecipe.ModRecipe ( Mod  mod)

Constructor

Parameters
modThe mod the recipe originates from.

Definition at line 28 of file ModRecipe.cs.

28  {
29  if (!RecipeHooks.setupRecipes)
30  throw new RecipeException("A ModRecipe can only be created inside recipe related methods");
31  this.mod = mod;
32  }

Member Function Documentation

void Terraria.ModLoader.ModRecipe.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.

Definition at line 78 of file ModRecipe.cs.

78  {
79  if (numIngredients == 14)
80  throw new RecipeException("Recipe already has maximum number of ingredients. 14 is the max.");
81  this.requiredItem[numIngredients].SetDefaults(itemID, false);
82  this.requiredItem[numIngredients].stack = stack;
84  }
void Terraria.ModLoader.ModRecipe.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.

Definition at line 93 of file ModRecipe.cs.

References Terraria.ModLoader.Environment, Terraria.ModLoader.Mod.ItemType(), and Terraria.ModLoader.Mod.Name.

93  {
94  if (mod == null) {
95  mod = this.mod;
96  }
97  int type = mod.ItemType(itemName);
98  if (type == 0) {
99  string message = "The item " + itemName + " does not exist in the mod " + mod.Name + "." + Environment.NewLine;
100  message += "If you are trying to use a vanilla item, try removing the first argument.";
101  throw new RecipeException(message);
102  }
103  this.AddIngredient(type, stack);
104  }
int ItemType(string name)
Gets the internal ID / type of the ModItem corresponding to the name. Returns 0 if no ModItem with th...
Sandstorm, Hell, Above surface during Eclipse, Space
void 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)
Definition: ModRecipe.cs:78
virtual string Name
Stores the name of the mod. This name serves as the mod's identification, and also helps with saving ...
Definition: Mod.cs:42

+ Here is the call graph for this function:

void Terraria.ModLoader.ModRecipe.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.

Definition at line 111 of file ModRecipe.cs.

References Terraria.ModLoader.ModItem.item.

111  {
112  this.AddIngredient(item.item.type, stack);
113  }
void 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)
Definition: ModRecipe.cs:78
void Terraria.ModLoader.ModRecipe.AddRecipe ( )

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.

Definition at line 221 of file ModRecipe.cs.

221  {
222  if (this.createItem == null || this.createItem.type == 0) {
223  throw new RecipeException("A recipe without any result has been added.");
224  }
225  if (this.numIngredients > 14 || this.numTiles > 14) {
226  throw new RecipeException("A recipe with either too many tiles or too many ingredients has been added. 14 is the maximum amount.");
227  }
228  for (int k = 0; k < Recipe.maxRequirements; k++) {
229  if (this.requiredTile[k] == TileID.Bottles) {
230  this.alchemy = true;
231  break;
232  }
233  }
234  if (Recipe.numRecipes >= Recipe.maxRecipes) {
235  Recipe.maxRecipes += 500;
236  Array.Resize(ref Main.recipe, Recipe.maxRecipes);
237  Array.Resize(ref Main.availableRecipe, Recipe.maxRecipes);
238  Array.Resize(ref Main.availableRecipeY, Recipe.maxRecipes);
239  for (int k = Recipe.numRecipes; k < Recipe.maxRecipes; k++) {
240  Main.recipe[k] = new Recipe();
241  Main.availableRecipeY[k] = 65f * k;
242  }
243  }
244  Main.recipe[Recipe.numRecipes] = this;
245  this.RecipeIndex = Recipe.numRecipes;
246  mod.recipes.Add(this);
247  Recipe.numRecipes++;
248  }
int RecipeIndex
The index of the recipe in the Main.recipe array.
Definition: ModRecipe.cs:19
void Terraria.ModLoader.ModRecipe.AddRecipeGroup ( string  name,
int  stack = 1 
)

Adds a recipe group ingredient to this recipe with the given RecipeGroup name and stack size. Vanilla recipe groups consist of "Wood", "IronBar", "PresurePlate", "Sand", and "Fragment".

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

Definition at line 121 of file ModRecipe.cs.

121  {
122  if (!RecipeGroup.recipeGroupIDs.ContainsKey(name)) {
123  throw new RecipeException("A recipe group with the name " + name + " does not exist.");
124  }
125  int id = RecipeGroup.recipeGroupIDs[name];
126  RecipeGroup rec = RecipeGroup.recipeGroups[id];
127  AddIngredient(rec.ValidItems[rec.IconicItemIndex], stack);
128  acceptedGroups.Add(id);
129  }
void 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)
Definition: ModRecipe.cs:78
void Terraria.ModLoader.ModRecipe.AddRecipeGroup ( int  recipeGroupID,
int  stack = 1 
)

Adds a recipe group ingredient to this recipe with the given RecipeGroupID and stack size. Vanilla recipe group IDs can be found in Terraria.ID.RecipeGroupID and modded recipe group IDs will be returned from RecipeGroup.RegisterGroup.

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

Definition at line 137 of file ModRecipe.cs.

138  {
139  if (!RecipeGroup.recipeGroups.ContainsKey(recipeGroupID)) {
140  throw new RecipeException("A recipe group with the ID " + recipeGroupID + " does not exist.");
141  }
142  RecipeGroup rec = RecipeGroup.recipeGroups[recipeGroupID];
143  AddIngredient(rec.ValidItems[rec.IconicItemIndex], stack);
144  acceptedGroups.Add(recipeGroupID);
145  }
void 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)
Definition: ModRecipe.cs:78
void Terraria.ModLoader.ModRecipe.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

Definition at line 152 of file ModRecipe.cs.

References Terraria.ModLoader.TileLoader.TileCount.

152  {
153  if (numTiles == 14)
154  throw new RecipeException("Recipe already has maximum number of tiles. 14 is the max.");
155  if (tileID < 0 || tileID >= TileLoader.TileCount) {
156  throw new RecipeException("No tile has ID " + tileID);
157  }
158  this.requiredTile[numTiles] = tileID;
159  numTiles++;
160  }
void Terraria.ModLoader.ModRecipe.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 ModRecipe.AddTile(tileID).

Definition at line 168 of file ModRecipe.cs.

References Terraria.ModLoader.Environment, Terraria.ModLoader.Mod.Name, and Terraria.ModLoader.Mod.TileType().

168  {
169  if (mod == null) {
170  mod = this.mod;
171  }
172  int type = mod.TileType(tileName);
173  if (type == 0) {
174  string message = "The tile " + tileName + " does not exist in the mod " + mod.Name + "." + Environment.NewLine;
175  message += "If you are trying to use a vanilla tile, try using ModRecipe.AddTile(tileID).";
176  throw new RecipeException(message);
177  }
178  this.AddTile(type);
179  }
int TileType(string name)
Gets the type of the ModTile of this mod with the given name. Returns 0 if no ModTile with the given ...
void AddTile(int tileID)
Adds a required crafting station with the given tile type to this recipe. Ex: recipe.AddTile(TileID.WorkBenches)
Definition: ModRecipe.cs:152
Sandstorm, Hell, Above surface during Eclipse, Space
virtual string Name
Stores the name of the mod. This name serves as the mod&#39;s identification, and also helps with saving ...
Definition: Mod.cs:42

+ Here is the call graph for this function:

void Terraria.ModLoader.ModRecipe.AddTile ( ModTile  tile)

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

Parameters
tileThe tile.

Definition at line 185 of file ModRecipe.cs.

References Terraria.ModLoader.ModTile.Type.

185  {
186  this.AddTile(tile.Type);
187  }
void AddTile(int tileID)
Adds a required crafting station with the given tile type to this recipe. Ex: recipe.AddTile(TileID.WorkBenches)
Definition: ModRecipe.cs:152
virtual int Terraria.ModLoader.ModRecipe.ConsumeItem ( int  type,
int  numRequired 
)
virtual

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.

Parameters
typeThe type.
numRequiredThe number required.
Returns

Definition at line 213 of file ModRecipe.cs.

213  {
214  return numRequired;
215  }
virtual void Terraria.ModLoader.ModRecipe.OnCraft ( Item  item)
virtual

Allows you to make anything happen when the player uses this recipe. The item parameter is the item the player has just crafted.

Parameters
itemThe item.

Definition at line 201 of file ModRecipe.cs.

Referenced by Terraria.ModLoader.RecipeHooks.OnCraft().

201  {
202  }

+ Here is the caller graph for this function:

virtual bool Terraria.ModLoader.ModRecipe.RecipeAvailable ( )
virtual

Whether or not the conditions are met for this recipe to be available for the player to use. This hook can be used for conditions unrelated to items or tiles (for example, biome or time).

Returns
Whether or not the conditions are met for this recipe to be available for the player to use.

Definition at line 193 of file ModRecipe.cs.

Referenced by Terraria.ModLoader.RecipeHooks.RecipeAvailable().

193  {
194  return true;
195  }

+ Here is the caller graph for this function:

void Terraria.ModLoader.ModRecipe.SetResult ( int  itemID,
int  stack = 1 
)

Sets the result of this recipe with the given item type and stack size.

Parameters
itemIDThe item identifier.
stackThe stack.

Definition at line 39 of file ModRecipe.cs.

39  {
40  this.createItem.SetDefaults(itemID, false);
41  this.createItem.stack = stack;
42  }
void Terraria.ModLoader.ModRecipe.SetResult ( Mod  mod,
string  itemName,
int  stack = 1 
)

Sets the result of 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 the item originates from.
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.

Definition at line 51 of file ModRecipe.cs.

References Terraria.ModLoader.Environment, Terraria.ModLoader.Mod.ItemType(), and Terraria.ModLoader.Mod.Name.

51  {
52  if (mod == null) {
53  mod = this.mod;
54  }
55  int type = mod.ItemType(itemName);
56  if (type == 0) {
57  string message = "The item " + itemName + " does not exist in the mod " + mod.Name + "." + Environment.NewLine;
58  message += "If you are trying to use a vanilla item, try removing the first argument.";
59  throw new RecipeException(message);
60  }
61  this.SetResult(type, stack);
62  }
int ItemType(string name)
Gets the internal ID / type of the ModItem corresponding to the name. Returns 0 if no ModItem with th...
void SetResult(int itemID, int stack=1)
Sets the result of this recipe with the given item type and stack size.
Definition: ModRecipe.cs:39
Sandstorm, Hell, Above surface during Eclipse, Space
virtual string Name
Stores the name of the mod. This name serves as the mod&#39;s identification, and also helps with saving ...
Definition: Mod.cs:42

+ Here is the call graph for this function:

void Terraria.ModLoader.ModRecipe.SetResult ( ModItem  item,
int  stack = 1 
)

Sets the result of this recipe to the given type of item and stack size. Useful in ModItem.AddRecipes.

Parameters
itemThe item.
stackThe stack.

Definition at line 69 of file ModRecipe.cs.

References Terraria.ModLoader.ModItem.item.

69  {
70  this.SetResult(item.item.type, stack);
71  }
void SetResult(int itemID, int stack=1)
Sets the result of this recipe with the given item type and stack size.
Definition: ModRecipe.cs:39

Member Data Documentation

readonly Mod Terraria.ModLoader.ModRecipe.mod

Definition at line 12 of file ModRecipe.cs.

int Terraria.ModLoader.ModRecipe.numIngredients = 0
private

Definition at line 13 of file ModRecipe.cs.

int Terraria.ModLoader.ModRecipe.numTiles = 0
private

Definition at line 14 of file ModRecipe.cs.

Property Documentation

int Terraria.ModLoader.ModRecipe.RecipeIndex
getprivate set

The index of the recipe in the Main.recipe array.

Definition at line 19 of file ModRecipe.cs.