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

This class will search through all existing recipes for you based on criteria that you give it. It's useful for finding a particular vanilla recipe that you wish to remove or edit. Use this by creating new instances with the empty constructor for each search you perform. More...

+ Collaboration diagram for Terraria.ModLoader.RecipeFinder:

Public Member Functions

 RecipeFinder ()
 
void AddIngredient (int itemID, int stack=1)
 Adds an ingredient with the given item type and stack size to the search criteria. More...
 
void AddRecipeGroup (int recipeGroupID, int stack=1)
 Adds a recipe group ingredient with the given RecipeGroupID and stack size to the search criteria. More...
 
void AddRecipeGroup (string name, int stack=1)
 Adds a recipe group ingredient with the given RecipeGroup name and stack size to the search criteria. More...
 
void AddTile (int tileID)
 Adds a required crafting station with the given tile type to the search criteria. More...
 
Recipe FindExactRecipe ()
 Searches for a recipe that matches the search criteria exactly, then returns it. That means the recipe will have exactly the same ingredients, tiles, liquid requirements, recipe groups, and result; even the stack sizes will match. If no recipe with an exact match is found, this will return null. More...
 
List< Recipe > SearchRecipes ()
 Searches for all recipes that include the search criteria, then returns them in a list. In terms of ingredients, it will search for recipes that include all the search criteria ingredients, with stack sizes greater than or equal to the search criteria. It will also make sure the recipes include all search criteria recipe groups and tiles. If the search criteria includes a result, the recipes will also have the same result with a stack size greater than or equal to the search criteria. Finally, if needWater, needLava, or needHoney are set to true, the found recipes will also have them set to true. More...
 
void SetResult (int itemID, int stack=1)
 Sets the search criteria's result to the given item type and stack size. More...
 

Public Attributes

bool needHoney
 Adds the requirement of being nearby honey to the search criteria. Defaults to false. More...
 
bool needLava
 Adds the requirement of being nearby lava to the search criteria. Defaults to false. More...
 
bool needWater
 Adds the requirement of being nearby water to the search criteria. Defaults to false. More...
 

Static Private Member Functions

static List< int > GetAcceptedGroups (Recipe recipe)
 

Private Attributes

List< int > groups = new List<int>()
 
List< Item > items = new List<Item>()
 
Item result = new Item()
 
List< int > tiles = new List<int>()
 

Detailed Description

This class will search through all existing recipes for you based on criteria that you give it. It's useful for finding a particular vanilla recipe that you wish to remove or edit. Use this by creating new instances with the empty constructor for each search you perform.

Definition at line 10 of file RecipeFinder.cs.

Constructor & Destructor Documentation

◆ RecipeFinder()

Terraria.ModLoader.RecipeFinder.RecipeFinder ( )

Definition at line 29 of file RecipeFinder.cs.

29 {
30 }

Member Function Documentation

◆ AddIngredient()

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

Adds an ingredient with the given item type and stack size to the search criteria.

Parameters
itemIDThe item ID of the ingredient to add.
stackThe stack of the ingredient to add.

Definition at line 37 of file RecipeFinder.cs.

37 {
38 if (itemID <= 0 || itemID >= ItemLoader.ItemCount) {
39 throw new RecipeException("No item has ID " + itemID);
40 }
41 Item item = new Item();
42 item.SetDefaults(itemID, false);
43 item.stack = stack;
44 items.Add(item);
45 }

References Terraria.ModLoader.Item, Terraria.ModLoader.ItemLoader.ItemCount, and Terraria.ModLoader.RecipeFinder.items.

Referenced by Terraria.ModLoader.RecipeFinder.AddRecipeGroup().

+ Here is the caller graph for this function:

◆ AddRecipeGroup() [1/2]

void Terraria.ModLoader.RecipeFinder.AddRecipeGroup ( int  recipeGroupID,
int  stack = 1 
)

Adds a recipe group ingredient with the given RecipeGroupID and stack size to the search criteria.

Parameters
nameThe RecipeGroupID of the recipegroup to accept.
stackThe stack of the recipegroup to accept.

Definition at line 67 of file RecipeFinder.cs.

