Jump to content

[Solved][1.7.10]Fluid Confusion[Solved]


SureShotM

Recommended Posts

So I am trying to make my own fluid, I have looked at and tried a few solutions to no avail. I have made sure that I am registering the fluid first then the block after, and to even make sure i directly the registering code into my preinit and that didn't work. I cant seem to find what I am doing wrong, I have a feeling I'm missing a line of code somewhere cause I've caught my self doing that sometimes recently. Either Way it keeps throwing a null error and I don't know why.

 

preinit code:

 

 

ModFluids.init();
        ModBlocks.init();
        GameRegistry.registerWorldGenerator(new WraithOreGen(), 0);
        ModItems.init();
        ModFluidBlocks.init();



        LogHelper.info("PreInit done.");

 

 

Fluid Class code:

 

 

public class FluidTestMod extends Fluid
{

    public FluidTestMod()
    {
        super(Names.Fluid.HYDROFLUORICACID);
        setUnlocalizedName(Names.Fluid.HYDROFLUORICACID);
        setLuminosity(;
    }

}

 

 

Fluid Block code:

 

 

public class HydrofluoricAcid extends BlockFluidClassic
{
    @SideOnly(Side.CLIENT)
    protected IIcon stillIcon;
    @SideOnly(Side.CLIENT)
    protected IIcon flowingIcon;

    public HydrofluoricAcid(Fluid fluid, Material material)
    {
        super(fluid, material);
        setCreativeTab(CreativeTabTestMod.TestMod_TAB);
        setBlockName(Names.Blocks.HYDROFLUORICACID);
    }

    @Override
    public IIcon getIcon(int side, int meta) {
        return (side == 0 || side == 1)? stillIcon : flowingIcon;
    }
    @SideOnly(Side.CLIENT)
    @Override
    public void registerBlockIcons(IIconRegister register)
    {
        stillIcon = register.registerIcon(Reference.MOD_ID + "hydrofluoricacid_still");
        flowingIcon = register.registerIcon(Reference.MOD_ID + "hydrofluoricacid_flow");
    }
    @Override
    public boolean canDisplace(IBlockAccess world, int x, int y, int z) {
        if (world.getBlock(x,  y,  z).getMaterial().isLiquid()) return false;
        return super.canDisplace(world, x, y, z);
    }

    @Override
    public boolean displaceIfPossible(World world, int x, int y, int z) {
        if (world.getBlock(x,  y,  z).getMaterial().isLiquid()) return false;
        return super.displaceIfPossible(world, x, y, z);
    }
}

 

 

Fluid Registry Code:

 

 

@GameRegistry.ObjectHolder(Reference.MOD_ID)
public class ModFluids
{
    public static final Fluid HydrofluoricAcid = new FluidTestMod();

    public static void init()
    {
        FluidRegistry.registerFluid(HydrofluoricAcid);

    }

 

 

 

Fluid Block Registry:

 

 

@GameRegistry.ObjectHolder(Reference.MOD_ID)
public class ModFluidBlocks
{
    public static final BlockFluidClassic hydrofluoric_acid = new HydrofluoricAcid(ModFluids.HydrofluoricAcid, Material.water);

    public static void init()
    {
        GameRegistry.registerBlock(hydrofluoric_acid, Names.Blocks.HYDROFLUORICACID);
    }

}

 

 

Error Log:

 

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.leo.testmod.block.HydrofluoricAcid.<init>(HydrofluoricAcid.java:27)

at com.leo.testmod.init.ModFluidBlocks.<clinit>(ModFluidBlocks.java:14)

 

~SureShotM/Leo~ gaming coding all around fun!

Link to comment
Share on other sites

Okay I'm confused a bit here then, All blocks or just Fluid Blocks?, only reason why I ask that is cause if you look at pahimar's tutorial or most tutorials at that they create a static init and load it to the preinit,

 

For my example in my case I have an ore that is in the ModBlocks.init(); witch I am calling from the preinit, I am doing same for my fluid block. I guess again I'm just confused.

~SureShotM/Leo~ gaming coding all around fun!

Link to comment
Share on other sites

okay I'll see what changing it will do for me, but i would like to note that I am not saying Pahimar is oh-so-fancy, but when you have the knowledge to look at other sources(open source mods) and look at there structure, it seams like it is more common  then not to see a static init load blocks, and items(not sure about recipes or fluids). I do appreciate the help though, I'm just sorta curious if there is a way to do this with the static init since it does seem to keep things organized and less cluttered. If the only way to fix this problem is by loading it through the preinit then so be it. Note what I mean by open source mods I specifically mean well known mods.

~SureShotM/Leo~ gaming coding all around fun!

Link to comment
Share on other sites

Well a few things now one I was looking at a mod that has fluid in them and found what looks like how they are doing it, so Ill give that a shot if that fails then I will just switch over, if any new errors come up I'll mention them but for now back to the trials and errors of coding.

~SureShotM/Leo~ gaming coding all around fun!

Link to comment
Share on other sites

Ok Got it working with the static init, but the interesting thing is I tried doing it without the static init and it still didn't work and threw the same null pointer, but I think it was because that the block wasn't connecting with the fluid id, so I added this to my Fluid Block class and it works now.

 

Fluids.HydrofluoricAcid.setBlock(this)

 

The code above goes into the constructor.

 

Also I would like to thank you for your help it did lead me to this solution, The other thing I would like to note is that the static init isn't ugly code in my opinion cause then you can register/initialize multiple blocks, again its all about the coders style and opinion though.

~SureShotM/Leo~ gaming coding all around fun!

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.



×
×
  • Create New...

Important Information

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