Jump to content

[1.12] Getting a fluid from another mod


Tomson124

Recommended Posts

I am currently updating my mod to 1.12 and am still pretty new to the new Registry system.

In my mod I use a bucket with ThermalFoundation's Destabilized Redstone for crafting.

For getting this bucket as an item I am using

Fluid redstone = FluidRegistry.getFluid("redstone");
bucketRedstone = FluidUtil.getFilledBucket(new FluidStack(redstone, 1000));

This is called while preInit (before the Registry<IRecipe> event). But I always get the error:

Spoiler

Caused by: java.lang.NullPointerException
	at net.minecraftforge.fluids.FluidUtil.getFilledBucket(FluidUtil.java:698)
	at tonius.simplyjetpacks.integration.TEItems.init(TEItems.java:73)
	at tonius.simplyjetpacks.setup.ModItems.preInit(ModItems.java:111)
	at tonius.simplyjetpacks.SimplyJetpacks.preInit(SimplyJetpacks.java:44)

 

I already checked the fluid and the FluidStack for being null, but both are not, as the Fluid is initialized in the preInit, too. And ThermalFoundation is loaded before my mod.

 

Now I found a way arround it by gathering the fluid in init phase and registering the 2 recipes which need the bucket also in init phase.

But it doesn't seem right that it doesn't work the original way. What am I missing?

Link to comment
Share on other sites

The ForgeModContainer#universalBucket field was null when you called FluidUtil.getFilledBucket, this is because it's not populated until RegistryEvent.Register<Item> (which is fired between preInit and init).

 

You should create the bucket ItemStack during RegistryEvent.Register<IRecipe>, or ideally use a JSON recipe instead. I have an IIngredientFactory implementation that produces a filled universal bucket here; I use it in this constant, which I use in this recipe.

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 am not that much of a fan of the new JSON recipe system, so that will probably be not my solution.

 

I tried creating the bucket during that event but it tells me that a recipe is invalid shaped, as the bucket is null.

Spoiler

net.minecraftforge.fml.common.LoaderExceptionModCrash: Caught exception from Simply Jetpacks 2 (simplyjetpacks)
Caused by: java.lang.RuntimeException: Invalid shaped ore recipe: ICI, PDP, IRI, I, ingotElectrum, P, blockGlassHardened, C, 1xitem.thermalfoundation.material@513, D, 1xtile.cofh.thermalexpansion.dynamo@1, R, null,
    at net.minecraftforge.common.crafting.CraftingHelper.parseShaped(CraftingHelper.java:344)
    at tonius.simplyjetpacks.util.crafting.RecipeHelper.addOldShaped(RecipeHelper.java:51)
    at tonius.simplyjetpacks.util.crafting.RecipeHandler.addShapedRecipe(RecipeHandler.java:30)
    at tonius.simplyjetpacks.util.crafting.RecipeHandler.addOreDictRecipe(RecipeHandler.java:18)
    at tonius.simplyjetpacks.setup.ModItems.registerRecipes(ModItems.java:318)
    at tonius.simplyjetpacks.setup.ModItems.preInit(ModItems.java:122)
    at tonius.simplyjetpacks.SimplyJetpacks.preInit(SimplyJetpacks.java:51)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at net.minecraftforge.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:611)
    at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.google.common.eventbus.Subscriber.invokeSubscriberMethod(Subscriber.java:91)

I did it this way:

@SubscribeEvent
	public void onRegisterRecipes(RegistryEvent.Register<IRecipe> event) {
		if (ModItems.integrateTE) {
			TEItems.initFluids();
		}

		for(IRecipe recipe : RECIPES_TO_REGISTER) {
			event.getRegistry().register(recipe);
		}
		RECIPES_TO_REGISTER.clear();
	}

Where initFluids() looks as follows:

public static void initFluids() {
	Fluid redstone = FluidRegistry.getFluid("redstone");
	bucketRedstone = FluidUtil.getFilledBucket(new FluidStack(redstone, Fluid.BUCKET_VOLUME));
}

 

Link to comment
Share on other sites

It looks like you create your recipes before you create and store the filled bucket ItemStack, so the field hasn't yet been populated when they reference it.

 

Where and when do you create your recipes? It should be done in RegistryEvent.Register<IRecipe>.

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

2 minutes ago, Choonster said:

Where and when do you create your recipes? It should be done in RegistryEvent.Register<IRecipe>.

I am doing it in the onRegisterRecipes() method (see post above).

The RegistryHandler is registered during preInit see following:

Spoiler

@EventHandler
	public static void preInit(FMLPreInitializationEvent evt) {
		logger.info("Starting Simply Jetpacks 2");

		MinecraftForge.EVENT_BUS.register(new RegistryHandler());

		Config.preInit(evt);
		ModItems.preInit();
		//Log.info("ListRecipes: " + RECIPES_TO_REGISTER);
	}

 

 

 

Link to comment
Share on other sites

Just now, Tomson124 said:

I am doing it in the onRegisterRecipes() method (see post above).

 

In the code you posted you register the recipes in that method, but they're created (instantiated) somewhere else.

  • 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

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.