diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/capability/energy/BlockEnergyStorageImpl.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/capability/energy/BlockEnergyStorageImpl.kt index fe1dccd81..cc7a7ed7e 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/capability/energy/BlockEnergyStorageImpl.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/capability/energy/BlockEnergyStorageImpl.kt @@ -72,18 +72,10 @@ sealed class BlockEnergyStorageImpl( if (!howMuch.isPositive) return Decimal.ZERO - @Suppress("NAME_SHADOWING") - var howMuch = howMuch - val maxOutput = maxOutput - - if (maxOutput != null) { - howMuch = howMuch.coerceAtMost(maxOutput) - } - if (!batteryLevel.isPositive) return Decimal.ZERO - val newLevel = (batteryLevel - howMuch).moreThanZero() + val newLevel = (batteryLevel - howMuch.coerceAtMost(maxOutput ?: Decimal.POSITIVE_INFINITY)).moreThanZero() val diff = (batteryLevel - newLevel) if (!simulate && batteryLevel != newLevel) { @@ -97,18 +89,10 @@ sealed class BlockEnergyStorageImpl( if (!howMuch.isPositive) return Decimal.ZERO - @Suppress("NAME_SHADOWING") - var howMuch = howMuch - val maxInput = maxInput - - if (maxInput != null) { - howMuch = howMuch.coerceAtMost(maxInput) - } - if (batteryLevel >= maxBatteryLevel && !maxBatteryLevel.isInfinite) return Decimal.ZERO - val newLevel = (batteryLevel + howMuch).coerceAtMost(maxBatteryLevel) + val newLevel = (batteryLevel + howMuch.coerceAtMost(maxInput ?: Decimal.POSITIVE_INFINITY)).coerceAtMost(maxBatteryLevel) val diff = (newLevel - batteryLevel) if (!simulate && batteryLevel != newLevel) { diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/capability/energy/ItemEnergyStorageImpl.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/capability/energy/ItemEnergyStorageImpl.kt index b3f29cb4a..2867fabd4 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/capability/energy/ItemEnergyStorageImpl.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/capability/energy/ItemEnergyStorageImpl.kt @@ -65,20 +65,11 @@ abstract class ItemEnergyStorageImpl(val itemStack: ItemStack) : IMatteryEnergyS if (!howMuch.isPositive || itemStack.count != 1) return Decimal.ZERO - @Suppress("NAME_SHADOWING") - var howMuch = howMuch - val maxInput = maxInput - - if (maxInput != null) { - howMuch = howMuch.coerceAtMost(maxInput) - } - val batteryLevel = batteryLevel - if (batteryLevel >= maxBatteryLevel && !maxBatteryLevel.isInfinite) return Decimal.ZERO - val newLevel = (batteryLevel + howMuch).coerceAtMost(maxBatteryLevel) + val newLevel = (batteryLevel + howMuch.coerceAtMost(maxInput ?: Decimal.POSITIVE_INFINITY)).coerceAtMost(maxBatteryLevel) val diff = (newLevel - batteryLevel) if (!simulate && batteryLevel != newLevel) {