Terraria ModLoader  0.11.5
A framework for 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 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 203 of file ModRecipe.cs.

203  {
204  if (this.createItem == null || this.createItem.type == 0) {
205  throw new RecipeException("A recipe without any result has been added.");
206  }
207  if (this.numIngredients > 14 || this.numTiles > 14) {
208  throw new RecipeException("A recipe with either too many tiles or too many ingredients has been added. 14 is the max.");
209  }
210  for (int k = 0; k < Recipe.maxRequirements; k++) {
211  if (this.requiredTile[k] == TileID.Bottles) {
212  this.alchemy = true;
213  break;
214  }
215  }
216  if (Recipe.numRecipes >= Recipe.maxRecipes) {
217  Recipe.maxRecipes += 500;
218  Array.Resize(ref Main.recipe, Recipe.maxRecipes);
219  Array.Resize(ref Main.availableRecipe, Recipe.maxRecipes);
220  Array.Resize(ref Main.availableRecipeY, Recipe.maxRecipes);
221  for (int k = Recipe.numRecipes; k < Recipe.maxRecipes; k++) {
222  Main.recipe[k] = new Recipe();
223  Main.availableRecipeY[k] = 65f * k;
224  }
225  }
226  Main.recipe[Recipe.numRecipes] = this;
227  this.RecipeIndex = Recipe.numRecipes;
228  mod.recipes.Add(this);
229  Recipe.numRecipes++;
230  }
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.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 134 of file ModRecipe.cs.

References Terraria.ModLoader.TileLoader.TileCount.

134  {
135  if (numTiles == 14)
136  throw new RecipeException("Recipe already has maximum number of tiles. 14 is the max.");
137  if (tileID < 0 || tileID >= TileLoader.TileCount) {
138  throw new RecipeException("No tile has ID " + tileID);
139  }
140  this.requiredTile[numTiles] = tileID;
141  numTiles++;
142  }
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 150 of file ModRecipe.cs.

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

150  {
151  if (mod == null) {
152  mod = this.mod;
153  }
154  int type = mod.TileType(tileName);
155  if (type == 0) {
156  string message = "The tile " + tileName + " does not exist in the mod " + mod.Name + "." + Environment.NewLine;
157  message += "If you are trying to use a vanilla tile, try using ModRecipe.AddTile(tileID).";
158  throw new RecipeException(message);
159  }
160  this.AddTile(type);
161  }
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:134
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 167 of file ModRecipe.cs.

References Terraria.ModLoader.ModTile.Type.

167  {
168  this.AddTile(tile.Type);
169  }
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:134
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 195 of file ModRecipe.cs.

195  {
196  return numRequired;
197  }
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 183 of file ModRecipe.cs.

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

183  {
184  }

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

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

175  {
176  return true;
177  }

+ 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.