Jump to content

[1.12] Removing vanilla Recipes


kirinnee97

Recommended Posts

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.

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

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

Link to comment
Share on other sites

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.

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

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 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

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 ?

 

Developing Kodev Minecraft Hardcore Mod!

If You're Wondering, My Mod Page. http://minecraft.curseforge.com/projects/minecraft-hardcore-mod

Link to comment
Share on other sites

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.

Developing Kodev Minecraft Hardcore Mod!

If You're Wondering, My Mod Page. http://minecraft.curseforge.com/projects/minecraft-hardcore-mod

Link to comment
Share on other sites

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();
	}

}

 

Developing Kodev Minecraft Hardcore Mod!

If You're Wondering, My Mod Page. http://minecraft.curseforge.com/projects/minecraft-hardcore-mod

Link to comment
Share on other sites

20 minutes ago, diesieben07 said:
  • Why on earth are you doing this in constructors? O.o
  • Why do you extend ForgeRegistriesO.o
  • 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 :D
  • 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.

Developing Kodev Minecraft Hardcore Mod!

If You're Wondering, My Mod Page. http://minecraft.curseforge.com/projects/minecraft-hardcore-mod

Link to comment
Share on other sites

  • 2 weeks later...

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.

Link to comment
Share on other sites

  • 2 weeks later...

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. 

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.

Announcements



×
×
  • Create New...

Important Information

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