improve IFluidContainerItem logic, fix #2295

This commit is contained in:
asiekierka 2014-12-11 16:42:07 +01:00
parent 01ad2501c9
commit 51d8c06b9f

View file

@ -154,18 +154,29 @@ public class BlockTank extends BlockBuildCraft {
} }
} }
} else if (current.getItem() instanceof IFluidContainerItem) { } else if (current.getItem() instanceof IFluidContainerItem) {
if (!world.isRemote) {
IFluidContainerItem container = (IFluidContainerItem) current.getItem(); IFluidContainerItem container = (IFluidContainerItem) current.getItem();
FluidStack liquid = container.getFluid(current); FluidStack liquid = container.getFluid(current);
if (liquid != null && liquid.amount > 0) { FluidStack tankLiquid = tank.getTankInfo(ForgeDirection.UNKNOWN)[0].fluid;
int qty = tank.fill(ForgeDirection.UNKNOWN, liquid, false); boolean mustDrain = (liquid == null || liquid.amount == 0);
tank.fill(ForgeDirection.UNKNOWN, container.drain(current, qty, true), true); boolean mustFill = (tankLiquid == null || tankLiquid.amount == 0);
} else { if (mustDrain && mustFill) {
// Both are empty, do nothing
} else if (mustDrain || !entityplayer.isSneaking()) {
liquid = tank.drain(ForgeDirection.UNKNOWN, 1000, false); liquid = tank.drain(ForgeDirection.UNKNOWN, 1000, false);
int qtyToFill = container.fill(current, liquid, true); int qtyToFill = container.fill(current, liquid, true);
tank.drain(ForgeDirection.UNKNOWN, qtyToFill, 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;
}
}
} }
return false; return false;