From 22951748722289f107e18c659ee98b2e19306e1d Mon Sep 17 00:00:00 2001 From: 90 Date: Thu, 9 May 2024 15:54:41 +0100 Subject: [PATCH] Fix power calculation resulting in potential infinite EMC void Closes #4 --- .../java/gripe/_90/appliede/me/service/EMCStorage.java | 8 +++----- 1 file changed, 3 insertions(+), 5 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 2cb6521..2a7f7d4 100644 --- a/src/main/java/gripe/_90/appliede/me/service/EMCStorage.java +++ b/src/main/java/gripe/_90/appliede/me/service/EMCStorage.java @@ -291,11 +291,9 @@ private void addKnowledge(AEItemKey what, IKnowledgeProvider provider, Player pl } private long getAmountAfterPowerExpenditure(long maxAmount, IEnergySource source) { - var requiredPower = PowerMultiplier.CONFIG.multiply(maxAmount); - var availablePower = source.extractAEPower(requiredPower, Actionable.SIMULATE, PowerMultiplier.CONFIG); - var powerToExpend = Math.min(requiredPower, availablePower); - source.extractAEPower(powerToExpend, Actionable.MODULATE, PowerMultiplier.CONFIG); - return (long) PowerMultiplier.CONFIG.divide(powerToExpend); + var availablePower = source.extractAEPower(maxAmount, Actionable.SIMULATE, PowerMultiplier.CONFIG); + source.extractAEPower(Math.min(maxAmount, availablePower), Actionable.MODULATE, PowerMultiplier.CONFIG); + return (double) maxAmount <= availablePower ? maxAmount : (long) availablePower; } public int getHighestTier() {