68 {
69 if (!RecipeGroup.recipeGroupIDs.ContainsValue(recipeGroupID)) {
70 throw new RecipeException("No recipe group has the RecipeGroupID " + recipeGroupID);
71 }
72 RecipeGroup rec = RecipeGroup.recipeGroups[recipeGroupID];
73 AddIngredient(rec.ValidItems[rec.IconicItemIndex], stack);
74 groups.Add(recipeGroupID);
75 }
void AddIngredient(int itemID, int stack=1)
Adds an ingredient with the given item type and stack size to the search criteria.
Definition: RecipeFinder.cs:37

References Terraria.ModLoader.RecipeFinder.AddIngredient(), and Terraria.ModLoader.RecipeFinder.groups.

+ Here is the call graph for this function:

◆ AddRecipeGroup() [2/2]

void Terraria.ModLoader.RecipeFinder.AddRecipeGroup ( string  name,
int  stack = 1 
)

Adds a recipe group ingredient with the given RecipeGroup name and stack size to the search criteria.

Parameters
nameThe name of the recipegroup to accept.
stackThe stack of the recipegroup to accept.

Definition at line 52 of file RecipeFinder.cs.

52 {
53 if (!RecipeGroup.recipeGroupIDs.ContainsKey(name)) {
54 throw new RecipeException("No recipe group is named " + name);
55 }
56 int id = RecipeGroup.recipeGroupIDs[name];
57 RecipeGroup rec = RecipeGroup.recipeGroups[id];
58 AddIngredient(rec.ValidItems[rec.IconicItemIndex], stack);
59 groups.Add(id);
60 }

References Terraria.ModLoader.RecipeFinder.AddIngredient(), and Terraria.ModLoader.RecipeFinder.groups.

+ Here is the call graph for this function:

◆ AddTile()

void Terraria.ModLoader.RecipeFinder.AddTile ( int  tileID)

Adds a required crafting station with the given tile type to the search criteria.

Parameters
tileIDThe tile ID of the tile to add.

Definition at line 94 of file RecipeFinder.cs.

94 {
95 if (tileID < 0 || tileID >= TileLoader.TileCount) {
96 throw new RecipeException("No tile has ID " + tileID);
97 }
98 tiles.Add(tileID);
99 }

References Terraria.ModLoader.TileLoader.TileCount, and Terraria.ModLoader.RecipeFinder.tiles.

◆ FindExactRecipe()

Recipe Terraria.ModLoader.RecipeFinder.FindExactRecipe ( )

Searches for a recipe that matches the search criteria exactly, then returns it. That means the recipe will have exactly the same ingredients, tiles, liquid requirements, recipe groups, and result; even the stack sizes will match. If no recipe with an exact match is found, this will return null.

Returns
The recipe found matching the finder's criteria.

Definition at line 105 of file RecipeFinder.cs.

105 {
106 for (int k = 0; k < Recipe.numRecipes; k++) {
107 Recipe recipe = Main.recipe[k];
108 bool matches = true;
109 List<Item> checkItems = new List<Item>(items);
110 for (int i = 0; i < Recipe.maxRequirements; i++) {
111 Item item = recipe.requiredItem[i];
112 if (item.type == 0) {
113 break;
114 }
115 bool itemMatched = false;
116 for (int j = 0; j < checkItems.Count; j++) {
117 if (item.type == checkItems[j].type && item.stack == checkItems[j].stack) {
118 itemMatched = true;
119 checkItems.RemoveAt(j);
120 break;
121 }
122 }
123 if (!itemMatched) {
124 matches = false;
125 break;
126 }
127 }
128 if (checkItems.Count > 0) {
129 matches = false;
130 }
131 List<int> checkGroups = new List<int>(groups);
132 List<int> acceptedGroups = GetAcceptedGroups(recipe);
133 for (int i = 0; i < acceptedGroups.Count; i++) {
134 int group = acceptedGroups[i];
135 bool groupMatched = false;
136 for (int j = 0; j < checkGroups.Count; j++) {
137 if (group == checkGroups[j]) {
138 groupMatched = true;
139 checkGroups.RemoveAt(j);
140 break;
141 }
142 }
143 if (!groupMatched) {
144 matches = false;
145 break;
146 }
147 }
148 if (checkGroups.Count > 0) {
149 matches = false;
150 }
151 if (result.type != recipe.createItem.type || result.stack != recipe.createItem.stack) {
152 matches = false;
153 }
154 List<int> checkTiles = new List<int>(tiles);
155 for (int i = 0; i < Recipe.maxRequirements; i++) {
156 int tile = recipe.requiredTile[i];
157 if (tile == -1) {
158 break;
159 }
160 bool tileMatched = false;
161 for (int j = 0; j < checkTiles.Count; j++) {
162 if (tile == checkTiles[j]) {
163 tileMatched = true;
164 checkTiles.RemoveAt(j);
165 break;
166 }
167 }
168 if (!tileMatched) {
169 matches = false;
170 break;
171 }
172 }
173 if (checkTiles.Count > 0) {
174 matches = false;
175 }
176 if (needWater != recipe.needWater) {
177 matches = false;
178 }
179 else if (needLava != recipe.needLava) {
180 matches = false;
181 }
182 else if (needHoney != recipe.needHoney) {
183 matches = false;
184 }
185 if (matches) {
186 return recipe;
187 }
188 }
189 return null;
190 }
bool needLava
Adds the requirement of being nearby lava to the search criteria. Defaults to false.
Definition: RecipeFinder.cs:23
bool needWater
Adds the requirement of being nearby water to the search criteria. Defaults to false.
Definition: RecipeFinder.cs:19
static List< int > GetAcceptedGroups(Recipe recipe)
bool needHoney
Adds the requirement of being nearby honey to the search criteria. Defaults to false.
Definition: RecipeFinder.cs:27

