Terraria ModLoader  0.10.1.5
A framework for 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 (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< Itemitems = 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

Terraria.ModLoader.RecipeFinder.RecipeFinder ( )

Definition at line 29 of file RecipeFinder.cs.

29  {
30  }

Member Function Documentation

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.

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

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  }
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  }
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
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 79 of file RecipeFinder.cs.

References Terraria.ModLoader.TileLoader.TileCount.

79  {
80  if (tileID < 0 || tileID >= TileLoader.TileCount) {
81  throw new RecipeException("No tile has ID " + tileID);
82  }
83  tiles.Add(tileID);
84  }
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 90 of file RecipeFinder.cs.

References Terraria.ModLoader.Item.

90  {
91  for (int k = 0; k < Recipe.numRecipes; k++) {
92  Recipe recipe = Main.recipe[k];
93  bool matches = true;
94  List<Item> checkItems = new List<Item>(items);
95  for (int i = 0; i < Recipe.maxRequirements; i++) {
96  Item item = recipe.requiredItem[i];
97  if (item.type == 0) {
98  break;
99  }
100  bool itemMatched = false;
101  for (int j = 0; j < checkItems.Count; j++) {
102  if (item.type == checkItems[j].type && item.stack == checkItems[j].stack) {
103  itemMatched = true;
104  checkItems.RemoveAt(j);
105  break;
106  }
107  }
108  if (!itemMatched) {
109  matches = false;
110  break;
111  }
112  }
113  if (checkItems.Count > 0) {
114  matches = false;
115  }
116  List<int> checkGroups = new List<int>(groups);
117  List<int> acceptedGroups = GetAcceptedGroups(recipe);
118  for (int i = 0; i < acceptedGroups.Count; i++) {
119  int group = acceptedGroups[i];
120  bool groupMatched = false;
121  for (int j = 0; j < checkGroups.Count; j++) {
122  if (group == checkGroups[j]) {
123  groupMatched = true;
124  checkGroups.RemoveAt(j);
125  break;
126  }
127  }
128  if (!groupMatched) {
129  matches = false;
130  break;
131  }
132  }
133  if (checkGroups.Count > 0) {
134  matches = false;
135  }
136  if (result.type != recipe.createItem.type || result.stack != recipe.createItem.stack) {
137  matches = false;
138  }
139  List<int> checkTiles = new List<int>(tiles);
140  for (int i = 0; i < Recipe.maxRequirements; i++) {
141  int tile = recipe.requiredTile[i];
142  if (tile == -1) {
143  break;
144  }
145  bool tileMatched = false;
146  for (int j = 0; j < checkTiles.Count; j++) {
147  if (tile == checkTiles[j]) {
148  tileMatched = true;
149  checkTiles.RemoveAt(j);
150  break;
151  }
152  }
153  if (!tileMatched) {
154  matches = false;
155  break;
156  }
157  }
158  if (checkTiles.Count > 0) {
159  matches = false;
160  }
161  if (needWater != recipe.needWater) {
162  matches = false;
163  }
164  else if (needLava != recipe.needLava) {
165  matches = false;
166  }
167  else if (needHoney != recipe.needHoney) {
168  matches = false;
169  }
170  if (matches) {
171  return recipe;
172  }
173  }
174  return null;
175  }
bool needHoney
Adds the requirement of being nearby honey to the search criteria. Defaults to false.
Definition: RecipeFinder.cs:27
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)
static List<int> Terraria.ModLoader.RecipeFinder.GetAcceptedGroups ( Recipe  recipe)
staticprivate

Definition at line 256 of file RecipeFinder.cs.

256  {
257  List<int> acceptedGroups = new List<int>(recipe.acceptedGroups);
258  if (recipe.anyWood) {
259  acceptedGroups.Add(RecipeGroupID.Wood);
260  }
261  if (recipe.anyIronBar) {
262  acceptedGroups.Add(RecipeGroupID.IronBar);
263  }
264  if (recipe.anySand) {
265  acceptedGroups.Add(RecipeGroupID.Sand);
266  }
267  if (recipe.anyPressurePlate) {
268  acceptedGroups.Add(RecipeGroupID.PressurePlate);
269  }
270  if (recipe.anyFragment) {
271  acceptedGroups.Add(RecipeGroupID.Fragment);
272  }
273  return acceptedGroups;
274  }
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 181 of file RecipeFinder.cs.

References Terraria.ModLoader.Item.

181  {
182  List<Recipe> recipes = new List<Recipe>();
183  for (int k = 0; k < Recipe.numRecipes; k++) {
184  Recipe recipe = Main.recipe[k];
185  bool matches = true;
186  List<Item> checkItems = new List<Item>(items);
187  for (int i = 0; i < Recipe.maxRequirements; i++) {
188  Item item = recipe.requiredItem[i];
189  if (item.type == 0) {
190  break;
191  }
192  for (int j = 0; j < checkItems.Count; j++) {
193  if (item.type == checkItems[j].type && item.stack >= checkItems[j].stack) {
194  checkItems.RemoveAt(j);
195  break;
196  }
197  }
198  }
199  if (checkItems.Count > 0) {
200  matches = false;
201  }
202  List<int> checkGroups = new List<int>(groups);
203  List<int> acceptedGroups = GetAcceptedGroups(recipe);
204  for (int i = 0; i < acceptedGroups.Count; i++) {
205  int group = acceptedGroups[i];
206  for (int j = 0; j < checkGroups.Count; j++) {
207  if (group == checkGroups[j]) {
208  checkGroups.RemoveAt(j);
209  break;
210  }
211  }
212  }
213  if (checkGroups.Count > 0) {
214  matches = false;
215  }
216  if (result.type != 0) {
217  if (result.type != recipe.createItem.type) {
218  matches = false;
219  }
220  else if (result.stack > recipe.createItem.stack) {
221  matches = false;
222  }
223  }
224  List<int> checkTiles = new List<int>(tiles);
225  for (int i = 0; i < Recipe.maxRequirements; i++) {
226  int tile = recipe.requiredTile[i];
227  if (tile == -1) {
228  break;
229  }
230  for (int j = 0; j < checkTiles.Count; j++) {
231  if (tile == checkTiles[j]) {
232  checkTiles.RemoveAt(j);
233  break;
234  }
235  }
236  }
237  if (checkTiles.Count > 0) {
238  matches = false;
239  }
240  if (needWater && !recipe.needWater) {
241  matches = false;
242  }
243  else if (needLava && !recipe.needLava) {
244  matches = false;
245  }
246  else if (needHoney && !recipe.needHoney) {
247  matches = false;
248  }
249  if (matches) {
250  recipes.Add(recipe);
251  }
252  }
253  return recipes;
254  }
bool needHoney
Adds the requirement of being nearby honey to the search criteria. Defaults to false.
Definition: RecipeFinder.cs:27
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)
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 67 of file RecipeFinder.cs.

References Terraria.ModLoader.ItemLoader.ItemCount.

67  {
68  if (itemID <= 0 || itemID >= ItemLoader.ItemCount) {
69  throw new RecipeException("No item has ID " + itemID);
70  }
71  result.SetDefaults(itemID, false);
72  result.stack = stack;
73  }

Member Data Documentation

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

Definition at line 13 of file RecipeFinder.cs.

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

Definition at line 12 of file RecipeFinder.cs.

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.

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.

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.

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

Definition at line 14 of file RecipeFinder.cs.

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

Definition at line 15 of file RecipeFinder.cs.