Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

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

Featured Replies

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!

  • Author

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.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.