Jump to content

[Solved][1.7.2] Fluid NullPointerException and Brewing Stand Question


Pandassaurus

Recommended Posts

Hi guys,

First, i have a new liquid i want to make, and i was following a tutorial, but it was 1.6.4.

It seems as though it should work, but i keep getting this exception:

 

 

Caused by: java.lang.NullPointerException
at net.minecraftforge.fluids.FluidRegistry.getFluidID(FluidRegistry.java:119)
at net.minecraftforge.fluids.Fluid.getID(Fluid.java:177)
at net.minecraftforge.fluids.FluidStack.<init>(FluidStack.java:27)
at net.minecraftforge.fluids.BlockFluidClassic.<init>(BlockFluidClassic.java:28)
at com.pandassaurus.breakingbad.block.HydrofluoricAcid.<init>(HydrofluoricAcid.java:14)
at com.pandassaurus.breakingbad.BreakingBad.<clinit>(BreakingBad.java:62)
... 35 more

 

 

This is my main class:

 

 

package com.pandassaurus.breakingbad;

/* imports */

@Mod(modid = "breakingbad", version = "1.0 Alpha", name = "Breaking Bad Mod")

public class BreakingBad {

    //proxies 
    @SidedProxy(clientSide = "com.pandassaurus.breakingbad.ClientProxy", serverSide = "com.pandassaurus.breakingbad.CommonProxy")
    public static CommonProxy proxy;

    /*other */

    //fluids

    public static Fluid FluidHydrofluoricAcid_ = new Fluid("Hydrofluoric Acid");
    public static Material MaterialHydrofluoricAcid_ = new MaterialLiquid(MapColor.clothColor);
    public static Block HydrofluoricAcid_ = new HydrofluoricAcid(FluidHydrofluoricAcid_, MaterialHydrofluoricAcid_);

    /*item/block creations  */


    public BreakingBad() {

        //Registrations 

        FluidRegistry.registerFluid(FluidHydrofluoricAcid_);
        GameRegistry.registerBlock(HydrofluoricAcid_, HydrofluoricAcid_.getUnlocalizedName());

       /* Other Registrations */


   /* Recipes  */
    }


}

 

 

 

And this is my HydrofluoricAcid class:

 

 

package com.pandassaurus.breakingbad.block;

/*imports*/

/**
* User: Pandassaurus
* Date: 3/9/14
*/
public class HydrofluoricAcid extends BlockFluidClassic {
    public HydrofluoricAcid(Fluid fluid, Material material) {
        super(fluid, material);
        this.setCreativeTab(BreakingBad.BreakingBadTab_);
        this.setBlockName("Hydrofluoric Acid");
        this.setBlockTextureName("breakingbad:HydrofluoricAcid");
    }
}

 

 

 

 

Also, is there a way to make custom brewing stand combos so that, for example, i can use gold to make a rotten flesh in the brewing stand or something?

 

 

 

 

Thanks a lot, and any help is appreciated,

-Pandassaurus

Link to comment
Share on other sites

Hi

 

It looks to me like FluidRegistry hasn't initialised yet.

 

Perhaps try moving the static initialisation of  these

 

    public static Fluid FluidHydrofluoricAcid_ = new Fluid("Hydrofluoric Acid");
    public static Material MaterialHydrofluoricAcid_ = new MaterialLiquid(MapColor.clothColor);
    public static Block HydrofluoricAcid_ = new HydrofluoricAcid(FluidHydrofluoricAcid_, MaterialHydrofluoricAcid_);

to your preInit method, eg

public static Fluid fluidHydrofluoricAcid;

PreInit method:
fluidHydrofluoricAcid = new Fluid("Hydrofluoric Acid");
// etc ...

 

 

I didn't really understand your question about the brewing stand.

 

-TGG

 

 

Link to comment
Share on other sites

Thanks for the reply,

 

I dont have a preint method, all i have is shown there. I've heard about it but have never used one, and for the most part, things worked. If i need one, can you tell me how to do it?

 

 

as for the brewing stand question:

 

the brewing stand can hold water bottles in the bottom slots and an ingredient at the top. So, i'm asking if there's a way to personalize the inputs and outputs so, for example, i can put a gold ingot in the top slot with water bottles at the bottom, and receive something like rotten flesh when the brewing is complete?

 

