kirinnee97 Posted July 4, 2017 Posted July 4, 2017 Cannot iterate registry IRecipe list and remove, how would i go about to remove a vanilla recipe in 1.12? Thank you in advance! Quote
Choonster Posted July 4, 2017 Posted July 4, 2017 The recipe registry (unlike other registries) is modifiable, so you can actually remove a recipe using IForgeRegistryModifiable#remove. Any advancement that rewards the recipe will throw a syntax exception (spamming the log) if you do this, though. 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.
kirinnee97 Posted July 4, 2017 Author Posted July 4, 2017 15 minutes ago, Choonster said: The recipe registry (unlike other registries) is modifiable, so you can actually remove a recipe using IForgeRegistryModifiable#remove. Any advancement that rewards the recipe will throw a syntax exception (spamming the log) if you do this, though. I accessed the registries both using the RegistryEvent and ForgeRegistries and access the recipe registry (ForgeRegistries.RECIPES) and tried removing, but it throws a java.lang.UnsupportedOperationException: remove Quote
Choonster Posted July 4, 2017 Posted July 4, 2017 9 minutes ago, kirinnee97 said: I accessed the registries both using the RegistryEvent and ForgeRegistries and access the recipe registry (ForgeRegistries.RECIPES) and tried removing, but it throws a java.lang.UnsupportedOperationException: remove Which version of Forge are you using? Post your code and the full stacktrace of the exception. 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.
kirinnee97 Posted July 4, 2017 Author Posted July 4, 2017 7 minutes ago, Choonster said: Which version of Forge are you using? Post your code and the full stacktrace of the exception. Hi, I'm sorry for the confusion, it seems I did not cast to IForgeRegistryModifiable. As you said, it works but throws exceptions, but replacing with no-op implementation doesn't, so i think i will go with diesieben's method! Thank you very much with your help this time again! Quote
kirinnee97 Posted July 9, 2017 Author Posted July 9, 2017 On 7/5/2017 at 2:29 AM, Tiesto97 said: Hello kririnee. I'm fairly new to java programing and even newer if we speak about mod writing. Would you mind uploading your code?(where u use the no-op implementation) Because I need it and I have literally no clue how to do it, and not found a single word about it on google... Thanks! Hi sorry for the late reply, and no-op implementation in Java essentially means a "dummy", or fake object. Its a dummy that implements an interface. Simply put, all you have to do is create a class that implements IRecipe, override its method properly, and create and object of that class. You then register that object with the minecraft vanilla object's registry name. Hope it helps. Quote
Arimil Posted July 14, 2017 Posted July 14, 2017 I was trying to use this to remove a recipe (not a vanilla recipe) however this doesn't seem to be allowed. if (ForgeRegistries.RECIPES.containsValue(recipe)) { ForgeRegistries.RECIPES.getEntries().remove(recipe); } I'll try replacing it instead. Quote
Choonster Posted July 14, 2017 Posted July 14, 2017 (edited) 4 hours ago, Arimil said: I was trying to use this to remove a recipe (not a vanilla recipe) however this doesn't seem to be allowed. if (ForgeRegistries.RECIPES.containsValue(recipe)) { ForgeRegistries.RECIPES.getEntries().remove(recipe); } I'll try replacing it instead. ForgeRegistry#getEntries returns an immutable copy of the registry's entries, so you can't use it to modify the registry. As I said earlier in the thread, use IForgeRegistryModifiable#remove. Edited July 14, 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.
Zamion101 Posted July 15, 2017 Posted July 15, 2017 I have a 2-3 years of Java knowledge and have 1.5 years of Spigot / Bukkit. But i want to learn Forge so i decided to create a mod. And i want remove some vanilla recipes but i don't understand what i need do can anybody help me ? Quote Developing Kodev Minecraft Hardcore Mod! If You're Wondering, My Mod Page. http://minecraft.curseforge.com/projects/minecraft-hardcore-mod
Zamion101 Posted July 15, 2017 Posted July 15, 2017 I know what he said but i can't understand this message i need Extends? or anything? I write this lines of code: Iterator<IRecipe> rec = ForgeRegistries.RECIPES.iterator(); IForgeRegistryModifiable<IRecipe> r = (IForgeRegistryModifiable<IRecipe>) rec.next(); r.remove(Items.STICK.getRegistryName()); I think i do error because not crashing game but not removing too. Quote Developing Kodev Minecraft Hardcore Mod! If You're Wondering, My Mod Page. http://minecraft.curseforge.com/projects/minecraft-hardcore-mod
Zamion101 Posted July 15, 2017 Posted July 15, 2017 When i call Iterator<Recipe> recipe = ForgeRegisteries.RECIPES.iterator(); recipe.remove(); Throws java.lang.UnsupportedOperationException: remove Quote Developing Kodev Minecraft Hardcore Mod! If You're Wondering, My Mod Page. http://minecraft.curseforge.com/projects/minecraft-hardcore-mod
Zamion101 Posted July 15, 2017 Posted July 15, 2017 Okey ı understand now and i fixed my error thank you so much and i give here the my code for everyone.@diesieben07 Thank you... /*POST-INIT*/ new RecipeManager(Items.STICK); or new RecipeManager(Blocks.GOLD_BLOCK); /*RECIPE MANAGER*/ public class RecipeManager extends ForgeRegistries{ public RecipeManager(Item item){ ForgeRegistry<IRecipe> r = (ForgeRegistry<IRecipe>) RECIPES; r.remove(item.getRegistryName()); CraftingHelper.loadRecipes(false); CraftingManager.init(); } public RecipeManager(ItemStack itemStack){ ForgeRegistry<IRecipe> r = (ForgeRegistry<IRecipe>) RECIPES; r.remove(itemStack.getItem().getRegistryName()); CraftingHelper.loadRecipes(false); CraftingManager.init(); } public RecipeManager(Block block){ ForgeRegistry<IRecipe> r = (ForgeRegistry<IRecipe>) RECIPES; r.remove(Item.getItemFromBlock(block).getRegistryName()); CraftingHelper.loadRecipes(false); CraftingManager.init(); } } Quote Developing Kodev Minecraft Hardcore Mod! If You're Wondering, My Mod Page. http://minecraft.curseforge.com/projects/minecraft-hardcore-mod
Zamion101 Posted July 15, 2017 Posted July 15, 2017 20 minutes ago, diesieben07 said: Why on earth are you doing this in constructors? Why do you extend ForgeRegistries? Why are you calling CraftingHelper.loadRecipes and CraftingManager.init? You should not be calling either, ever. Do not use the ForgeRegistry class, use the interfaces IForgeRegistry resp. IForgeRegistryModifiable. Because i want. Because IDK Because if you don't call CraftingHelper.loadRecipes crashing game when open crafting table or player inventory. Next time. Now don't have a any error. Quote Developing Kodev Minecraft Hardcore Mod! If You're Wondering, My Mod Page. http://minecraft.curseforge.com/projects/minecraft-hardcore-mod
Zamion101 Posted July 15, 2017 Posted July 15, 2017 2 minutes ago, diesieben07 said: Show that crash. When exactly (i.e. which loading phase / event) are you removing these recipes? https://pastebin.com/bqGt0MQH Quote Developing Kodev Minecraft Hardcore Mod! If You're Wondering, My Mod Page. http://minecraft.curseforge.com/projects/minecraft-hardcore-mod
Zamion101 Posted July 15, 2017 Posted July 15, 2017 FMLPostInitializationEvent / RecipeManager class. CraftingHelper can't find minecraft:stick recipe because we're removing... So when you reloadRecipes don't give crash. Quote Developing Kodev Minecraft Hardcore Mod! If You're Wondering, My Mod Page. http://minecraft.curseforge.com/projects/minecraft-hardcore-mod
kreezxil Posted July 25, 2017 Posted July 25, 2017 This thread is very helpful as long as you read the opening post and then only the replies from diesieben07. However, because the majority of us are absolute java newbs, it's the truth, the advice given is lost on us. With some help from TheDragon team and MMD team on Discord I was able to finally understand what had to be done and where it had to be done. To remove a wooden button, which was my goal for my mod More Beautiful Buttons (1.12), I used [https://github.com/kreezxil/More-Beautiful-Buttons/blob/master/src/main/java/com/kreezcraft/morebeautifulbuttons/init/Registrar.java#L43-L49]: @SubscribeEvent public static void registerRecipes(RegistryEvent.Register<IRecipe> event) { ResourceLocation theButton = new ResourceLocation("minecraft:wooden_button"); IForgeRegistryModifiable modRegistry = (IForgeRegistryModifiable) event.getRegistry(); modRegistry.remove(theButton); } This segment of code goes in your EventBus handler. You tell Forge which class is this type of handler with @EventBusSubscriber being placed above the class name. @EventBusSubscriber public class Registrar { You can use this to remove any recipe from any place vanilla or other mods. Quote https://www.akliz.net/manage/aff.php?aff=179 coupon: kreezxil KreezCraft.com - Twitch.TV/Kreezxil - YouTube.com/Kreezxil
kreezxil Posted August 7, 2017 Posted August 7, 2017 Being the newb that I am; while I do understand how to remove recipes now as evidenced by the code snippet. What I don't understand is how to no-op the wooden and stone button advancements. I see the words and stuff. but what I really need is a function fragment with the code in it. Quote https://www.akliz.net/manage/aff.php?aff=179 coupon: kreezxil KreezCraft.com - Twitch.TV/Kreezxil - YouTube.com/Kreezxil
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.