diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/energy/EnergyNet.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/energy/EnergyNet.java index c3b335b317..ae93826ffe 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/energy/EnergyNet.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/energy/EnergyNet.java @@ -154,7 +154,9 @@ public void tick(@Nonnull Block b, SlimefunBlockData blockData) { if (connectorNodes.isEmpty() && terminusNodes.isEmpty()) { updateHologram(b, "&4找不到能源网络", blockData::isPendingRemove); } else { - int supply = tickAllGenerators(timestamp::getAndAdd) + tickAllCapacitors(); + int generatorsSupply = tickAllGenerators(timestamp::getAndAdd); + int capacitorsSupply = tickAllCapacitors(); + int supply = NumberUtils.flowSafeAddition(generatorsSupply, capacitorsSupply); int remainingEnergy = supply; int demand = 0; @@ -187,7 +189,7 @@ public void tick(@Nonnull Block b, SlimefunBlockData blockData) { if (charge < capacity) { int availableSpace = capacity - charge; - demand += availableSpace; + demand = NumberUtils.flowSafeAddition(demand, availableSpace); if (remainingEnergy > 0) { if (remainingEnergy > availableSpace) { @@ -305,7 +307,7 @@ private int tickAllGenerators(@Nonnull LongConsumer timings) { loc.getWorld().createExplosion(loc, 0F, false); }); } else { - supply = MathUtil.saturatedAdd(supply, energy); + supply = NumberUtils.flowSafeAddition(supply, energy); } } catch (Exception | LinkageError throwable) { explodedBlocks.add(loc); @@ -328,7 +330,7 @@ private int tickAllCapacitors() { int supply = 0; for (Map.Entry entry : capacitors.entrySet()) { - supply = MathUtil.saturatedAdd(supply, entry.getValue().getCharge(entry.getKey())); + supply = NumberUtils.flowSafeAddition(supply, entry.getValue().getCharge(entry.getKey())); } return supply;