thanks for the feedback,

-Pandassaurus

Link to comment
Share on other sites

Hi

 

This link gives a bit of background information about preInit and all the rest.

 

http://greyminecraftcoder.blogspot.com.au/2013/11/how-forge-starts-up-your-code.html

 

It's a little bit outdated now but the concepts are the same.

The reason to use preInit and the others is to make sure that your objects are created at the correct time.  I suspect this might be the problem in your case.

 

Re the brewing stand: the answer is almost certainly yes, but I haven't done anything with Brewing Stands myself so I'm not sure.

 

PotionBrewedEvent might be a good place to start;

http://www.minecraftforum.net/topic/1419836-forge-4x-events-howto/

 

-TGG

Link to comment
Share on other sites

No, i don't think that was it. The error, though, points me to the super of the block class:

 

super(fluid, material)

 

and to the creation of the block:

public static Block HydrofluoricAcid_ = new HydrofluoricAcid(FluidHydrofluoricAcid_, MaterialHydrofluoricAcid_);

 

I don't know why this is happening, but thanks for the help.

-Pandassaurus

 

Link to comment
Share on other sites

Hi

 

Yeah the problem is occurring here:

 

at net.minecraftforge.fluids.FluidRegistry.getFluidID(FluidRegistry.java:119)

    public static int getFluidID(String fluidName)
    {
        return fluidIDs.get(fluidName);      // here
    }

    static BiMap<String, Integer> fluidIDs = HashBiMap.create();

 

The only way that this can give NPE is if fluidIDs is null (because it hasn't been initialised yet), or (as I just realised) because the fluid hasn't been registered yet.

 

So I suggest:

(1) Create your fluid in the preInit method, not static initialiser

(2) register your fluid

(3) create your block in the preInit method, not static initialiser

(4) register your block

 

-TGG

 

 

 

 

 

Link to comment
Share on other sites

Yes that finally worked thank you!!

 

For anyone who wants to know how to do it:

 

 

package com.pandassaurus.breakingbad;

   /*imports*/

@Mod(modid = "breakingbad", version = "1.0 Alpha", name = "Breaking Bad Mod")

public class BreakingBad {

    /*proxies*/

//fluids
    public static Fluid FluidHydrofluoricAcid_;
    public static Block HydrofluoricAcid_;
    public static Material MaterialHydrofluoricAcid_ = new MaterialLiquid(MapColor.clothColor);

    public static Fluid FluidMethylamine_;
    public static Block Methylamine_;
    public static Material MaterialMethylamine_ = new MaterialLiquid(MapColor.airColor);

//preInit
    @Mod.EventHandler
    public void preInit(FMLPreInitializationEvent event) {
        FluidHydrofluoricAcid_ = new Fluid("Hydrofluoric Acid");
        FluidRegistry.registerFluid(FluidHydrofluoricAcid_);
        HydrofluoricAcid_ = new HydrofluoricAcid(FluidHydrofluoricAcid_, MaterialHydrofluoricAcid_);
        GameRegistry.registerBlock(HydrofluoricAcid_, HydrofluoricAcid_.getUnlocalizedName());

        FluidMethylamine_ = new Fluid("Methylamine");
        FluidRegistry.registerFluid(FluidMethylamine_);
        Methylamine_ = new Methylamine(FluidMethylamine_, MaterialMethylamine_);
        GameRegistry.registerBlock(Methylamine_, Methylamine_.getUnlocalizedName());
    }

    /*other code*/

    public BreakingBad() {

/*Registrations and recipies*/ 
    
    }


}

 

 

 

and my block class:

 

 

package com.pandassaurus.breakingbad.block;

/*imports*/

/**
* User: Pandassaurus
* Date: 3/9/14
*/
public class HydrofluoricAcid extends BlockFluidClassic {
    public HydrofluoricAcid(Fluid fluid, Material material) {
        super(fluid, material);
        this.setCreativeTab(BreakingBad.BreakingBadTab_);
        this.setBlockName("Hydrofluoric Acid");
        this.setBlockTextureName("breakingbad:HydrofluoricAcid");
    }
}

 

 

 

Also, i figured out what i wanted to do for the potions, so that's covered.

 

Thanks a lot TGG for the help,

-Pandassaurus

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.