tModLoader v0.11.8.9
A mod to make and play Terraria mods
Terraria.ModLoader.RecipeEditor Class Reference

This class allows you to make any changes you want to a recipe, whether it be adding/removing ingredients, changing the result, or removing the recipe entirely. More...

+ Collaboration diagram for Terraria.ModLoader.RecipeEditor:

Public Member Functions

 RecipeEditor (Recipe recipe)
 Creates a recipe editor that acts on the given recipe. More...
 
bool AcceptRecipeGroup (string groupName)
 Adds the recipe group with the given name to the recipe. Note that, unlike ModRecipe and RecipeFinder, this won't actually add an ingredient; it will only allow existing ingredients to be interchangeable with other items. Returns true if the operation was successful. Returns false if the recipe already accepts the given recipe group. Can also throw a RecipeException. More...
 
void AddIngredient (int itemID, int stack=1)
 Adds an ingredient with the given item ID and stack size to the recipe. If the recipe already contains the ingredient, it will increase the stack requirement instead. Can also throw a RecipeException. More...
 
bool AddTile (int tileID)
 Adds the crafting station with the given tile ID to the recipe. Returns true if the operation was successful. Returns false if the recipe already requires the given tile. Can also throw a RecipeException. More...
 
bool DeleteIngredient (int itemID)
 Deletes the ingredient requirement with the given ID from the recipe. Returns true if the operation was successful. Returns false if the recipe did not contain the ingredient in the first place. Can also throw a RecipeException. More...
 
bool DeleteRecipe ()
 Completely removes the recipe from the game, making it unusable. Returns true if the operation was successful. Returns false if the recipe was already not in the game. More...
 
bool DeleteTile (int tileID)
 Removes the crafting station with the given tile ID as a requirement from the recipe. Returns true if the operation was successful. Returns false if the recipe did not require the tile in the first place. Can also throw a RecipeException. More...
 
bool RejectRecipeGroup (string groupName)
 Removes the recipe group with the given name from the recipe. This is the opposite of AcceptRecipeGroup; while it won't remove ingredients, it will make existing ingredients no longer be interchangeable with other items. Returns true if the operation was successful. Returns false if the recipe did not contain the recipe group in the first place. Can also throw a RecipeException. More...
 
bool SetIngredientStack (int itemID, int stack)
 Sets the stack requirement of the ingredient with the given item ID in the recipe. Returns true if the operation was successful. Returns false if the recipe does not contain the ingredient. Can also throw a RecipeException. More...
 
void SetNeedHoney (bool needHoney)
 A convenience method for setting recipe.needHoney. More...
 
void SetNeedLava (bool needLava)
 A convenience method for setting recipe.needLava. More...
 
void SetNeedWater (bool needWater)
 A convenience method for setting recipe.needWater. More...
 
void SetResult (int itemID, int stack=1)
 A convenience method for setting the result of the recipe. Similar to calling recipe.createItem.SetDefaults(itemID), followed by recipe.createItem.stack = stack. Can also throw a RecipeException. More...
 

Private Attributes

Recipe recipe
 

Detailed Description

This class allows you to make any changes you want to a recipe, whether it be adding/removing ingredients, changing the result, or removing the recipe entirely.

Definition at line 8 of file RecipeEditor.cs.

Constructor & Destructor Documentation

◆ RecipeEditor()

Terraria.ModLoader.RecipeEditor.RecipeEditor ( Recipe  recipe)

Creates a recipe editor that acts on the given recipe.

Parameters
recipeThe recipe this RecipeEditor should focus on.

Definition at line 16 of file RecipeEditor.cs.

16 {
17 this.recipe = recipe;
18 }

References Terraria.ModLoader.RecipeEditor.recipe.

Member Function Documentation

◆ AcceptRecipeGroup()

bool Terraria.ModLoader.RecipeEditor.AcceptRecipeGroup ( string  groupName)

Adds the recipe group with the given name to the recipe. Note that, unlike ModRecipe and RecipeFinder, this won't actually add an ingredient; it will only allow existing ingredients to be interchangeable with other items. Returns true if the operation was successful. Returns false if the recipe already accepts the given recipe group. Can also throw a RecipeException.

Parameters
groupNameThe recipegroup name to accept.
Returns
Whether adding the recipegroup was successful.

Definition at line 88 of file RecipeEditor.cs.

88 {
89 int groupID;
90 if (!RecipeGroup.recipeGroupIDs.TryGetValue(groupName, out groupID)) {
91 throw new RecipeException("No recipe group is named " + groupName);
92 }
93 if (recipe.acceptedGroups.Contains(groupID)) {
94 return false;
95 }
96 recipe.acceptedGroups.Add(groupID);
97 return true;
98 }

