Skip to content

Commit

Permalink
Fix potential voiding of imported EMC from energy collectors in the e…
Browse files Browse the repository at this point in the history
…vent of brownouts
  • Loading branch information
62832 committed May 13, 2024
1 parent 88603a6 commit 86dd102
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,23 @@ public boolean transfer(StackTransferContext context) {
}

var remainingTransfer = context.getOperationsRemaining() * EMCKeyType.TYPE.getAmountPerOperation();
var inserted = new AtomicLong(0);
var transferred = new AtomicLong(0);

be.getCapability(PECapabilities.EMC_STORAGE_CAPABILITY).ifPresent(emcStorage -> {
inserted.set(Math.min(remainingTransfer, emcStorage.getStoredEmc()));
StorageHelper.poweredInsert(
var inserted = StorageHelper.poweredInsert(
context.getEnergySource(),
context.getInternalStorage().getInventory(),
EMCKey.BASE,
inserted.get(),
Math.min(remainingTransfer, emcStorage.getStoredEmc()),
context.getActionSource(),
Actionable.MODULATE);
emcStorage.extractEmc(inserted.get(), IEmcStorage.EmcAction.EXECUTE);
emcStorage.extractEmc(inserted, IEmcStorage.EmcAction.EXECUTE);

var opsUsed = Math.max(1, inserted.get() / EMCKeyType.TYPE.getAmountPerOperation());
var opsUsed = Math.max(1, inserted / EMCKeyType.TYPE.getAmountPerOperation());
context.reduceOperationsRemaining(opsUsed);
transferred.set(inserted);
});

return inserted.get() > 0;
return transferred.get() > 0;
}
}

0 comments on commit 86dd102

Please sign in to comment.