Skip to content

Commit

Permalink
Fix incorrect bounds check, restrict interface to only work with lear…
Browse files Browse the repository at this point in the history
…ned items
  • Loading branch information
62832 committed Apr 29, 2024
1 parent 92aeb53 commit 22a4c45
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/main/java/gripe/_90/appliede/iface/EMCInterfaceLogic.java
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,12 @@ private boolean tryUsePlan(int slot, AEKey what, int amount) {
return false;
}

var knowledge = grid.getService(KnowledgeService.class);

if (!knowledge.getKnowledge().hasKnowledge(itemKey.toStack())) {
return false;
}

if (amount < 0) {
amount = -amount;
var inSlot = storage.getStack(slot);
Expand All @@ -227,7 +233,7 @@ private boolean tryUsePlan(int slot, AEKey what, int amount) {
var totalEmc = itemEmc.multiply(BigInteger.valueOf(amount));
var insertedItems = 0;

while (totalEmc.compareTo(BigInteger.valueOf(Long.MAX_VALUE)) > 0) {
while (totalEmc.compareTo(BigInteger.ZERO) > 0) {
var toDeposit = clampedLong(totalEmc);
var energyToExpend = PowerMultiplier.CONFIG.multiply(toDeposit);
var availablePower = grid.getEnergyService()
Expand All @@ -238,9 +244,7 @@ private boolean tryUsePlan(int slot, AEKey what, int amount) {
}

grid.getEnergyService().extractAEPower(energyToExpend, Actionable.MODULATE, PowerMultiplier.CONFIG);
grid.getService(KnowledgeService.class)
.getStorage()
.insert(EMCKey.base(), toDeposit, Actionable.MODULATE, requestSource);
knowledge.getStorage().insert(EMCKey.base(), toDeposit, Actionable.MODULATE, requestSource);

var deposited = BigInteger.valueOf(toDeposit);
insertedItems += (int) deposited.divide(itemEmc).longValue();
Expand Down Expand Up @@ -272,7 +276,7 @@ private boolean acquireFromNetwork(IGrid grid, int slot, AEKey what, long amount
var totalEmc = itemEmc.multiply(BigInteger.valueOf(amount));
var acquiredItems = 0L;

while (totalEmc.compareTo(BigInteger.valueOf(Long.MAX_VALUE)) > 0) {
while (totalEmc.compareTo(BigInteger.ZERO) > 0) {
var toWithdraw = clampedLong(totalEmc);
var canWithdraw = emcStorage.extract(EMCKey.base(), toWithdraw, Actionable.SIMULATE, requestSource);

Expand Down

0 comments on commit 22a4c45

Please sign in to comment.