References Terraria.ModLoader.RecipeEditor.recipe.

◆ AddIngredient()

void Terraria.ModLoader.RecipeEditor.AddIngredient ( int  itemID,
int  stack = 1 
)

Adds an ingredient with the given item ID and stack size to the recipe. If the recipe already contains the ingredient, it will increase the stack requirement instead. Can also throw a RecipeException.

Parameters
itemIDThe required item (ingredient) ID
stackThe required item (ingredient) stack

Definition at line 25 of file RecipeEditor.cs.

25 {
26 if (itemID <= 0 || itemID >= ItemLoader.ItemCount) {
27 throw new RecipeException("No item has ID " + itemID);
28 }
29 for (int k = 0; k < Recipe.maxRequirements; k++) {
30 if (recipe.requiredItem[k].type == 0) {
31 recipe.requiredItem[k].SetDefaults(itemID, false);
32 recipe.requiredItem[k].stack = stack;
33 return;
34 }
35 if (recipe.requiredItem[k].type == itemID) {
36 recipe.requiredItem[k].stack += stack;
37 return;
38 }
39 }
40 throw new RecipeException("Recipe already has maximum number of ingredients");
41 }

References Terraria.ModLoader.ItemLoader.ItemCount, and Terraria.ModLoader.RecipeEditor.recipe.

◆ AddTile()

bool Terraria.ModLoader.RecipeEditor.AddTile ( int  tileID)

Adds the crafting station with the given tile ID to the recipe. Returns true if the operation was successful. Returns false if the recipe already requires the given tile. Can also throw a RecipeException.

Parameters
tileIDThe tile ID to add.
Returns
Whether the operation was successful

Definition at line 131 of file RecipeEditor.cs.

131 {
132 if (tileID < 0 || tileID >= TileLoader.TileCount) {
133 throw new RecipeException("No tile has ID " + tileID);
134 }
135 for (int k = 0; k < Recipe.maxRequirements; k++) {
136 if (recipe.requiredTile[k] == -1) {
137 recipe.requiredTile[k] = tileID;
138 return true;
139 }
140 if (recipe.requiredTile[k] == tileID) {
141 return false;
142 }
143 }
144 throw new RecipeException("Recipe already has maximum number of tiles");
145 }

References Terraria.ModLoader.RecipeEditor.recipe, and Terraria.ModLoader.TileLoader.TileCount.

◆ DeleteIngredient()

bool Terraria.ModLoader.RecipeEditor.DeleteIngredient ( int  itemID)

Deletes the ingredient requirement with the given ID from the recipe. Returns true if the operation was successful. Returns false if the recipe did not contain the ingredient in the first place. Can also throw a RecipeException.

Parameters
itemIDThe item ID of the ingredient to delete.
Returns
Whether the operation was successful.

Definition at line 67 of file RecipeEditor.cs.

67 {
68 if (itemID <= 0 || itemID >= ItemLoader.ItemCount) {
69 throw new RecipeException("No item has ID " + itemID);
70 }
71 for (int k = 0; k < Recipe.maxRequirements; k++) {
72 if (recipe.requiredItem[k].type == itemID) {
73 for (int j = k; j < Recipe.maxRequirements - 1; j++) {
74 recipe.requiredItem[j] = recipe.requiredItem[j + 1];
75 }
76 recipe.requiredItem[Recipe.maxRequirements - 1] = new Item();
77 return true;
78 }
79 }
80 return false;
81 }

References Terraria.ModLoader.Item, Terraria.ModLoader.ItemLoader.ItemCount, and Terraria.ModLoader.RecipeEditor.recipe.

◆ DeleteRecipe()

bool Terraria.ModLoader.RecipeEditor.DeleteRecipe ( )

Completely removes the recipe from the game, making it unusable. Returns true if the operation was successful. Returns false if the recipe was already not in the game.

Returns

Definition at line 196 of file RecipeEditor.cs.

196 {
197 for (int k = 0; k < Recipe.numRecipes; k++) {
198 if (Main.recipe[k] == recipe) {
199 for (int j = k; j < Recipe.numRecipes - 1; j++) {
200 Main.recipe[j] = Main.recipe[j + 1];
201 }
202 Main.recipe[Recipe.numRecipes - 1] = new Recipe();
203 Recipe.numRecipes--;
204 return true;
205 }
206 }
207 return false;
208 }

References Terraria.ModLoader.RecipeEditor.recipe.

◆ DeleteTile()

bool Terraria.ModLoader.RecipeEditor.DeleteTile ( int  tileID)

Removes the crafting station with the given tile ID as a requirement from the recipe. Returns true if the operation was successful. Returns false if the recipe did not require the tile in the first place. Can also throw a RecipeException.

