diff --git a/src/main/java/gripe/_90/arseng/me/strategy/SourceStorageExportStrategy.java b/src/main/java/gripe/_90/arseng/me/strategy/SourceStorageExportStrategy.java index e386143..2986698 100644 --- a/src/main/java/gripe/_90/arseng/me/strategy/SourceStorageExportStrategy.java +++ b/src/main/java/gripe/_90/arseng/me/strategy/SourceStorageExportStrategy.java @@ -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); } diff --git a/src/main/java/gripe/_90/arseng/me/strategy/SourceStorageImportStrategy.java b/src/main/java/gripe/_90/arseng/me/strategy/SourceStorageImportStrategy.java index 0e86305..31f7352 100644 --- a/src/main/java/gripe/_90/arseng/me/strategy/SourceStorageImportStrategy.java +++ b/src/main/java/gripe/_90/arseng/me/strategy/SourceStorageImportStrategy.java @@ -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; } }