Small correction to checked energy extensions

This commit is contained in:
DBotThePony 2023-01-14 14:24:48 +07:00
parent b9cb5db9ac
commit 1365ac445a
Signed by: DBot
GPG Key ID: DCC23B5715498507

View File

@ -38,6 +38,9 @@ internal fun IEnergyStorage.receiveEnergy(amount: Decimal, simulate: Boolean): D
return receiveEnergyChecked(amount, simulate) return receiveEnergyChecked(amount, simulate)
if (!amount.isPositive) if (!amount.isPositive)
throw IllegalArgumentException("Negative energy: $amount")
if (!canReceive())
return Decimal.ZERO return Decimal.ZERO
if (amount > Decimal.INT_MAX_VALUE) if (amount > Decimal.INT_MAX_VALUE)
@ -54,6 +57,9 @@ internal fun IEnergyStorage.extractEnergy(amount: Decimal, simulate: Boolean): D
return extractEnergyChecked(amount, simulate) return extractEnergyChecked(amount, simulate)
if (!amount.isPositive) if (!amount.isPositive)
throw IllegalArgumentException("Negative energy: $amount")
if (!canExtract())
return Decimal.ZERO return Decimal.ZERO
if (amount > Decimal.INT_MAX_VALUE) if (amount > Decimal.INT_MAX_VALUE)