Terraria ModLoader  0.11.7.5
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  this.mod = mod;
30  }

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 76 of file ModRecipe.cs.

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

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

91  {
92  if (mod == null) {
93  mod = this.mod;
94  }
95  int type = mod.ItemType(itemName);
96  if (type == 0) {
97  string message = "The item " + itemName + " does not exist in the mod " + mod.Name + "." + Environment.NewLine;
98  message += "If you are trying to use a vanilla item, try removing the first argument.";
99  throw new RecipeException(message);
100  }
101  this.AddIngredient(type, stack);
102  }
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:76
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 109 of file ModRecipe.cs.

References Terraria.ModLoader.ModItem.item.

109  {
110  this.AddIngredient(item.item.type, stack);
111  }
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:76
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 219 of file ModRecipe.cs.

219  {
220  if (this.createItem == null || this.createItem.type == 0) {
221  throw new RecipeException("A recipe without any result has been added.");
222  }
223  if (this.numIngredients > 14 || this.numTiles > 14) {
224  throw new RecipeException("A recipe with either too many tiles or too many ingredients has been added. 14 is the maximum amount.");
225  }
226  for (int k = 0; k < Recipe.maxRequirements; k++) {
227  if (this.requiredTile[k] == TileID.Bottles) {
228  this.alchemy = true;
229  break;
230  }
231  }
232  if (Recipe.numRecipes >= Recipe.maxRecipes) {
233  Recipe.maxRecipes += 500;
234  Array.Resize(ref Main.recipe, Recipe.maxRecipes);
235  Array.Resize(ref Main.availableRecipe, Recipe.maxRecipes);
236  Array.Resize(ref Main.availableRecipeY, Recipe.maxRecipes);
237  for (int k = Recipe.numRecipes; k < Recipe.maxRecipes; k++) {
238  Main.recipe[k] = new Recipe();
239  Main.availableRecipeY[k] = 65f * k;
240  }
241  }
242  Main.recipe[Recipe.numRecipes] = this;
243  this.RecipeIndex = Recipe.numRecipes;
244  mod.recipes.Add(this);
245  Recipe.numRecipes++;
246  }
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 119 of file ModRecipe.cs.

119  {
120  if (!RecipeGroup.recipeGroupIDs.ContainsKey(name)) {
121  throw new RecipeException("A recipe group with the name " + name + " does not exist.");
122  }
123  int id = RecipeGroup.recipeGroupIDs[name];
124  RecipeGroup rec = RecipeGroup.recipeGroups[id];
125  AddIngredient(rec.ValidItems[rec.IconicItemIndex], stack);
126  acceptedGroups.Add(id);
127  }
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:76
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 135 of file ModRecipe.cs.

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

References Terraria.ModLoader.TileLoader.TileCount.

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

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

166  {
167  if (mod == null) {
168  mod = this.mod;
169  }
170  int type = mod.TileType(tileName);
171  if (type == 0) {
172  string message = "The tile " + tileName + " does not exist in the mod " + mod.Name + "." + Environment.NewLine;
173  message += "If you are trying to use a vanilla tile, try using ModRecipe.AddTile(tileID).";
174  throw new RecipeException(message);
175  }
176  this.AddTile(type);
177  }
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:150
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 183 of file ModRecipe.cs.

References Terraria.ModLoader.ModTile.Type.

183  {
184  this.AddTile(tile.Type);
185  }
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:150
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 211 of file ModRecipe.cs.

211  {
212  return numRequired;
213  }
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 199 of file ModRecipe.cs.

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

199  {
200  }

+ 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 191 of file ModRecipe.cs.

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

191  {
192  return true;
193  }

+ 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 37 of file ModRecipe.cs.

37  {
38  this.createItem.SetDefaults(itemID, false);
39  this.createItem.stack = stack;
40  }
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 49 of file ModRecipe.cs.

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

49  {
50  if (mod == null) {
51  mod = this.mod;
52  }
53  int type = mod.ItemType(itemName);
54  if (type == 0) {
55  string message = "The item " + itemName + " does not exist in the mod " + mod.Name + "." + Environment.NewLine;
56  message += "If you are trying to use a vanilla item, try removing the first argument.";
57  throw new RecipeException(message);
58  }
59  this.SetResult(type, stack);
60  }
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:37
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 67 of file ModRecipe.cs.

References Terraria.ModLoader.ModItem.item.

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

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.