From 0a4193b72ea46b48b24afea99da69404c7f25c7c Mon Sep 17 00:00:00 2001 From: CovertJaguar Date: Thu, 5 Dec 2013 18:05:32 -0800 Subject: [PATCH] Some more minor optimizations --- common/buildcraft/core/utils/MathUtils.java | 4 ++++ .../transport/PipeTransportFluids.java | 19 +++++++++---------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/common/buildcraft/core/utils/MathUtils.java b/common/buildcraft/core/utils/MathUtils.java index ad6432fe..d0c3adff 100644 --- a/common/buildcraft/core/utils/MathUtils.java +++ b/common/buildcraft/core/utils/MathUtils.java @@ -14,6 +14,10 @@ package buildcraft.core.utils; */ public class MathUtils { + public static int clamp(int value, int min, int max) { + return value < min ? min : (value > max ? max : value); + } + public static float clamp(float value, float min, float max) { return value < min ? min : (value > max ? max : value); } diff --git a/common/buildcraft/transport/PipeTransportFluids.java b/common/buildcraft/transport/PipeTransportFluids.java index 407c4fd7..7fd9b3f3 100644 --- a/common/buildcraft/transport/PipeTransportFluids.java +++ b/common/buildcraft/transport/PipeTransportFluids.java @@ -62,15 +62,14 @@ public class PipeTransportFluids extends PipeTransport implements IFluidHandler @Override public FluidStack drain(int maxDrain, boolean doDrain) { - int maxToDrain = Math.min(maxDrain, Math.min(flowRate, getAvailable())); - if (maxToDrain < 0) + int maxToDrain = getAvailable(); + if (maxToDrain > maxDrain) + maxToDrain = maxDrain; + if (maxToDrain > flowRate) + maxToDrain = flowRate; + if (maxToDrain <= 0) return null; - - FluidStack drained = super.drain(maxToDrain, doDrain); - if (drained == null) - return null; - - return drained; + return super.drain(maxToDrain, doDrain); } public void moveFluids() { @@ -88,7 +87,7 @@ public class PipeTransportFluids extends PipeTransport implements IFluidHandler } public int getAvailable() { - int all = this.getFluid() != null ? this.getFluid().amount : 0; + int all = getFluidAmount(); for (short slot : incomming) { all -= slot; } @@ -359,7 +358,7 @@ public class PipeTransportFluids extends PipeTransport implements IFluidHandler internalTanks[o.ordinal()].drain(filled, true); if (filled <= 0) { outputTTL[o.ordinal()]--; - } + } // else FluidEvent.fireEvent(new FluidMotionEvent(liquidToPush, container.worldObj, container.xCoord, container.yCoord, container.zCoord)); } }