minecraftbigfoot Posted March 29, 2017 Posted March 29, 2017 (edited) 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 March 29, 2017 by minecraftbigfoot 1.10 Quote
Failender Posted March 29, 2017 Posted March 29, 2017 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 Quote
minecraftbigfoot Posted March 29, 2017 Author Posted March 29, 2017 The issue I seem to be having is: Iterator<IRecipe> furance = FurnaceRecipes.instance().getSmeltingList().iterator(); as there is no iterator for FurnaceRecipes, whereas normal crafting will return me one. Quote
Failender Posted March 29, 2017 Posted March 29, 2017 oh okay. i made that up out of my mind. give me a sec ill look into it Quote
minecraftbigfoot Posted March 29, 2017 Author Posted March 29, 2017 (edited) 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 March 29, 2017 by minecraftbigfoot Quote
Failender Posted March 29, 2017 Posted March 29, 2017 Aaaah I see. FurnaceRecipes is a map, I remembered it as a list. That means that you need use the getSmeltingList.entrySet.iterator. You can than use that iterator to remove every entrance where value == stone Quote
Jay Avery Posted March 29, 2017 Posted March 29, 2017 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. Quote
Failender Posted March 29, 2017 Posted March 29, 2017 If he is iterating over the entry set and checking if the VALUE is stone then he will remove all recipes that have stone as output that will also catch modded recipes if he is calling it AFTER modded recipes are added. Quote
minecraftbigfoot Posted March 29, 2017 Author Posted March 29, 2017 (edited) Iterating over it isn't working well.. because theres not an Interface for smelting to get the current recipe of the interator. On 3/29/2017 at 1:51 PM, 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. Expand How would you go about calling this? I take it: FurnaceRecipes.instance().getSmeltingList().remove(stone) wouldn't work. Edited March 29, 2017 by minecraftbigfoot Quote
Jay Avery Posted March 29, 2017 Posted March 29, 2017 On 3/29/2017 at 2:47 PM, 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. Expand 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!). Quote
minecraftbigfoot Posted March 29, 2017 Author Posted March 29, 2017 On 3/29/2017 at 2:53 PM, 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!). Expand 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 Quote
Failender Posted March 29, 2017 Posted March 29, 2017 get the EntrySet of the furnaceRecipes. get the iterator. while(iterator.hasNext) get the iterator item if item.value is stone iterator.remove easy. 1 Quote
Choonster Posted March 29, 2017 Posted March 29, 2017 (edited) 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 March 29, 2017 by Choonster 1 Quote 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.
minecraftbigfoot Posted March 29, 2017 Author Posted March 29, 2017 On 3/29/2017 at 3:18 PM, 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. Expand 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. Quote
Choonster Posted March 29, 2017 Posted March 29, 2017 On 3/29/2017 at 3:20 PM, 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. Expand 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. 1 Quote 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.
Failender Posted March 29, 2017 Posted March 29, 2017 you can easyly compare using stack.getItem == Stone Quote
Draco18s Posted March 29, 2017 Posted March 29, 2017 If you want, you can take a look at how I accomplished this. https://github.com/Draco18s/ReasonableRealism/blob/master/src/main/java/com/draco18s/hardlib/util/RecipesUtils.java#L85 1 Quote 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.
minecraftbigfoot Posted March 29, 2017 Author Posted March 29, 2017 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 Quote
Draco18s Posted March 29, 2017 Posted March 29, 2017 On 3/29/2017 at 4:49 PM, minecraftbigfoot said: ItemStack stone = new ItemStack(Blocks.STONE, 1, 0); Expand Move this line outside the loop, otherwise you're creating new objects every time the loop iterates, leading to more garbage collection. Quote 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.
Recommended Posts
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.