Jump to content

[Solved] [1.7.2] FluidContainerRegistry.getFluidForFilledItem() returns null


Recommended Posts

Posted

So I was playing around with fluids in guis and when I try to put a fluid into a tank using the method from the FluidContainerRegistry, it always returns null. Even if I put a water bucket or a lava bucket. If I try to put in a fluid without using that method, just defining one like: FluidStack fluid = new FluidStack(Mod.fluid, bucketSize); it works, but not when I'm using the method to get the the fluid out of the bucket.

 

TileEntity Code:

 

(The only important part is updateEntity(), all other code works fine and is tested, so I'm just posting that method)

 

    @Override
    public void updateEntity()
    {
        FluidStack fluid = tank.getFluid();
        int bucketSize = FluidContainerRegistry.BUCKET_VOLUME;

        if (!worldObj.isRemote)
        {
            ItemStack stack = items[0];

            if (stack != null)
            {
                FluidStack liquid  = null;
                
                if (stack.getItem().getContainerItem() != null)
                {
                    liquid = FluidContainerRegistry.getFluidForFilledItem(stack);
                }

                if (liquid != null)
                {
                    if (fill(ForgeDirection.UNKNOWN, liquid, false) == liquid.amount)
                    {
                        fill(ForgeDirection.UNKNOWN, liquid, true);
                        setInventorySlotContents(0, consumeItem(stack)); //consumes the item (for method look down below)
                    }
                }
            }

            if (items[1] != null)
            {
                if (FluidContainerRegistry.isBucket(items[1]))
                {
                    if (tank.getFluid() != null)
                    {
                        if (tank.getFluidAmount() >= bucketSize)
                        {
                            setInventorySlotContents(1, FluidContainerRegistry.fillFluidContainer(tank.getFluid(), items[1]));
                            drain(ForgeDirection.UNKNOWN, tank.getFluid(), bucketSize, true);
                        }
                    }
                }
            }
        }
    }

 

I've got two slots; one for filling and one for draining a bucket. The drain() and fill() methods are both working, there is nothing wrong there.

 

consumeItem(ItemStack stack):

 

    public static ItemStack consumeItem(ItemStack stack)
    {
        if (stack.stackSize == 1)
        {
            if (stack.getItem().getContainerItem() != null)
            {
                return stack.getItem().getContainerItem(stack);
            }
            else
            {
                return null;
            }
        }
        else
        {
            stack.splitStack(1);

            return stack;
        }
    }

 

Thanks for any help!

Posted

I've also noticed that the fillFluidContainer(FluidStack fluid, ItemStack container) also returns null, is this an error/problem on my side of coding or does the Forge code simply not work. Would be grateful for any answer.

Posted

Check your version of Forge. Before 10.12.0.1034 there were quite a lot bugs in the fluid api that resulted in problems like you are describing. The only other thing I can think of is that your itemstack is invalid (null or not a registered fluid container).

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.