Parameters
tileIDThe tile ID to remove.
Returns
Whether the operation was successful or not.

Definition at line 152 of file RecipeEditor.cs.

152 {
153 if (tileID < 0 || tileID >= TileLoader.TileCount) {
154 throw new RecipeException("No tile has ID " + tileID);
155 }
156 for (int k = 0; k < Recipe.maxRequirements; k++) {
157 if (recipe.requiredTile[k] == tileID) {
158 for (int j = k; j < Recipe.maxRequirements - 1; j++) {
159 recipe.requiredTile[j] = recipe.requiredTile[j + 1];
160 }
161 recipe.requiredTile[Recipe.maxRequirements - 1] = -1;
162 return true;
163 }
164 }
165 return false;
166 }

References Terraria.ModLoader.RecipeEditor.recipe, and Terraria.ModLoader.TileLoader.TileCount.

◆ RejectRecipeGroup()

bool Terraria.ModLoader.RecipeEditor.RejectRecipeGroup ( string  groupName)

Removes the recipe group with the given name from the recipe. This is the opposite of AcceptRecipeGroup; while it won't remove ingredients, it will make existing ingredients no longer be interchangeable with other items. Returns true if the operation was successful. Returns false if the recipe did not contain the recipe group in the first place. Can also throw a RecipeException.

Parameters
groupNameThe recipegroup name to reject.
Returns
Whether removing the recipegroup was successful.

Definition at line 105 of file RecipeEditor.cs.

105 {
106 int groupID;
107 if (!RecipeGroup.recipeGroupIDs.TryGetValue(groupName, out groupID)) {
108 throw new RecipeException("No recipe group is named " + groupName);
109 }
110 return recipe.acceptedGroups.Remove(groupID);
111 }

References Terraria.ModLoader.RecipeEditor.recipe.

◆ SetIngredientStack()

bool Terraria.ModLoader.RecipeEditor.SetIngredientStack ( int  itemID,
int  stack 
)

Sets the stack requirement of the ingredient with the given item ID in the recipe. Returns true if the operation was successful. Returns false if the recipe does not contain the ingredient. Can also throw a RecipeException.

Parameters
itemIDThe item ID of the ingredient to set the stack on.
stackThe new stack amount.
Returns
Whether the operation was successful.

Definition at line 49 of file RecipeEditor.cs.

49 {
50 if (itemID <= 0 || itemID >= ItemLoader.ItemCount) {
51 throw new RecipeException("No item has ID " + itemID);
52 }
53 for (int k = 0; k < Recipe.maxRequirements; k++) {
54 if (recipe.requiredItem[k].type == itemID) {
55 recipe.requiredItem[k].stack = stack;
56 return true;
57 }
58 }
59 return false;
60 }

References Terraria.ModLoader.ItemLoader.ItemCount, and Terraria.ModLoader.RecipeEditor.recipe.

◆ SetNeedHoney()

void Terraria.ModLoader.RecipeEditor.SetNeedHoney ( bool  needHoney)

A convenience method for setting recipe.needHoney.

Parameters
needHoneyWhether the recipe needs honey.

Definition at line 188 of file RecipeEditor.cs.

188 {
189 recipe.needHoney = needHoney;
190 }

◆ SetNeedLava()

void Terraria.ModLoader.RecipeEditor.SetNeedLava ( bool  needLava)

A convenience method for setting recipe.needLava.

Parameters
needLavaWhether the recipe needs lava.

Definition at line 180 of file RecipeEditor.cs.

180 {
181 recipe.needLava = needLava;
182 }

◆ SetNeedWater()

void Terraria.ModLoader.RecipeEditor.SetNeedWater ( bool  needWater)

A convenience method for setting recipe.needWater.

Parameters
needWaterWhether the recipe needs water.

Definition at line 172 of file RecipeEditor.cs.

172 {
173 recipe.needWater = needWater;
174 }

◆ SetResult()

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

A convenience method for setting the result of the recipe. Similar to calling recipe.createItem.SetDefaults(itemID), followed by recipe.createItem.stack = stack. Can also throw a RecipeException.

Parameters
itemIDThe ID of the item to set as result.
stackThe stack of the item to set as result.

Definition at line 118 of file RecipeEditor.cs.

118 {
119 if (itemID <= 0 || itemID >= ItemLoader.ItemCount) {
120 throw new RecipeException("No item has ID " + itemID);
121 }
122 recipe.createItem.SetDefaults(itemID);
123 recipe.createItem.stack = stack;
124 }

References Terraria.ModLoader.ItemLoader.ItemCount, and Terraria.ModLoader.RecipeEditor.recipe.

Member Data Documentation

◆ recipe