Jump to content

Recommended Posts

Posted

I made my own shield item and want it to replace the Vanilla one, so I'm just trying to at least remove the Vanilla recipe so the player can't get it.

 

I'm trying this at the end of my FMLInitializationEvent...

ForgeRegistry<IRecipe> recipeRegistry = (ForgeRegistry<IRecipe>) ForgeRegistries.RECIPES;
for (IRecipe r : recipeRegistry.getValuesCollection())
{
	Item item = r.getRecipeOutput().getItem();
	if (item == Items.SHIELD)
	{
		recipeRegistry.register(RecipeEdit.get(r));
	}
}

...but I'm getting this error that I've never experienced before:

Spoiler

Caused by: java.util.ConcurrentModificationException
	at com.google.common.collect.HashBiMap$Itr.hasNext(HashBiMap.java:401)
	at java.util.Collections$UnmodifiableCollection$1.hasNext(Unknown Source)
	at avrye.fcr.Main.overrideVanilla(Main.java:58)
	at avrye.fcr.Main.init(Main.java:52)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at net.minecraftforge.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:629)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at com.google.common.eventbus.Subscriber.invokeSubscriberMethod(Subscriber.java:91)
	at com.google.common.eventbus.Subscriber$SynchronizedSubscriber.invokeSubscriberMethod(Subscriber.java:150)
	at com.google.common.eventbus.Subscriber$1.run(Subscriber.java:76)
	at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:399)
	at com.google.common.eventbus.Subscriber.dispatchEvent(Subscriber.java:71)
	at com.google.common.eventbus.Dispatcher$PerThreadQueuedDispatcher.dispatch(Dispatcher.java:116)
	at com.google.common.eventbus.EventBus.post(EventBus.java:217)
	at net.minecraftforge.fml.common.LoadController.sendEventToModContainer(LoadController.java:218)
	at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:196)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at com.google.common.eventbus.Subscriber.invokeSubscriberMethod(Subscriber.java:91)
	at com.google.common.eventbus.Subscriber$SynchronizedSubscriber.invokeSubscriberMethod(Subscriber.java:150)
	at com.google.common.eventbus.Subscriber$1.run(Subscriber.java:76)
	at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:399)
	at com.google.common.eventbus.Subscriber.dispatchEvent(Subscriber.java:71)
	at com.google.common.eventbus.Dispatcher$PerThreadQueuedDispatcher.dispatch(Dispatcher.java:116)
	at com.google.common.eventbus.EventBus.post(EventBus.java:217)
	at net.minecraftforge.fml.common.LoadController.distributeStateMessage(LoadController.java:135)
	at net.minecraftforge.fml.common.Loader.initializeMods(Loader.java:744)
	at net.minecraftforge.fml.client.FMLClientHandler.finishMinecraftLoading(FMLClientHandler.java:329)
	at net.minecraft.client.Minecraft.init(Minecraft.java:581)
	at net.minecraft.client.Minecraft.run(Minecraft.java:421)
	at net.minecraft.client.main.Main.main(Main.java:118)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
	at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97)
	at GradleStart.main(GradleStart.java:25)

 

 

This is the RecipeEdit (fake recipe) class:

Spoiler

package avrye.fcr.util;

import avrye.fcr.Main;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import net.minecraftforge.registries.IForgeRegistryEntry;

public class RecipeEdit extends IForgeRegistryEntry.Impl<IRecipe> implements IRecipe
{
	private final ItemStack output;

	public RecipeEdit(ItemStack item)
	{
		this.output = item;
	}

	public static IRecipe get(IRecipe recipe)
	{
		return new RecipeEdit(recipe.getRecipeOutput())
				.setRegistryName(new ResourceLocation(Main.MODID, recipe.getRecipeOutput().getItem().getUnlocalizedName()));
	}

	@Override
	public boolean matches(InventoryCrafting inv, World worldIn)
	{
		return false;
	}

	@Override
	public ItemStack getCraftingResult(InventoryCrafting inv)
	{
		return ItemStack.EMPTY;
	}

	@Override
	public boolean canFit(int width, int height)
	{
		return false;
	}

	@Override
	public ItemStack getRecipeOutput()
	{
		return output;
	}

}

 

 

What am I doing wrong?

Posted (edited)
24 minutes ago, SapphireSky said:

I'm trying this at the end of my FMLInitializationEvent...

This is the wrong time to be removing recipes. You need to remove them at the appropriate registry event. Yes, recipes are a IForgeRegistryEntry.

Also don't do this

Item item = r.getRecipeOutput().getItem();
	if (item == Items.SHIELD)
	{
		recipeRegistry.register(RecipeEdit.get(r));
	}

check whether the recipe you need removed is the one by comparing it's registry name.

 

24 minutes ago, SapphireSky said:

This is the RecipeEdit (fake recipe) class:

Why does it even have the output itemstack if it outputs an empty stack when asked? And it doesn't even matter since it doesn't fit any crafting grid. Also it doesn't override the recipe you desire to override since it's registry name will never equal the recipe you are overriding.

Edited by V0idWa1k3r
Posted
2 hours ago, V0idWa1k3r said:

This is the wrong time to be removing recipes. You need to remove them at the appropriate registry event. Yes, recipes are a IForgeRegistryEntry.

This is arguable, since the Recipes registry is modifiable(at least the last time I checked).

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted
5 minutes ago, Animefan8888 said:

This is arguable, since the Recipes registry is modifiable(at least the last time I checked).

Well, yes, but it doesn't really make sense to modify the registry before any recipe has been loaded. And yes, vanilla recipes also get loaded basically at that event(it loads vanilla recipes first, then fires the event). And yes, the recipe registry happens after pre-init but before init, just as any other registry. See Loader#initializeMods. And while you could in theory modify the registry in the init or post-init after it has been initialized it won't work with any mod that grabs a reference for recipes, like JEI for example. It won't even work with the recipe book actually since it builds the recipe table after the registry event but before the init. So the registry being modifiable doesn't really mean you can do whatever you want with it whenever you want without consequences or incompatibilities. 

Besides the registry event just seems like the most logical place to modify the registry.

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.