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!