From 31cb9973d56d66e1628690e34b0792402604f1c2 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Wed, 19 Jul 2023 17:18:02 +0700 Subject: [PATCH] Shortcut when trying to receive/extract zero matter --- .../capability/matter/MatterStorageImpl.kt | 20 ++++++------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/capability/matter/MatterStorageImpl.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/capability/matter/MatterStorageImpl.kt index 72daab76b..4b60d458f 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/capability/matter/MatterStorageImpl.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/capability/matter/MatterStorageImpl.kt @@ -44,25 +44,14 @@ open class MatterStorageImpl @JvmOverloads constructor( override var storedMatter = Decimal.ZERO - private var handler = LazyOptional.of { this } - - fun invalidate() { - handler.invalidate() - } - - fun revive() { - handler = LazyOptional.of { this } - } - - fun get(): LazyOptional { - 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) {