From f99777f9039a745222f9571b3a357f0601430166 Mon Sep 17 00:00:00 2001 From: Vilim Lendvaj Date: Sun, 8 Mar 2015 23:21:45 +0100 Subject: [PATCH] Add a cooling buffer, fix #2530 Now no coolant is lost due to rounding, and coolants that are too strong will not cause engines to blow up before even being used. --- common/buildcraft/energy/TileEngineIron.java | 30 ++++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/common/buildcraft/energy/TileEngineIron.java b/common/buildcraft/energy/TileEngineIron.java index f4c4c568..e04796a9 100644 --- a/common/buildcraft/energy/TileEngineIron.java +++ b/common/buildcraft/energy/TileEngineIron.java @@ -48,6 +48,7 @@ public class TileEngineIron extends TileEngineWithInventory implements IFluidHan public Tank tankCoolant = new Tank("tankCoolant", MAX_LIQUID, this); private int burnTime = 0; + private float coolingBuffer = 0.0f; private TankManager tankManager = new TankManager(); private IFuel currentFuel; @@ -246,6 +247,21 @@ public class TileEngineIron extends TileEngineWithInventory implements IFluidHan private void coolEngine(float idealHeat) { float extraHeat = heat - idealHeat; + if (coolingBuffer < extraHeat) { + fillCoolingBuffer(); + } + + if (coolingBuffer >= extraHeat) { + coolingBuffer -= extraHeat; + heat -= extraHeat; + return; + } + + heat -= coolingBuffer; + coolingBuffer = 0.0f; + } + + private void fillCoolingBuffer() { FluidStack coolant = this.tankCoolant.getFluid(); if (coolant == null) { return; @@ -256,18 +272,8 @@ public class TileEngineIron extends TileEngineWithInventory implements IFluidHan if (currentCoolant != null) { float cooling = currentCoolant.getDegreesCoolingPerMB(heat); cooling /= getBiomeTempScalar(); - - if (cooling > extraHeat) { - return; - } - - if (coolantAmount * cooling > extraHeat) { - tankCoolant.drain(Math.round(extraHeat / cooling), true); - heat -= extraHeat; - } else { - tankCoolant.drain(coolantAmount, true); - heat -= coolantAmount * cooling; - } + coolingBuffer += coolantAmount * cooling; + tankCoolant.drain(coolantAmount, true); } }