Jump to content

[Solved][1.7.10]Custom Fluid - NullPointerException


grand_mind1

Recommended Posts

Hello, I'm trying to create a custom coffee liquid. I semi-followed(I know the "semi-" part is where I went wrong, I just can't find what I didn't do/changed that would affect it in this way) the tutorial on the wiki here: http://www.minecraftforge.net/wiki/Create_a_Fluid however, when I try to run the game, I get the following error:

 

 

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.darichey.ACOJ.block.BlockLiquidCoffee.<init>(BlockLiquidCoffee.java:27)
at com.darichey.ACOJ.init.ModBlocks.<clinit>(ModBlocks.java:22)
... 47 more

 

 

 

The init() method from the following class is called from my preInit() method in my main class:

 

public class ModBlocks
{
    public static final Fluid LiquidCoffee = new LiquidCoffee();
    public static final BlockFluidClassic BlockLiquidCoffee = new BlockLiquidCoffee(LiquidCoffee, Material.water);

    public static void init()
    {
        GameRegistry.registerBlock(BlockLiquidCoffee, Names.LIQUID_COFFEE_BLOCK);
        FluidRegistry.registerFluid(LiquidCoffee);
    }
}

 

 

The LiquidCoffee class:

 

public class LiquidCoffee extends Fluid
{
    public LiquidCoffee()
    {
        super(Names.LIQUID_COFFEE);
        this.setUnlocalizedName(Names.LIQUID_COFFEE);
        this.setViscosity(2000);
    }
}

 

 

The BlockLiquidCoffee class:

 

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

    @SideOnly(Side.CLIENT)
    protected IIcon flowingIcon;

    public BlockLiquidCoffee(Fluid fluid, Material material)
    {
        super(fluid, material);
        this.setCreativeTab(CreativeTabACOJ.ACOJ_TAB);
        this.setBlockName(Names.LIQUID_COFFEE_BLOCK);
    }

    @Override
    public IIcon getIcon(int side, int meta)
    {
        return (side == 0 || side == 1)? stillIcon : flowingIcon;
    }

    @SideOnly(Side.CLIENT)
    @Override
    public void registerBlockIcons(IIconRegister iconRegister)
    {
        stillIcon = iconRegister.registerIcon(Reference.MOD_ID + ":LiquidCoffeeStill");
        flowingIcon = iconRegister.registerIcon(Reference.MOD_ID + ":LiquidCoffeeFlowing");
    }

    @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);
    }
}

 

 

If I've forgotten to include any relevant code, please tell me.

Thanks!  :D

Link to comment
Share on other sites

Try swapping these two lines:

 

        GameRegistry.registerBlock(BlockLiquidCoffee, Names.LIQUID_COFFEE_BLOCK);

        FluidRegistry.registerFluid(LiquidCoffee);

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Thank you for your reply. I've done so with the ModBlocks class now looking like this:

 

public class ModBlocks
{
    public static final Fluid LiquidCoffee = new LiquidCoffee();
    public static final BlockFluidClassic BlockLiquidCoffee = new BlockLiquidCoffee(LiquidCoffee, Material.water);

    public static void init()
    {
        FluidRegistry.registerFluid(LiquidCoffee);
        GameRegistry.registerBlock(BlockLiquidCoffee, Names.LIQUID_COFFEE_BLOCK);
    }
}

 

 

However, the problem still persists. The error is identical.

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.