diff options
Diffstat (limited to 'src/main/java/gregtech/common/covers/GT_Cover_Pump.java')
-rw-r--r-- | src/main/java/gregtech/common/covers/GT_Cover_Pump.java | 50 |
1 files changed, 26 insertions, 24 deletions
diff --git a/src/main/java/gregtech/common/covers/GT_Cover_Pump.java b/src/main/java/gregtech/common/covers/GT_Cover_Pump.java index c19f9d0d3a..a31a18c821 100644 --- a/src/main/java/gregtech/common/covers/GT_Cover_Pump.java +++ b/src/main/java/gregtech/common/covers/GT_Cover_Pump.java @@ -45,33 +45,35 @@ public class GT_Cover_Pump extends GT_CoverBehavior { return aCoverVariable; } } - if ((aTileEntity instanceof IFluidHandler)) { - final IFluidHandler tTank2 = aTileEntity.getITankContainerAtSide(side); - if (tTank2 != null) { - // aTileEntity.decreaseStoredEnergyUnits(GT_Utility.getTier(this.mTransferRate), true); - final IFluidHandler tTank1 = (IFluidHandler) aTileEntity; - if (aCoverVariable % 2 == 0) { - FluidStack tLiquid = tTank1.drain(side, this.mTransferRate, false); - if (tLiquid != null) { - tLiquid = tLiquid.copy(); - tLiquid.amount = tTank2.fill(side.getOpposite(), tLiquid, false); - if (tLiquid.amount > 0 && canTransferFluid(tLiquid)) { - tTank2.fill(side.getOpposite(), tTank1.drain(side, tLiquid.amount, true), true); - } - } - } else { - FluidStack tLiquid = tTank2.drain(side.getOpposite(), this.mTransferRate, false); - if (tLiquid != null) { - tLiquid = tLiquid.copy(); - tLiquid.amount = tTank1.fill(side, tLiquid, false); - if (tLiquid.amount > 0 && canTransferFluid(tLiquid)) { - tTank1.fill(side, tTank2.drain(side.getOpposite(), tLiquid.amount, true), true); - } - } + + if (aTileEntity instanceof IFluidHandler current) { + final IFluidHandler toAccess = aTileEntity.getITankContainerAtSide(side); + transferFluid(current, toAccess, side, aCoverVariable % 2); + } + return aCoverVariable; + } + + protected void transferFluid(IFluidHandler current, IFluidHandler toAccess, ForgeDirection side, + int exportOrImport) { + if (exportOrImport == 0) { + FluidStack liquid = current.drain(side, this.mTransferRate, false); + if (liquid != null) { + liquid = liquid.copy(); + liquid.amount = toAccess.fill(side.getOpposite(), liquid, false); + if (liquid.amount > 0 && canTransferFluid(liquid)) { + toAccess.fill(side.getOpposite(), current.drain(side, liquid.amount, true), true); } } + return; + } + FluidStack liquid = toAccess.drain(side.getOpposite(), this.mTransferRate, false); + if (liquid != null) { + liquid = liquid.copy(); + liquid.amount = current.fill(side, liquid, false); + if (liquid.amount > 0 && canTransferFluid(liquid)) { + current.fill(side, toAccess.drain(side.getOpposite(), liquid.amount, true), true); + } } - return aCoverVariable; } protected boolean canTransferFluid(FluidStack fluid) { |