Skip to content

Commit

Permalink
Fix #7819: Energy Acceptor randomly stops accepting power (#8087)
Browse files Browse the repository at this point in the history
If the buffer inside `ForgeEnergyAdaptor` got larger than `1e-9` but
smaller than `StoredEnergyAmount.MIN_AMOUNT`, the energy acceptor would
"get stuck". The issue could be reproduced by setting the buffer to
`1e-8`.
  • Loading branch information
Technici4n authored Aug 1, 2024
1 parent 485ca12 commit d806fde
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/main/java/appeng/helpers/ForgeEnergyAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import appeng.api.config.Actionable;
import appeng.api.config.PowerUnits;
import appeng.blockentity.powersink.IExternalPowerSink;
import appeng.me.energy.StoredEnergyAmount;

/**
* Adapts an {@link IExternalPowerSink} to TR Energy's {@link EnergyStorage} by buffering energy packets. Not ideal, but
Expand Down Expand Up @@ -54,6 +55,10 @@ protected void readSnapshot(Double snapshot) {
@Override
protected void onFinalCommit() {
buffer = sink.injectExternalPower(PowerUnits.TR, buffer, Actionable.MODULATE);
if (buffer < StoredEnergyAmount.MIN_AMOUNT) {
// Prevent a small leftover amount from blocking further energy insertions.
buffer = 0;
}
}

@Override
Expand All @@ -62,7 +67,7 @@ public long insert(long maxAmount, TransactionContext transaction) {
// Always schedule a push into the network at outer commit.
updateSnapshots(transaction);

if (Math.abs(buffer) <= 1e-9) {
if (buffer == 0) {
// Cap at the remaining capacity...
maxAmount = (long) Math
.floor(Math.min(maxAmount, this.sink.getExternalPowerDemand(PowerUnits.TR, maxAmount)));
Expand Down

0 comments on commit d806fde

Please sign in to comment.