Jump to content

Removing a Vanilla Smelting Recipe [1.10]


minecraftbigfoot

Recommended Posts

package mod.brandy;

import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.FurnaceRecipes;

public class BrandyAntiRecipes {

	public static void removeRecipes()
	{
		ItemStack stone = new ItemStack(Blocks.STONE, 1, 0);
		FurnaceRecipes.instance().getSmeltingList().remove(stone);
	}
}

 

This is called in my init() in my main class, however it does nothing. Clearly I've made a bit of a mistake :)

 

thank you~

 

version: 1.10

Edited by minecraftbigfoot
1.10
Link to comment
Share on other sites

This is just pseudo code you will need to make it java urself

 

recipes = Furnaceripes.instance.getList

foreach(recipe in recipes) {

   if(recipe.output == stone)

     remove recipe

}

 

remember that you cant remove stuff while iterating over it with foreach so you will need to use the iterator methods

 

Link to comment
Share on other sites

Thank youu

 

this is what I have so far :3

	public static void removeRecipes()
	{
		Iterator<IRecipe> furnace = FurnaceRecipes.instance().getSmeltingList().iterator();
		Iterator<IRecipe> iterator = CraftingManager.getInstance().getRecipeList().iterator();
		
		while (iterator.hasNext())
		{
		    IRecipe recipe = iterator.next();
			ItemStack stone = new ItemStack(Blocks.STONE, 1, 0);

		    if (recipe == null)
			    continue;
		    
		    ItemStack output = recipe.getRecipeOutput();
		    
		    if (output != null && output.equals(stone))
			    iterator.remove();
		}
	}

 

Edited by minecraftbigfoot
Link to comment
Share on other sites

Iterating over it isn't working well.. because theres not an Interface for smelting to get the current recipe of the interator.

56 minutes ago, Jay Avery said:

Furnace recipes are a map of input->output. The remove method removes an entry with the given key, that is, input. So if you want to remove the cobblestone->stone recipe, you need to call remove with cobblestone.

How would you go about calling this? I take it:

        FurnaceRecipes.instance().getSmeltingList().remove(stone)
wouldn't work.

 

Edited by minecraftbigfoot
Link to comment
Share on other sites

4 minutes ago, minecraftbigfoot said:

Iterating over it isn't working well.. because theres not an Interface for smelting to get the current recipe of the interator.

How would you go about calling this? I take it:

        FurnaceRecipes.instance().getSmeltingList().remove(stone)
wouldn't work.

 

I think all you should need to do is make a cobblestone ItemStack (instead of the stone stack you used in your initial code), and call remove using that. (I haven't specifically done this with furnace recipes, but from what I know about Maps I don't see a reason for it not to work!).

Link to comment
Share on other sites

8 minutes ago, Jay Avery said:

I think all you should need to do is make a cobblestone ItemStack (instead of the stone stack you used in your initial code), and call remove using that. (I haven't specifically done this with furnace recipes, but from what I know about Maps I don't see a reason for it not to work!).

		ItemStack cobble = new ItemStack(Blocks.COBBLESTONE);
		FurnaceRecipes.instance().getSmeltingList().remove(cobble);

Doesn't work, guess I will have to continue brainstorming. Thank you anyway Jay

Link to comment
Share on other sites

Calling Map#remove with a new ItemStack on a Map with ItemStack keys won't do anything. ItemStack doesn't override Object#equals or Object#hashCode, so two ItemStacks are only considered to be the same key if they're the same object.

 

Map#remove will only work here if you call it with an ItemStack object that's already a key in the Map.

Edited by Choonster
  • Like 1

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

Just now, Choonster said:

Calling Map#remove with a new ItemStack on a Map with ItemStack keys won't do anything. ItemStack doesn't override Object#equals or Object#hashCode, so two ItemStacks are only considered to be the same key if they're the same object.

Hence why I can't make it work this way. 

	public static void removeRecipes()
	{
		Iterator interator = FurnaceRecipes.instance().getSmeltingList().entrySet().iterator();
		
		while (interator.hasNext())
		{
			ItemStack cobble = new ItemStack(Blocks.COBBLESTONE);
		    
		    if (interator.next().equals(cobble))
		    	interator.remove();
		}
	}
	

Done this with normal stone and cobble as Jay suggested neither even changes a thing. Nothing is changed because it wants an object and I'm giving it an ItemStack.

Link to comment
Share on other sites

1 minute ago, minecraftbigfoot said:

Hence why I can't make it work this way. 


	public static void removeRecipes()
	{
		Iterator interator = FurnaceRecipes.instance().getSmeltingList().entrySet().iterator();
		
		while (interator.hasNext())
		{
			ItemStack cobble = new ItemStack(Blocks.COBBLESTONE);
		    
		    if (interator.next().equals(cobble))
		    	interator.remove();
		}
	}
	

Done this with normal stone and cobble as Jay suggested neither even changes a thing. Nothing is changed because it wants an object and I'm giving it an ItemStack.

 

You can't compare ItemStacks using Object#equals, you need to use one of the static equality methods in the ItemStack class.

 

You shouldn't be creating a new ItemStack at all, though. You need to get the ItemStack key from the Iterator and check its Item, metadata and NBT as appropriate to determine whether it should be removed.

 

Iterator<E> is a generic type, don't use it (or any other generic type) without specifying its type argument.

  • Like 1

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

  • Like 1

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Thanks for all the help guys!

 

Final method:

public static void removeRecipes()
	{
		ItemStack result = null;
		Map<ItemStack, ItemStack> recipes = FurnaceRecipes.instance().getSmeltingList();
		Iterator<ItemStack> interator = recipes.keySet().iterator();
		
		while (interator.hasNext())
		{
		    ItemStack recipe = interator.next();
		    result = recipes.get(recipe);
			ItemStack stone = new ItemStack(Blocks.STONE, 1, 0);
		    		    
		    if (ItemStack.areItemStacksEqual(stone, result))
		    {
		    	interator.remove();
		    }
		}
	}

 

 

Thanks all <3

Link to comment
Share on other sites

59 minutes ago, minecraftbigfoot said:

ItemStack stone = new ItemStack(Blocks.STONE, 1, 0);

Move this line outside the loop, otherwise you're creating new objects every time the loop iterates, leading to more garbage collection.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.