Shortcut when trying to receive/extract zero matter

This commit is contained in:
DBotThePony 2023-07-19 17:18:02 +07:00
parent d534ebbbf2
commit 31cb9973d5
Signed by: DBot
GPG Key ID: DCC23B5715498507

View File

@ -44,25 +44,14 @@ open class MatterStorageImpl @JvmOverloads constructor(
override var storedMatter = Decimal.ZERO
private var handler = LazyOptional.of<IMatterStorage> { this }
fun invalidate() {
handler.invalidate()
}
fun revive() {
handler = LazyOptional.of { this }
}
fun get(): LazyOptional<IMatterStorage> {
return handler
}
open fun canReceiveAll(value: Decimal): Boolean {
return maxStoredMatter >= value && storedMatter + value <= maxStoredMatter
}
override fun receiveMatter(howMuch: Decimal, simulate: Boolean): Decimal {
if (!howMuch.isPositive)
return Decimal.ZERO
val new: Decimal
if (maxReceive == null) {
@ -82,6 +71,9 @@ open class MatterStorageImpl @JvmOverloads constructor(
}
override fun extractMatter(howMuch: Decimal, simulate: Boolean): Decimal {
if (!howMuch.isPositive)
return Decimal.ZERO
val new: Decimal
if (maxExtract == null) {