Terraria.ModLoader.RecipeFinder.SearchRecipes C# (CSharp) Method

SearchRecipes() public method

public SearchRecipes ( ) : List
return List
		public List<Recipe> SearchRecipes()
		{
			List<Recipe> recipes = new List<Recipe>();
			for (int k = 0; k < Recipe.numRecipes; k++)
			{
				Recipe recipe = Main.recipe[k];
				bool matches = true;
				List<Item> checkItems = new List<Item>(items);
				for (int i = 0; i < Recipe.maxRequirements; i++)
				{
					Item item = recipe.requiredItem[i];
					if (item.type == 0)
					{
						break;
					}
					for (int j = 0; j < checkItems.Count; j++)
					{
						if (item.type == checkItems[j].type && item.stack >= checkItems[j].stack)
						{
							checkItems.RemoveAt(j);
							break;
						}
					}
				}
				if (checkItems.Count > 0)
				{
					matches = false;
				}
				List<int> checkGroups = new List<int>(groups);
				List<int> acceptedGroups = GetAcceptedGroups(recipe);
				for (int i = 0; i < acceptedGroups.Count; i++)
				{
					int group = acceptedGroups[i];
					for (int j = 0; j < checkGroups.Count; j++)
					{
						if (group == checkGroups[j])
						{
							checkGroups.RemoveAt(j);
							break;
						}
					}
				}
				if (checkGroups.Count > 0)
				{
					matches = false;
				}
				if (result.type != 0)
				{
					if (result.type != recipe.createItem.type)
					{
						matches = false;
					}
					else if (result.stack > recipe.createItem.stack)
					{
						matches = false;
					}
				}
				List<int> checkTiles = new List<int>(tiles);
				for (int i = 0; i < Recipe.maxRequirements; i++)
				{
					int tile = recipe.requiredTile[i];
					if (tile == -1)
					{
						break;
					}
					for (int j = 0; j < checkTiles.Count; j++)
					{
						if (tile == checkTiles[j])
						{
							checkTiles.RemoveAt(j);
							break;
						}
					}
				}
				if (checkTiles.Count > 0)
				{
					matches = false;
				}
				if (needWater && !recipe.needWater)
				{
					matches = false;
				}
				else if (needLava && !recipe.needLava)
				{
					matches = false;
				}
				else if (needHoney && !recipe.needHoney)
				{
					matches = false;
				}
				if (matches)
				{
					recipes.Add(recipe);
				}
			}
			return recipes;
		}

Usage Example

Exemplo n.º 1
0
        public static void TestRecipeEditor(Mod mod)
        {
            RecipeFinder finder = new RecipeFinder();
            finder.AddIngredient(ItemID.Chain);
            foreach (Recipe recipe in finder.SearchRecipes())
            {
                RecipeEditor editor = new RecipeEditor(recipe);
                editor.DeleteIngredient(ItemID.Chain);
            }

            finder = new RecipeFinder();
            finder.AddRecipeGroup("IronBar");
            finder.AddTile(TileID.Anvils);
            finder.SetResult(ItemID.Chain, 10);
            Recipe recipe2 = finder.FindExactRecipe();
            if (recipe2 != null)
            {
                RecipeEditor editor = new RecipeEditor(recipe2);
                editor.DeleteRecipe();
            }
        }