Update energy impls to make more use of infinity
This commit is contained in:
parent
2276f0ef45
commit
6de2f14fcd
@ -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) {
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user