Terraria ModLoader  0.10.1.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  this.requiredItem[numIngredients].SetDefaults(itemID, false);
78  this.requiredItem[numIngredients].stack = stack;
80  }
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 89 of file ModRecipe.cs.

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

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

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

References Terraria.ModLoader.ModItem.item.

107  {
108  this.AddIngredient(item.item.type, stack);
109  }
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 199 of file ModRecipe.cs.

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

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

References Terraria.ModLoader.TileLoader.TileCount.

132  {
133  if (tileID < 0 || tileID >= TileLoader.TileCount) {
134  throw new RecipeException("No tile has ID " + tileID);
135  }
136  this.requiredTile[numTiles] = tileID;
137  numTiles++;
138  }
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 146 of file ModRecipe.cs.

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

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

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

References Terraria.ModLoader.ModTile.Type.

163  {
164  this.AddTile(tile.Type);
165  }
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:132
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 191 of file ModRecipe.cs.

191  {
192  return numRequired;
193  }
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 179 of file ModRecipe.cs.

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

179  {
180  }

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

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

171  {
172  return true;
173  }

+ 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:39

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