builders now clear unused power if idle too long, close #1587

This commit is contained in:
SpaceToad 2014-05-01 15:27:27 +02:00
parent 920be38a5f
commit a9777c7d92

View file

@ -40,6 +40,9 @@ public abstract class TileAbstractBuilder extends TileBuildCraft implements ITil
@MjBattery(maxReceivedPerCycle = 100, maxCapacity = FULL_CHEST_ENERGY, minimumConsumption = 1) @MjBattery(maxReceivedPerCycle = 100, maxCapacity = FULL_CHEST_ENERGY, minimumConsumption = 1)
protected double mjStored = 0; protected double mjStored = 0;
private double mjPrev = 0;
private int mjUnchangedCycles = 0;
@NetworkData @NetworkData
public LinkedList<LaserData> pathLasers = new LinkedList<LaserData> (); public LinkedList<LaserData> pathLasers = new LinkedList<LaserData> ();
@ -67,6 +70,11 @@ public abstract class TileAbstractBuilder extends TileBuildCraft implements ITil
public void updateEntity() { public void updateEntity() {
super.updateEntity(); super.updateEntity();
if (mjPrev != mjStored) {
mjPrev = mjStored;
mjUnchangedCycles = 0;
}
BuildingItem toRemove = null; BuildingItem toRemove = null;
for (BuildingItem i : buildersInAction) { for (BuildingItem i : buildersInAction) {
@ -80,6 +88,27 @@ public abstract class TileAbstractBuilder extends TileBuildCraft implements ITil
if (toRemove != null) { if (toRemove != null) {
buildersInAction.remove(toRemove); 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<BuildingItem> getBuilders() { public ArrayList<BuildingItem> getBuilders() {