Jump to content

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


Recommended Posts

Posted

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

Posted

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

 

 

Posted

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

Posted

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

Posted

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

 

Posted

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

 

 

 

 

 

Posted

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

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hi, i'm really having problems trying to set the texture to my custom item. I thought i'm doing everything correctly, but all i see is the missing texture block for my item. I am trying this for over a week now and getting really frustrated. The only time i could make the texture work, was when i used an older Forge version (52.0.1) for Minecraft (1.21.4). Was there a fundamental change for textures and models somewhere between versions that i'm missing? I started with Forge 54.1.0 and had this problem, so in my frustration i tried many things: Upgrading to Forge 54.1.1, created multiple new projects, workspaces, redownloaded everything and setting things up multiple times, as it was suggested in an older thread. Therea are no errors in the console logs, but maybe i'm blind, so i pasted the console logs to pastebin anyway: https://pastebin.com/zAM8RiUN The only time i see an error is when i change the models JSON file to an incorrect JSON which makes sense and that suggests to me it is actually reading the JSON file.   I set the github repository to public, i would be so thankful if anyone could take a look and tell me what i did wrong: https://github.com/xLorkin/teleport_pug_forge   As a note: i'm pretty new to modding, this is my first mod ever. But i'm used to programming. I had some up and downs, but through reading the documentation, using google and experimenting, i could solve all other problems. I only started modding for Minecraft because my son is such a big fan and wanted this mod.
    • Please read the FAQ (link in orange bar at top of page), and post logs as described there.
    • Hello fellow Minecrafters! I recently returned to Minecraft and realized I needed a wiki that displays basic information easily and had great user navigation. That’s why I decided to build: MinecraftSearch — a site by a Minecraft fan, for Minecraft fans. Key Features So Far Straight-to-the-Point Info: No extra fluff; just the essentials on items, mobs, recipes, loot and more. Clean & Intuitive Layout: Easy navigation so you spend less time scrolling and more time playing. Optimized Search: Search for anything—items, mobs, blocks—and get results instantly. What I’m Thinking of Adding More data/information: Catch chances for fishing rod, traveling villager trades, biomes info and a lot more. The website is still under development and need a lot more data added. Community Contributions: Potential for user-uploaded tips for items/mobs/blocks in the future. Feature Requests Welcome: Your ideas could shape how the wiki evolves! You can see my roadmap at the About page https://minecraftsearch.com/about I’d love for you to check out MinecraftSearch and see if it helps you find the info you need faster. Feedback is crucial—I want to develop this further based on what the community needs most, so please let me know what you think. Thanks, and happy crafting!
    • Instructions on how to install newer Java can be found in the FAQ
    • That's just plain wrong... newer versions are much better optimised and start a lot faster than 1.8.9, both Forge and Minecraft itself. Comparing Fabric 1.21 with Forge 1.8 is like comparing apples and oranges... one's brand new and the other's over a decade old.
  • Topics

  • Who's Online (See full list)

    • There are no registered users currently online
×
×
  • Create New...

Important Information

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