From ad5d0e42efe0d3d546a9dee91340288bf3e509c6 Mon Sep 17 00:00:00 2001 From: kekzdealer Date: Thu, 14 May 2020 19:00:10 +0200 Subject: Guarded against some edge case where you could get stuck with a wrong passive loss --- .../GTMTE_LapotronicSuperCapacitor.java | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/common/tileentities/GTMTE_LapotronicSuperCapacitor.java b/src/main/java/common/tileentities/GTMTE_LapotronicSuperCapacitor.java index 4ea0f06bb4..a23026b6ea 100644 --- a/src/main/java/common/tileentities/GTMTE_LapotronicSuperCapacitor.java +++ b/src/main/java/common/tileentities/GTMTE_LapotronicSuperCapacitor.java @@ -320,7 +320,7 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_MultiBlock } // Calculate how much energy to void each tick passiveDischargeAmount = new BigDecimal(tempCapacity).multiply(PASSIVE_DISCHARGE_FACTOR_PER_TICK).toBigInteger(); - + passiveDischargeAmount = recalculateLossWithMaintenance(super.getRepairStatus()); return formationChecklist; } @@ -442,11 +442,8 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_MultiBlock } // Loose some energy // Recalculate if the repair status changed - final int repairStatus = super.getRepairStatus(); - if(repairStatus != repairStatusCache) { - repairStatusCache = repairStatus; - passiveDischargeAmount = new BigDecimal(passiveDischargeAmount) - .multiply(BigDecimal.valueOf(1.0D + 0.2D * repairStatus)).toBigInteger(); + if(super.getRepairStatus() != repairStatusCache) { + passiveDischargeAmount = recalculateLossWithMaintenance(super.getRepairStatus()); } stored = stored.subtract(passiveDischargeAmount); stored = (stored.compareTo(BigInteger.ZERO) <= 0) ? BigInteger.ZERO : stored; @@ -454,6 +451,18 @@ public class GTMTE_LapotronicSuperCapacitor extends GT_MetaTileEntity_MultiBlock return true; } + /** + * To be called whenever the maintenance status changes or the capacity was recalculated + * @param repairStatus + * This machine's repair status + * @return new BigInteger instance for passiveDischargeAmount + */ + private BigInteger recalculateLossWithMaintenance(int repairStatus) { + repairStatusCache = repairStatus; + return new BigDecimal(passiveDischargeAmount) + .multiply(BigDecimal.valueOf(1.0D + 0.2D * repairStatus)).toBigInteger(); + } + /** * Calculate how much EU to draw from an Energy Hatch * @param hatchWatts -- cgit