References Terraria.ModLoader.RecipeFinder.GetAcceptedGroups(), Terraria.ModLoader.RecipeFinder.groups, Terraria.ModLoader.Item, Terraria.ModLoader.RecipeFinder.items, Terraria.ModLoader.RecipeFinder.needHoney, Terraria.ModLoader.RecipeFinder.needLava, Terraria.ModLoader.RecipeFinder.needWater, Terraria.ModLoader.RecipeFinder.result, and Terraria.ModLoader.RecipeFinder.tiles.

+ Here is the call graph for this function:

◆ GetAcceptedGroups()

static List< int > Terraria.ModLoader.RecipeFinder.GetAcceptedGroups ( Recipe  recipe)
staticprivate

Definition at line 271 of file RecipeFinder.cs.

271 {
272 List<int> acceptedGroups = new List<int>(recipe.acceptedGroups);
273 if (recipe.anyWood) {
274 acceptedGroups.Add(RecipeGroupID.Wood);
275 }
276 if (recipe.anyIronBar) {
277 acceptedGroups.Add(RecipeGroupID.IronBar);
278 }
279 if (recipe.anySand) {
280 acceptedGroups.Add(RecipeGroupID.Sand);
281 }
282 if (recipe.anyPressurePlate) {
283 acceptedGroups.Add(RecipeGroupID.PressurePlate);
284 }
285 if (recipe.anyFragment) {
286 acceptedGroups.Add(RecipeGroupID.Fragment);
287 }
288 return acceptedGroups;
289 }

Referenced by Terraria.ModLoader.RecipeFinder.FindExactRecipe(), and Terraria.ModLoader.RecipeFinder.SearchRecipes().

+ Here is the caller graph for this function:

◆ SearchRecipes()

List< Recipe > Terraria.ModLoader.RecipeFinder.SearchRecipes ( )

Searches for all recipes that include the search criteria, then returns them in a list. In terms of ingredients, it will search for recipes that include all the search criteria ingredients, with stack sizes greater than or equal to the search criteria. It will also make sure the recipes include all search criteria recipe groups and tiles. If the search criteria includes a result, the recipes will also have the same result with a stack size greater than or equal to the search criteria. Finally, if needWater, needLava, or needHoney are set to true, the found recipes will also have them set to true.

Returns
A list containing found recipes matching the finder's criteria.

Definition at line 196 of file RecipeFinder.cs.

