diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/container/MatteryContainer.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/container/MatteryContainer.kt index 83dbf75de..7396cabc4 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/container/MatteryContainer.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/container/MatteryContainer.kt @@ -142,33 +142,31 @@ open class MatteryContainer(val watcher: Runnable, private val size: Int) : Cont return false } - protected var handler: MatteryContainerHandler? = null - fun handler( insert_validator: (slot: Int, stack: ItemStack) -> Boolean, extract_validator: (slot: Int, amount: Int, stack: ItemStack) -> Boolean ): MatteryContainerHandler { - return handler ?: MatteryContainerHandler(this, object : MatteryContainerFilter { + return MatteryContainerHandler(this, object : MatteryContainerFilter { override fun canInsert(slot: Int, stack: ItemStack) = insert_validator(slot, stack) override fun canExtract(slot: Int, amount: Int, stack: ItemStack) = extract_validator(slot, amount, stack) - }).also { handler = it } + }) } fun handler( filter: MatteryContainerFilter ): MatteryContainerHandler { - return handler ?: MatteryContainerHandler(this, filter).also { handler = it } + return MatteryContainerHandler(this, filter) } fun handler(insert_validator: (Int, ItemStack) -> Boolean): MatteryContainerHandler { - return handler ?: MatteryContainerHandler(this, object : MatteryContainerFilter { + return MatteryContainerHandler(this, object : MatteryContainerFilter { override fun canInsert(slot: Int, stack: ItemStack) = insert_validator(slot, stack) override fun canExtract(slot: Int, amount: Int, stack: ItemStack) = false - }).also { handler = it } + }) } fun handler(): MatteryContainerHandler { - return handler ?: MatteryContainerHandler(this).also { handler = it } + return MatteryContainerHandler(this) } open fun getMaxStackSize(slot: Int) = maxStackSize