Jump to content

[1.12] Override vanilla recipe


DragonFerocity

Recommended Posts

Hey guys,

 

So how do I override a vanilla recipe in 1.12? I tried overriding the recipe json file in a resource pack but it didn't work. Sorry if this is a basic question, but there doesn't seem to be anything out there for 1.12 yet that I can find.

Edited by DragonFerocity
Link to comment
Share on other sites

Now that IRecipes are in a Forge registry, you can override an existing IRecipe simply by registering a new one with the same registry name.

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

9 hours ago, Choonster said:

Now that IRecipes are in a Forge registry, you can override an existing IRecipe simply by registering a new one with the same registry name.

This didn't work for me until I removed the recipe first. Unless by registering  you mean in code and not via JSON.

 

My solution:

    @SubscribeEvent
    public static void registerRecipes(RegistryEvent.Register<IRecipe> event)
    {
    	ResourceLocation theButton = new ResourceLocation("minecraft:wooden_button");
        IForgeRegistryModifiable modRegistry = (IForgeRegistryModifiable) event.getRegistry();
        modRegistry.remove(theButton);
    }

from https://github.com/kreezxil/More-Beautiful-Buttons/blob/master/src/main/java/com/kreezcraft/morebeautifulbuttons/init/Registrar.java#L43-L49

Link to comment
Share on other sites

Just now, kreezxil said:

This didn't work for me until I removed the recipe first. Unless by registering  you mean in code and not via JSON.

 

JSON recipes always have your mod ID as the domain of their registry name, so they can't directly override a vanilla recipe.

 

Removing a vanilla recipe and then loading your own to replace is it possible, as you discovered.

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

6 minutes ago, Choonster said:

 

JSON recipes always have your mod ID as the domain of their registry name, so they can't directly override a vanilla recipe.

 

Removing a vanilla recipe and then loading your own to replace is it possible, as you discovered.

Is there an easier way to do what I did?

Link to comment
Share on other sites

Just now, kreezxil said:

Is there an easier way to do what I did?

 

Not really, the recipe removal needs to be done in code and the replacement should generally be added via JSON; so replacing recipes via the registry override system (registering a new value with the same name) usually isn't practical.

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

5 hours ago, kreezxil said:

This didn't work for me until I removed the recipe first. Unless by registering  you mean in code and not via JSON.

 

My solution:


    @SubscribeEvent
    public static void registerRecipes(RegistryEvent.Register<IRecipe> event)
    {
    	ResourceLocation theButton = new ResourceLocation("minecraft:wooden_button");
        IForgeRegistryModifiable modRegistry = (IForgeRegistryModifiable) event.getRegistry();
        modRegistry.remove(theButton);
    }

from https://github.com/kreezxil/More-Beautiful-Buttons/blob/master/src/main/java/com/kreezcraft/morebeautifulbuttons/init/Registrar.java#L43-L49

Where exactly did you put that snippet of code? Preinit or init or elsewhere?

Link to comment
Share on other sites

Look at my github link that I provided. Note that above the class for the file containing this snipped it says @EventBusSubscriber. That's what tells Forge to come to the file and load up the subscriber events, ie these routines don't go in the init, preinit, or postinit. So feel free to copy my registrar.java and use it as you please. You'll probably end up with a class that looks like:

package com.mod.awesomeyour;

import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.event.ModelRegistryEvent;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.event.RegistryEvent.Register;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.registries.IForgeRegistryModifiable;

@EventBusSubscriber
public class Registrar {

    @SubscribeEvent
    public static void registerRecipes(RegistryEvent.Register<IRecipe> event)
    {
    	ResourceLocation theButton = new ResourceLocation("minecraft:wooden_button");
        IForgeRegistryModifiable modRegistry = (IForgeRegistryModifiable) event.getRegistry();
        modRegistry.remove(theButton);
    }
}

that's all you need to remove the wooden button, extrapolate as necessary.

Link to comment
Share on other sites

  • 1 month later...

This doesn't work for me on Forge 2462, the event never fires.

Nevermind, I was using a non-static event handler and copied in a static method.

Edited by Draco18s

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.

Announcements



×
×
  • Create New...

Important Information

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