Jump to content

Recommended Posts

Posted

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.

Posted
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

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

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

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

Posted

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.

Posted (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 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.

Posted

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

Posted

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

Posted
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

  • 2 weeks later...
Posted

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.

  • 2 weeks later...

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.