Posted February 27, 20178 yr Just as the title says, I'm looking for a way to remove vanila items from creative tabs and also to remove their recipes. Back in 1.7.10 I had at least the recipe part working but when I updated it to 1.11.2 it stopped working entirely. I can't really see the issue as to why it shouldn't work as it was a very minor adjustment code wise. 1.7.10 class: public class RecipeHandler { public static void removeRecipes(ItemStack stack) { ItemStack resultItem = stack; resultItem.stackSize = 1; List<IRecipe> recipes = CraftingManager.getInstance().getRecipeList(); for (int i = 0; i < recipes.size(); i++) { IRecipe tmpRecipe = recipes.get(i); ItemStack recipeResult = tmpRecipe.getRecipeOutput(); if(recipeResult != null) { recipeResult.stackSize = 1; } if (ItemStack.areItemStacksEqual(resultItem, recipeResult)) { System.out.println(Reference.MOD_NAME + " || Removed Recipe: " +recipes.get(i)+ " <--> " +recipeResult); recipes.remove(i--); } } } } Edited February 27, 20178 yr by nexusrightsi
February 27, 20178 yr Author All that had do be done was change both resultItem.stackSize = 1; and recipeResult.stackSize = 1; to this: .setCount(1); Before anyone asks, yes I am most certainly calling the method that removes the recipes from my post init. I posted this in a new reply since it wouldn't allowe me to post this in the original post... Edited February 27, 20178 yr by nexusrightsi
February 27, 20178 yr Here is my code using an Iterator private void removeCraftRecipe(ItemStack stack) { Iterator recipes = CraftingManager.getInstance().getRecipeList().iterator(); while (recipes.hasNext()) { ItemStack output = ((IRecipe) recipes.next()).getRecipeOutput(); if(output != null && output.getItem() != null) { if(output.isItemEqual(stack)) { recipes.remove(); } } } } Classes: 94 Lines of code: 12173 Other files: 206 Github repo: https://github.com/KokkieBeer/DeGeweldigeMod
February 27, 20178 yr private void removeCraftRecipe(ItemStack stack) { Iterator<IRecipe> recipes = CraftingManager.getInstance().getRecipeList().iterator(); while (recipes.hasNext()) { ItemStack output = ((IRecipe) recipes.next()).getRecipeOutput(); if(output != null && output.getItem() != null) { if(output.isItemEqual(stack)) { recipes.remove(); } } } } 1 minute ago, diesieben07 said: Ewww, raw types... Here you go... Classes: 94 Lines of code: 12173 Other files: 206 Github repo: https://github.com/KokkieBeer/DeGeweldigeMod
February 27, 20178 yr OK SENSEI private void removeCraftRecipe(ItemStack stack) { Iterator<IRecipe> recipes = CraftingManager.getInstance().getRecipeList().iterator(); while (recipes.hasNext()) { ItemStack output = recipes.next().getRecipeOutput(); if(output != null && output.getItem() != null) { if(output.isItemEqual(stack)) { recipes.remove(); } } } } Classes: 94 Lines of code: 12173 Other files: 206 Github repo: https://github.com/KokkieBeer/DeGeweldigeMod
February 27, 20178 yr So basically fuck all the code that I've got already and just do that instead of what I've got... No thanks... Classes: 94 Lines of code: 12173 Other files: 206 Github repo: https://github.com/KokkieBeer/DeGeweldigeMod
February 27, 20178 yr This is the furthest I'll go private void removeCraftRecipe(ItemStack stack) { Iterator<IRecipe> recipes = CraftingManager.getInstance().getRecipeList().iterator(); while (recipes.hasNext()) { ItemStack output = recipes.next().getRecipeOutput(); if (output.isItemEqual(stack)) { recipes.remove(); } } } Classes: 94 Lines of code: 12173 Other files: 206 Github repo: https://github.com/KokkieBeer/DeGeweldigeMod
February 27, 20178 yr Author Diesieben please, your last comment made me facepalm so hard Why the frig did I want this code... when its just as easy as CraftingManager.getInstance().getRecipeList().removeIf(stack -> stack.getItem() == Items.STICK); You sir, ruined my day! nah just kidding. Thank you for the easy solution though, less code is always better and if I can slim it down to a mere line who am I to moan!
February 27, 20178 yr Author 8 minutes ago, diesieben07 said: Well, removeIf (and lambdas) are a pretty new feature, available since Java 8. So nothing wrong with not knowing about them yet. Quite unfortunate that neither solutions work though, the recipe is still there for some reason...
February 27, 20178 yr Author 8 minutes ago, diesieben07 said: Post updated code. Its pretty much the solution koekkie came up, scratch that. Its just a copy and paste. public class RecipeHandler { public static void removeRecipes() { /* * Items */ removeRecipes(new ItemStack(Items.DIAMOND_HOE)); removeRecipes(new ItemStack(Items.IRON_HOE)); removeRecipes(new ItemStack(Items.GOLDEN_HOE)); removeRecipes(new ItemStack(Items.STONE_HOE)); //recipe.removeRecipes(new ItemStack(Items.DYE, 0, 15)); /* * Blocks */ //recipe.RemoveRecipe(new ItemStack(Block.workbench)); } private static void removeRecipes(ItemStack stack) { Iterator<IRecipe> recipes = CraftingManager.getInstance().getRecipeList().iterator(); while (recipes.hasNext()) { ItemStack output = recipes.next().getRecipeOutput(); if (output.isItemEqual(stack)) { recipes.remove(); } } }
February 27, 20178 yr Author In my proxy.PostInit() which is being called in the post init of the main class.
February 27, 20178 yr Author 4 minutes ago, diesieben07 said: That should work, although I am not sure why you would do this in your proxy. Is the code getting called? Does it get to the part where recipes are removed? I have no clue what is going on right now... I switched the call of removeRecipes() from the proxy post init to the main class post init not that that should matter in the slightest... However the method isn't even being called...
February 27, 20178 yr Author @Mod(modid = Reference.MOD_ID, version = Reference.VERSION) public class NagaCore { @Instance(Reference.MOD_ID) public static NagaCore instance; /* * Sets the proxies up for usage. */ @SidedProxy( clientSide = Reference.CLIENT_PROXY_LOCATION, serverSide = Reference.COMMON_PROXY_LOCATION) public static CommonProxy proxy; public static CreativeTabs tabBlocks = new CreativeTabNFOBlocks("nfo_blocks"); public static CreativeTabs tabItems = new CreativeTabNFOItems("nfo_items"); /* * This loads in all the given methods upon the start of the game, commonly used for important systems such as packets, handlers and other * important stuff. * take note of the hierarchy in which order everything is getting loaded into the game. */ @EventHandler public void preInit(FMLPreInitializationEvent event) { proxy.preInit(); BlockHandler.BlockInit(); ItemHandler.ItemInit(); ItemHandler.registerRecipes(); ItemHandler.registerOreItems(); } /* * This loads in all the given methods upon the start of the game, commonly used for blocks, items and varius other things. * take note of the hierarchy in which order everything is getting loaded into the game. */ @EventHandler public void init(FMLInitializationEvent event) { proxy.init(); } /* * This loads in all the given methods upon the start of the game, commonly used for Gui's and stuff that are allowed to be initialized * at the very end of the minecraft boot up. * take note of the hierarchy in which order everything is getting loaded into the game. */ @EventHandler public void postInit(FMLPostInitializationEvent event) { proxy.postInit(); RecipeHandler.removeRecipes(); } } I try to keep this as clean as possible that is why I try to move everything into the proxy but sadly i can't do that for the items and blocks. They will crash the game when I do that
February 27, 20178 yr Author Okay... that was random, without me changing absolutely anything it decided to work... my code is being haunted, I need an exorcist to cleanse my project please!
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.