I found that there are two recipes in Minecraft that haven't RecipeOutput (at least on load). It's recipe for dyeing armor and copying maps. Lets just ignore them. So final code is:
private static void RemoveRecipe(ItemStack resultItem)
{
ItemStack recipeResult = null;
ArrayList recipes = (ArrayList) CraftingManager.getInstance().getRecipeList();
for (int scan = 0; scan < recipes.size(); scan++)
{
IRecipe tmpRecipe = (IRecipe) recipes.get(scan);
recipeResult = tmpRecipe.getRecipeOutput();
if (recipeResult != null) {
if (recipeResult.itemID == resultItem.itemID && recipeResult.getItemDamage() == resultItem.getItemDamage())
{
System.out.println("Removed Recipe: " + recipes.get(scan) + " -> " + recipeResult);
recipes.remove(scan);
scan--; //list is shifted after remove! Adjust index, so next time we will check this value again.
}
}
}
}
How do you remove a recipe in RecipesFood.java? Do I just add another "this.RemoveRecipe(new ItemStack(Item.paper, 1));" line to remove another recipe?
I found out that you only have to change the itemstack number to the recipe output amount(ex. this.RemoveRecipe(newItemStack(Item.cookie,8));), so just ignore this
This code works great. If you don't understand it, what it's doing is looking through the entire list of recipes and removes all of the recipes that contain that item as an output. For example, If you call RemoveRecipe(new ItemStack(Item.pickaxeWood)); then it will remove all recipes that produce a wooden pickaxe. Then you would just add back in the ones you want.
Just be sure to include this little bit of code as well:
Otherwise it won't remove certain recipes that are considered "ShapedOreRecipe". This was a problem I had that took me hours to figure out. The problem is that underneath, the OreDictionary class was going through and replacing the bed recipe with a ShapedOreRecipe to allow for the different colored wool to be used in the recipe. Since the recipe was no longer an instance of ShapedRecipe or ShapelessRecipe it wasn't finding it in the list and it wasn't removing it, so just make sure to include that extra if statement in there if you run into problems like me.
So the whole code would look something like this:
public static void RemoveRecipe(ItemStack resultItem) //Code by yope_fried inspired by pigalot, modified by jayperdu
{
ItemStack recipeResult = null;
ArrayList recipes = (ArrayList) CraftingManager.getInstance().getRecipeList();
for (int i = 0; i < recipes.size(); i++)
{
IRecipe tmpRecipe = (IRecipe) recipes.get(i);
if (tmpRecipe instanceof ShapedRecipes)
{
ShapedRecipes recipe = (ShapedRecipes)tmpRecipe;
recipeResult = recipe.getRecipeOutput();
}
if (tmpRecipe instanceof ShapelessRecipes)
{
ShapelessRecipes recipe = (ShapelessRecipes)tmpRecipe;
recipeResult = recipe.getRecipeOutput();
}
if (tmpRecipe instanceof ShapedOreRecipe)
{
ShapedOreRecipe recipe = (ShapedOreRecipe)tmpRecipe;
recipeResult = recipe.getRecipeOutput();
}
if (ItemStack.areItemStacksEqual(resultItem, recipeResult))
{
recipes.remove(i);
}
}
}
I found that there are two recipes in Minecraft that haven't RecipeOutput (at least on load). It's recipe for dyeing armor and copying maps. Lets just ignore them. So final code is:
This time i tested that on my side, code:
works fine for me.
Here is my coding
I found out that you only have to change the itemstack number to the recipe output amount(ex. this.RemoveRecipe(new ItemStack(Item.cookie, 8));), so just ignore this
This code works great. If you don't understand it, what it's doing is looking through the entire list of recipes and removes all of the recipes that contain that item as an output. For example, If you call RemoveRecipe(new ItemStack(Item.pickaxeWood)); then it will remove all recipes that produce a wooden pickaxe. Then you would just add back in the ones you want.
Just be sure to include this little bit of code as well:
Otherwise it won't remove certain recipes that are considered "ShapedOreRecipe". This was a problem I had that took me hours to figure out. The problem is that underneath, the OreDictionary class was going through and replacing the bed recipe with a ShapedOreRecipe to allow for the different colored wool to be used in the recipe. Since the recipe was no longer an instance of ShapedRecipe or ShapelessRecipe it wasn't finding it in the list and it wasn't removing it, so just make sure to include that extra if statement in there if you run into problems like me.
So the whole code would look something like this: