From 0c3158dc39c94cd08261d3a60ba3a3b780a19bd6 Mon Sep 17 00:00:00 2001 From: 90 Date: Mon, 11 Nov 2024 18:09:21 +0000 Subject: [PATCH] Fix #19: Transmuting items to/from EMC does not limit the amount of items based on stored energy --- .../_90/appliede/me/service/EMCStorage.java | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/main/java/gripe/_90/appliede/me/service/EMCStorage.java b/src/main/java/gripe/_90/appliede/me/service/EMCStorage.java index a9554be..00785f2 100644 --- a/src/main/java/gripe/_90/appliede/me/service/EMCStorage.java +++ b/src/main/java/gripe/_90/appliede/me/service/EMCStorage.java @@ -328,16 +328,18 @@ private long getAmountAfterPowerExpenditure(BigInteger maxEmc, BigInteger itemEm var available = energyService.extractAEPower(toExpend.doubleValue(), Actionable.SIMULATE, PowerMultiplier.ONE); var expended = Math.min(available, toExpend.doubleValue()); - energyService.extractAEPower(expended, Actionable.MODULATE, PowerMultiplier.ONE); - - return expended == available - ? maxEmc.divide(itemEmc).longValue() - : BigDecimal.valueOf(available) - .min(toExpend) - .divide(multiplier, RoundingMode.HALF_UP) - .toBigInteger() - .divide(itemEmc) - .longValue(); + var amount = BigDecimal.valueOf(available) + .min(toExpend) + .divide(multiplier, RoundingMode.HALF_UP) + .toBigInteger() + .divide(itemEmc) + .longValue(); + + if (amount > 0) { + energyService.extractAEPower(expended, Actionable.MODULATE, PowerMultiplier.ONE); + } + + return amount; } private void addKnowledge(AEItemKey what, IKnowledgeProvider provider, Player player) {