Update drain/fill to take into account pipe connections (#1371)

This commit is contained in:
Jason Mitchell 2018-02-10 11:51:55 -08:00 committed by Blood-Asp
parent 4a4f7da15f
commit 2b21b51b64

View file

@ -1173,44 +1173,69 @@ public class BaseMetaPipeEntity extends BaseTileEntity implements IGregTechTileE
return mMetaTileEntity.injectRotationalEnergy(aSide, aSpeed, aEnergy);
}
private boolean canMoveFluidOnSide(ForgeDirection aSide, Fluid aFluid, boolean isFill) {
if (aSide == ForgeDirection.UNKNOWN)
return true;
if (!mMetaTileEntity.isConnectedAtSide((byte) aSide.ordinal()))
return false;
if(isFill && mMetaTileEntity.isLiquidInput((byte) aSide.ordinal())
&& getCoverBehaviorAtSide((byte) aSide.ordinal()).letsFluidIn((byte) aSide.ordinal(), getCoverIDAtSide((byte) aSide.ordinal()), getCoverDataAtSide((byte) aSide.ordinal()), mMetaTileEntity.getFluid() == null ? null : mMetaTileEntity.getFluid().getFluid(), this))
return true;
if (!isFill && mMetaTileEntity.isLiquidOutput((byte) aSide.ordinal())
&& getCoverBehaviorAtSide((byte) aSide.ordinal()).letsFluidOut((byte) aSide.ordinal(), getCoverIDAtSide((byte) aSide.ordinal()), getCoverDataAtSide((byte) aSide.ordinal()), mMetaTileEntity.getFluid() == null ? null : mMetaTileEntity.getFluid().getFluid(), this))
return true;
return false;
}
@Override
public int fill(ForgeDirection aSide, FluidStack aFluid, boolean doFill) {
if (mTickTimer > 5 && canAccessData() && (aSide == ForgeDirection.UNKNOWN || (mMetaTileEntity.isLiquidInput((byte) aSide.ordinal()) && getCoverBehaviorAtSide((byte) aSide.ordinal()).letsFluidIn((byte) aSide.ordinal(), getCoverIDAtSide((byte) aSide.ordinal()), getCoverDataAtSide((byte) aSide.ordinal()), aFluid == null ? null : aFluid.getFluid(), this))))
return mMetaTileEntity.fill(aSide, aFluid, doFill);
public int fill(ForgeDirection aSide, FluidStack aFluidStack, boolean doFill) {
if (mTickTimer > 5 && canAccessData() && canMoveFluidOnSide(aSide, aFluidStack == null ? null : aFluidStack.getFluid(), true))
return mMetaTileEntity.fill(aSide, aFluidStack, doFill);
return 0;
}
@Override
public FluidStack drain(ForgeDirection aSide, int maxDrain, boolean doDrain) {
if (mTickTimer > 5 && canAccessData() && (aSide == ForgeDirection.UNKNOWN || (mMetaTileEntity.isLiquidOutput((byte) aSide.ordinal()) && getCoverBehaviorAtSide((byte) aSide.ordinal()).letsFluidOut((byte) aSide.ordinal(), getCoverIDAtSide((byte) aSide.ordinal()), getCoverDataAtSide((byte) aSide.ordinal()), mMetaTileEntity.getFluid() == null ? null : mMetaTileEntity.getFluid().getFluid(), this))))
if (mTickTimer > 5 && canAccessData() && canMoveFluidOnSide(aSide, mMetaTileEntity.getFluid() == null ? null : mMetaTileEntity.getFluid().getFluid(), false))
return mMetaTileEntity.drain(aSide, maxDrain, doDrain);
return null;
}
@Override
public FluidStack drain(ForgeDirection aSide, FluidStack aFluid, boolean doDrain) {
if (mTickTimer > 5 && canAccessData() && (aSide == ForgeDirection.UNKNOWN || (mMetaTileEntity.isLiquidOutput((byte) aSide.ordinal()) && getCoverBehaviorAtSide((byte) aSide.ordinal()).letsFluidOut((byte) aSide.ordinal(), getCoverIDAtSide((byte) aSide.ordinal()), getCoverDataAtSide((byte) aSide.ordinal()), aFluid == null ? null : aFluid.getFluid(), this))))
return mMetaTileEntity.drain(aSide, aFluid, doDrain);
public FluidStack drain(ForgeDirection aSide, FluidStack aFluidStack, boolean doDrain) {
if (mTickTimer > 5 && canAccessData() && canMoveFluidOnSide(aSide, aFluidStack == null ? null : aFluidStack.getFluid(), false))
return mMetaTileEntity.drain(aSide, aFluidStack, doDrain);
return null;
}
@Override
public boolean canFill(ForgeDirection aSide, Fluid aFluid) {
if (mTickTimer > 5 && canAccessData() && (aSide == ForgeDirection.UNKNOWN || (mMetaTileEntity.isLiquidInput((byte) aSide.ordinal()) && getCoverBehaviorAtSide((byte) aSide.ordinal()).letsFluidIn((byte) aSide.ordinal(), getCoverIDAtSide((byte) aSide.ordinal()), getCoverDataAtSide((byte) aSide.ordinal()), aFluid, this))))
if (mTickTimer > 5 && canAccessData() && canMoveFluidOnSide(aSide, aFluid, true))
return mMetaTileEntity.canFill(aSide, aFluid);
return false;
}
@Override
public boolean canDrain(ForgeDirection aSide, Fluid aFluid) {
if (mTickTimer > 5 && canAccessData() && (aSide == ForgeDirection.UNKNOWN || (mMetaTileEntity.isLiquidOutput((byte) aSide.ordinal()) && getCoverBehaviorAtSide((byte) aSide.ordinal()).letsFluidOut((byte) aSide.ordinal(), getCoverIDAtSide((byte) aSide.ordinal()), getCoverDataAtSide((byte) aSide.ordinal()), aFluid, this))))
if (mTickTimer > 5 && canAccessData() && canMoveFluidOnSide(aSide, aFluid, false))
return mMetaTileEntity.canDrain(aSide, aFluid);
return false;
}
@Override
public FluidTankInfo[] getTankInfo(ForgeDirection aSide) {
if (canAccessData() && (aSide == ForgeDirection.UNKNOWN || (mMetaTileEntity.isLiquidInput((byte) aSide.ordinal()) && getCoverBehaviorAtSide((byte) aSide.ordinal()).letsFluidIn((byte) aSide.ordinal(), getCoverIDAtSide((byte) aSide.ordinal()), getCoverDataAtSide((byte) aSide.ordinal()), null, this)) || (mMetaTileEntity.isLiquidOutput((byte) aSide.ordinal()) && getCoverBehaviorAtSide((byte) aSide.ordinal()).letsFluidOut((byte) aSide.ordinal(), getCoverIDAtSide((byte) aSide.ordinal()), getCoverDataAtSide((byte) aSide.ordinal()), null, this))))
if (canAccessData()
&& (aSide == ForgeDirection.UNKNOWN
|| (mMetaTileEntity.isLiquidInput((byte) aSide.ordinal())
&& getCoverBehaviorAtSide((byte) aSide.ordinal()).letsFluidIn((byte) aSide.ordinal(), getCoverIDAtSide((byte) aSide.ordinal()), getCoverDataAtSide((byte) aSide.ordinal()), null, this))
|| (mMetaTileEntity.isLiquidOutput((byte) aSide.ordinal()) && getCoverBehaviorAtSide((byte) aSide.ordinal()).letsFluidOut((byte) aSide.ordinal(), getCoverIDAtSide((byte) aSide.ordinal()), getCoverDataAtSide((byte) aSide.ordinal()), null, this))
// Doesn't need to be connected to get Tank Info -- otherwise things can't connect
)
)
return mMetaTileEntity.getTankInfo(aSide);
return new FluidTankInfo[]{};
}