196 {
197 List<Recipe> recipes = new List<Recipe>();
198 for (int k = 0; k < Recipe.numRecipes; k++) {
199 Recipe recipe = Main.recipe[k];
200 bool matches = true;
201 List<Item> checkItems = new List<Item>(items);
202 for (int i = 0; i < Recipe.maxRequirements; i++) {
203 Item item = recipe.requiredItem[i];
204 if (item.type == 0) {
205 break;
206 }
207 for (int j = 0; j < checkItems.Count; j++) {
208 if (item.type == checkItems[j].type && item.stack >= checkItems[j].stack) {
209 checkItems.RemoveAt(j);
210 break;
211 }
212 }
213 }
214 if (checkItems.Count > 0) {
215 matches = false;
216 }
217 List<int> checkGroups = new List<int>(groups);
218 List<int> acceptedGroups = GetAcceptedGroups(recipe);
219 for (int i = 0; i < acceptedGroups.Count; i++) {
220 int group = acceptedGroups[i];
221 for (int j = 0; j < checkGroups.Count; j++) {
222 if (group == checkGroups[j]) {
223 checkGroups.RemoveAt(j);
224 break;
225 }
226 }
227 }
228 if (checkGroups.Count > 0) {
229 matches = false;
230 }
231 if (result.type != 0) {
232 if (result.type != recipe.createItem.type) {
233 matches = false;
234 }
235 else if (result.stack > recipe.createItem.stack) {
236 matches = false;
237 }
238 }
239 List<int> checkTiles = new List<int>(tiles);
240 for (int i = 0; i < Recipe.maxRequirements; i++) {
241 int tile = recipe.requiredTile[i];
242 if (tile == -1) {
243 break;
244 }
245 for (int j = 0; j < checkTiles.Count; j++) {
246 if (tile == checkTiles[j]) {
247 checkTiles.RemoveAt(j);
248 break;
249 }
250 }
251 }
252 if (checkTiles.Count > 0) {
253 matches = false;
254 }
255 if (needWater && !recipe.needWater) {
256 matches = false;
257 }
258 else if (needLava && !recipe.needLava) {
259 matches = false;
260 }
261 else if (needHoney && !recipe.needHoney) {
262 matches = false;
263 }
264 if (matches) {
265 recipes.Add(recipe);
266 }
267 }
268 return recipes;
269 }

References Terraria.ModLoader.RecipeFinder.GetAcceptedGroups(), Terraria.ModLoader.RecipeFinder.groups, Terraria.ModLoader.Item, Terraria.ModLoader.RecipeFinder.items, Terraria.ModLoader.RecipeFinder.needHoney, Terraria.ModLoader.RecipeFinder.needLava, Terraria.ModLoader.RecipeFinder.needWater, Terraria.ModLoader.RecipeFinder.result, and Terraria.ModLoader.RecipeFinder.tiles.

+ Here is the call graph for this function:

◆ SetResult()

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

Sets the search criteria's result to the given item type and stack size.

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

Definition at line 82 of file RecipeFinder.cs.

82 {
83 if (itemID <= 0 || itemID >= ItemLoader.ItemCount) {
84 throw new RecipeException("No item has ID " + itemID);
85 }
86 result.SetDefaults(itemID, false);
87 result.stack = stack;
88 }

References Terraria.ModLoader.ItemLoader.ItemCount, and Terraria.ModLoader.RecipeFinder.result.

Member Data Documentation

◆ groups

List<int> Terraria.ModLoader.RecipeFinder.groups = new List<int>()
private

◆ items

List<Item> Terraria.ModLoader.RecipeFinder.items = new List<Item>()
private

◆ needHoney

bool Terraria.ModLoader.RecipeFinder.needHoney

Adds the requirement of being nearby honey to the search criteria. Defaults to false.

Definition at line 27 of file RecipeFinder.cs.

Referenced by Terraria.ModLoader.RecipeFinder.FindExactRecipe(), and Terraria.ModLoader.RecipeFinder.SearchRecipes().

◆ needLava

bool Terraria.ModLoader.RecipeFinder.needLava

Adds the requirement of being nearby lava to the search criteria. Defaults to false.

Definition at line 23 of file RecipeFinder.cs.

Referenced by Terraria.ModLoader.RecipeFinder.FindExactRecipe(), and Terraria.ModLoader.RecipeFinder.SearchRecipes().

◆ needWater

bool Terraria.ModLoader.RecipeFinder.needWater

Adds the requirement of being nearby water to the search criteria. Defaults to false.

Definition at line 19 of file RecipeFinder.cs.

Referenced by Terraria.ModLoader.RecipeFinder.FindExactRecipe(), and Terraria.ModLoader.RecipeFinder.SearchRecipes().

◆ result

Item Terraria.ModLoader.RecipeFinder.result = new Item()
private

◆ tiles

List<int> Terraria.ModLoader.RecipeFinder.tiles = new List<int>()
private