Skip to content

Commit

Permalink
fix: missing energynet overflow fix
Browse files Browse the repository at this point in the history
  • Loading branch information
StarWishsama committed Nov 9, 2024
1 parent df25dd3 commit 1425b6d
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand All @@ -328,7 +330,7 @@ private int tickAllCapacitors() {
int supply = 0;

for (Map.Entry<Location, EnergyNetComponent> entry : capacitors.entrySet()) {
supply = MathUtil.saturatedAdd(supply, entry.getValue().getCharge(entry.getKey()));
supply = NumberUtils.flowSafeAddition(supply, entry.getValue().getCharge(entry.getKey()));
}

return supply;
Expand Down

0 comments on commit 1425b6d

Please sign in to comment.