From 22a4c45ce1435083c4e16052cff2aa6da8b7917f Mon Sep 17 00:00:00 2001 From: 90 Date: Mon, 29 Apr 2024 17:08:11 +0100 Subject: [PATCH] Fix incorrect bounds check, restrict interface to only work with learned items --- .../_90/appliede/iface/EMCInterfaceLogic.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/java/gripe/_90/appliede/iface/EMCInterfaceLogic.java b/src/main/java/gripe/_90/appliede/iface/EMCInterfaceLogic.java index c2e505c..151fa4b 100644 --- a/src/main/java/gripe/_90/appliede/iface/EMCInterfaceLogic.java +++ b/src/main/java/gripe/_90/appliede/iface/EMCInterfaceLogic.java @@ -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); @@ -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() @@ -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(); @@ -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);