tModLoader v0.11.8.9
A mod to make and play Terraria mods
RecipeEditor.cs
Go to the documentation of this file.
2
3namespace Terraria.ModLoader
4{
8 public class RecipeEditor
9 {
10 private Recipe recipe;
11
16 public RecipeEditor(Recipe recipe) {
17 this.recipe = recipe;
18 }
19
25 public void AddIngredient(int itemID, int stack = 1) {
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 }
42
49 public bool SetIngredientStack(int itemID, int stack) {
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 }
61
67 public bool DeleteIngredient(int itemID) {
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 }
82
88 public bool AcceptRecipeGroup(string groupName) {
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 }
99
105 public bool RejectRecipeGroup(string groupName) {
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 }
112
118 public void SetResult(int itemID, int stack = 1) {
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 }
125
131 public bool AddTile(int tileID) {
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 }
146
152 public bool DeleteTile(int tileID) {
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 }
167
172 public void SetNeedWater(bool needWater) {
173 recipe.needWater = needWater;
174 }
175
180 public void SetNeedLava(bool needLava) {
181 recipe.needLava = needLava;
182 }
183
188 public void SetNeedHoney(bool needHoney) {
189 recipe.needHoney = needHoney;
190 }
191
196 public bool DeleteRecipe() {
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 }
209 }
210}
This serves as the central class from which item-related functions are carried out....
Definition: ItemLoader.cs:22
This class allows you to make any changes you want to a recipe, whether it be adding/removing ingredi...
Definition: RecipeEditor.cs:9
bool AcceptRecipeGroup(string groupName)
Adds the recipe group with the given name to the recipe. Note that, unlike ModRecipe and RecipeFinder...
Definition: RecipeEditor.cs:88
void SetNeedLava(bool needLava)
A convenience method for setting recipe.needLava.
void SetNeedHoney(bool needHoney)
A convenience method for setting recipe.needHoney.
bool DeleteIngredient(int itemID)
Deletes the ingredient requirement with the given ID from the recipe. Returns true if the operation w...
Definition: RecipeEditor.cs:67
bool DeleteRecipe()
Completely removes the recipe from the game, making it unusable. Returns true if the operation was su...
bool SetIngredientStack(int itemID, int stack)
Sets the stack requirement of the ingredient with the given item ID in the recipe....
Definition: RecipeEditor.cs:49
void SetResult(int itemID, int stack=1)
A convenience method for setting the result of the recipe. Similar to calling recipe....
bool RejectRecipeGroup(string groupName)
Removes the recipe group with the given name from the recipe. This is the opposite of AcceptRecipeGro...
void SetNeedWater(bool needWater)
A convenience method for setting recipe.needWater.
bool AddTile(int tileID)
Adds the crafting station with the given tile ID to the recipe. Returns true if the operation was suc...
bool DeleteTile(int tileID)
Removes the crafting station with the given tile ID as a requirement from the recipe....
RecipeEditor(Recipe recipe)
Creates a recipe editor that acts on the given recipe.
Definition: RecipeEditor.cs:16
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 contain...
Definition: RecipeEditor.cs:25
This serves as the central class from which tile-related functions are supported and carried out.
Definition: TileLoader.cs:15