Skip to content

Commit

Permalink
Fix wonky source import logic, use proper canAccept/Provide metho…
Browse files Browse the repository at this point in the history
…ds to check during import/export
  • Loading branch information
62832 committed Dec 24, 2024
1 parent f51faf2 commit 44dc77c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public long transfer(StackTransferContext context, AEKey what, long amount) {
context.getActionSource(),
Actionable.MODULATE);

if (extracted > 0) {
if (extracted > 0 && sourceTile.canAcceptSource(extracted)) {
sourceTile.receiveSource(extracted, false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,30 +46,29 @@ public boolean transfer(StackTransferContext context) {
var inv = context.getInternalStorage().getInventory();

// Check how much source we can actually insert
var amount = inv.insert(SourceKey.KEY, rawAmount, Actionable.SIMULATE, context.getActionSource());
var amount = (int) inv.insert(SourceKey.KEY, rawAmount, Actionable.SIMULATE, context.getActionSource());

if (amount > 0) {
sourceTile.extractSource((int) amount, false);
}
if (amount > 0 && sourceTile.canProvideSource(amount)) {
sourceTile.extractSource(amount, false);
var inserted = inv.insert(SourceKey.KEY, amount, Actionable.MODULATE, context.getActionSource());

var inserted = inv.insert(SourceKey.KEY, amount, Actionable.MODULATE, context.getActionSource());
if (inserted < amount) {
var leftover = amount - inserted;
var backFill = (int) Math.min(leftover, sourceTile.getSourceCapacity() - sourceTile.getSource());

if (inserted < amount) {
var leftover = amount - inserted;
var backFill = (int) Math.min(leftover, sourceTile.getSourceCapacity() - sourceTile.getSource());
if (backFill > 0) {
sourceTile.receiveSource(backFill, false);
}

if (backFill > 0) {
sourceTile.receiveSource(backFill, false);
if (leftover > backFill) {
LOGGER.error("Storage import issue, voided {} source.", leftover - backFill);
}
}

if (leftover > backFill) {
LOGGER.error("Storage import issue, voided {} source.", leftover - backFill);
}
var opsUsed = Math.max(1, inserted / SourceKeyType.TYPE.getAmountPerOperation());
context.reduceOperationsRemaining(opsUsed);
}

var opsUsed = Math.max(1, inserted / SourceKeyType.TYPE.getAmountPerOperation());
context.reduceOperationsRemaining(opsUsed);

return amount > 0;
}
}

0 comments on commit 44dc77c

Please sign in to comment.