diff --git a/core/src/mindustry/world/blocks/power/PowerDiode.java b/core/src/mindustry/world/blocks/power/PowerDiode.java index 75f589eabd..03892d1c54 100644 --- a/core/src/mindustry/world/blocks/power/PowerDiode.java +++ b/core/src/mindustry/world/blocks/power/PowerDiode.java @@ -71,8 +71,8 @@ public class PowerDiode extends Block{ // prevent sending more than the front can handle amount = Mathf.clamp(amount, 0, frontGraph.getTotalBatteryCapacity() * (1 - frontStored)); - backGraph.useBatteries(amount); - frontGraph.chargeBatteries(amount); + backGraph.transferPower(-amount); + frontGraph.transferPower(amount); } } } diff --git a/core/src/mindustry/world/blocks/power/PowerGraph.java b/core/src/mindustry/world/blocks/power/PowerGraph.java index 8c79b63804..03aa029f19 100644 --- a/core/src/mindustry/world/blocks/power/PowerGraph.java +++ b/core/src/mindustry/world/blocks/power/PowerGraph.java @@ -21,6 +21,8 @@ public class PowerGraph{ private final WindowedMean powerBalance = new WindowedMean(60); private float lastPowerProduced, lastPowerNeeded, lastPowerStored; private float lastScaledPowerIn, lastScaledPowerOut, lastCapacity; + //diodes workaround for correct energy production info + private float energyDelta = 0f; private long lastFrameUpdated = -1; private final int graphID; @@ -62,6 +64,15 @@ public class PowerGraph{ return lastPowerStored; } + public void transferPower(float amount){ + if(amount > 0){ + chargeBatteries(amount); + }else{ + useBatteries(-amount); + } + energyDelta += amount; + } + public float getSatisfaction(){ if(Mathf.zero(lastPowerProduced)){ return 0f; @@ -218,7 +229,8 @@ public class PowerGraph{ lastCapacity = getTotalBatteryCapacity(); lastPowerStored = getBatteryStored(); - powerBalance.add((lastPowerProduced - lastPowerNeeded) / Time.delta); + powerBalance.add((lastPowerProduced - lastPowerNeeded + energyDelta) / Time.delta); + energyDelta = 0f; if(!(consumers.size == 0 && producers.size == 0 && batteries.size == 0)){ diff --git a/core/src/mindustry/world/blocks/power/PowerNode.java b/core/src/mindustry/world/blocks/power/PowerNode.java index 1e77e2b41d..43c292e5b0 100644 --- a/core/src/mindustry/world/blocks/power/PowerNode.java +++ b/core/src/mindustry/world/blocks/power/PowerNode.java @@ -107,7 +107,7 @@ public class PowerNode extends PowerBlock{ super.setBars(); bars.add("power", entity -> new Bar(() -> Core.bundle.format("bar.powerbalance", - ((entity.power.graph.getPowerBalance() >= 0 ? "+" : "") + Strings.fixed(entity.power.graph.getPowerBalance() * 60, 1))), + ((entity.power.graph.getPowerBalance() >= 0 ? "+" : "") + UI.formatAmount((int)(entity.power.graph.getPowerBalance() * 60)))), () -> Pal.powerBar, () -> Mathf.clamp(entity.power.graph.getLastPowerProduced() / entity.power.graph.getLastPowerNeeded())));