From a9777c7d92c695aa0438a94cfb89fc609810be87 Mon Sep 17 00:00:00 2001 From: SpaceToad Date: Thu, 1 May 2014 15:27:27 +0200 Subject: [PATCH] builders now clear unused power if idle too long, close #1587 --- .../builders/TileAbstractBuilder.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/common/buildcraft/builders/TileAbstractBuilder.java b/common/buildcraft/builders/TileAbstractBuilder.java index 2ea80b87..70f76137 100755 --- a/common/buildcraft/builders/TileAbstractBuilder.java +++ b/common/buildcraft/builders/TileAbstractBuilder.java @@ -40,6 +40,9 @@ public abstract class TileAbstractBuilder extends TileBuildCraft implements ITil @MjBattery(maxReceivedPerCycle = 100, maxCapacity = FULL_CHEST_ENERGY, minimumConsumption = 1) protected double mjStored = 0; + private double mjPrev = 0; + private int mjUnchangedCycles = 0; + @NetworkData public LinkedList pathLasers = new LinkedList (); @@ -67,6 +70,11 @@ public abstract class TileAbstractBuilder extends TileBuildCraft implements ITil public void updateEntity() { super.updateEntity(); + if (mjPrev != mjStored) { + mjPrev = mjStored; + mjUnchangedCycles = 0; + } + BuildingItem toRemove = null; for (BuildingItem i : buildersInAction) { @@ -80,6 +88,27 @@ public abstract class TileAbstractBuilder extends TileBuildCraft implements ITil if (toRemove != null) { buildersInAction.remove(toRemove); } + + if (mjPrev != mjStored) { + mjPrev = mjStored; + mjUnchangedCycles = 0; + } + + mjUnchangedCycles++; + + /** + * After 100 cycles with no consumption or additional power, start to + * slowly to decrease the amount of power available in the builder. + */ + if (mjUnchangedCycles > 100) { + mjStored -= 100; + + if (mjStored < 0) { + mjStored = 0; + } + + mjPrev = mjStored; + } } public ArrayList getBuilders() {