From 51d8c06b9fc4528a3357e750c50ffe01830beaaf Mon Sep 17 00:00:00 2001 From: asiekierka Date: Thu, 11 Dec 2014 16:42:07 +0100 Subject: [PATCH] improve IFluidContainerItem logic, fix #2295 --- common/buildcraft/factory/BlockTank.java | 29 ++++++++++++++++-------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/common/buildcraft/factory/BlockTank.java b/common/buildcraft/factory/BlockTank.java index 83482969..2214befe 100644 --- a/common/buildcraft/factory/BlockTank.java +++ b/common/buildcraft/factory/BlockTank.java @@ -154,16 +154,27 @@ public class BlockTank extends BlockBuildCraft { } } } else if (current.getItem() instanceof IFluidContainerItem) { - IFluidContainerItem container = (IFluidContainerItem) current.getItem(); - FluidStack liquid = container.getFluid(current); - if (liquid != null && liquid.amount > 0) { - int qty = tank.fill(ForgeDirection.UNKNOWN, liquid, false); - tank.fill(ForgeDirection.UNKNOWN, container.drain(current, qty, true), true); - } else { - liquid = tank.drain(ForgeDirection.UNKNOWN, 1000, false); - int qtyToFill = container.fill(current, liquid, true); - tank.drain(ForgeDirection.UNKNOWN, qtyToFill, true); + if (!world.isRemote) { + IFluidContainerItem container = (IFluidContainerItem) current.getItem(); + FluidStack liquid = container.getFluid(current); + FluidStack tankLiquid = tank.getTankInfo(ForgeDirection.UNKNOWN)[0].fluid; + boolean mustDrain = (liquid == null || liquid.amount == 0); + boolean mustFill = (tankLiquid == null || tankLiquid.amount == 0); + if (mustDrain && mustFill) { + // Both are empty, do nothing + } else if (mustDrain || !entityplayer.isSneaking()) { + liquid = tank.drain(ForgeDirection.UNKNOWN, 1000, false); + int qtyToFill = container.fill(current, liquid, true); + tank.drain(ForgeDirection.UNKNOWN, qtyToFill, true); + } else if (mustFill || entityplayer.isSneaking()) { + if (liquid != null && liquid.amount > 0) { + int qty = tank.fill(ForgeDirection.UNKNOWN, liquid, false); + tank.fill(ForgeDirection.UNKNOWN, container.drain(current, qty, true), true); + } + } } + + return true; } } }