Merge branch 'master' into 1.20.1
This commit is contained in:
commit
86c426a504
@ -44,8 +44,17 @@ import java.util.stream.StreamSupport
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
@Suppress("UNUSED")
|
||||
open class MatteryContainer(protected val watcher: Runnable, private val size: Int) : IMatteryContainer, INBTSerializable<Tag?>, StackedContentsCompatible {
|
||||
constructor(size: Int) : this({}, size)
|
||||
open class MatteryContainer(var listener: ContainerListener, private val size: Int) : IMatteryContainer, INBTSerializable<Tag?>, StackedContentsCompatible {
|
||||
constructor(watcher: () -> Unit, size: Int) : this({ _, _, _ -> watcher.invoke() }, size)
|
||||
constructor(size: Int) : this(EmptyListener, size)
|
||||
|
||||
fun interface ContainerListener {
|
||||
fun setChanged(slot: Int, new: ItemStack, old: ItemStack)
|
||||
}
|
||||
|
||||
object EmptyListener : ContainerListener {
|
||||
override fun setChanged(slot: Int, new: ItemStack, old: ItemStack) {}
|
||||
}
|
||||
|
||||
init {
|
||||
require(size >= 0) { "Invalid container size $size" }
|
||||
@ -254,7 +263,7 @@ open class MatteryContainer(protected val watcher: Runnable, private val size: I
|
||||
}
|
||||
|
||||
protected open fun setChanged(slot: Int, new: ItemStack, old: ItemStack) {
|
||||
watcher.run()
|
||||
listener.setChanged(slot, new, old)
|
||||
}
|
||||
|
||||
override fun serializeNBT(): CompoundTag {
|
||||
|
@ -3,8 +3,10 @@ package ru.dbotthepony.mc.otm.container
|
||||
import net.minecraft.world.inventory.CraftingContainer
|
||||
import net.minecraft.world.item.ItemStack
|
||||
|
||||
open class MatteryCraftingContainer(watcher: Runnable, private val width: Int, private val height: Int) : MatteryContainer(watcher, width * height), CraftingContainer {
|
||||
constructor(width: Int, height: Int) : this({}, width, height)
|
||||
open class MatteryCraftingContainer(listener: ContainerListener, private val width: Int, private val height: Int) : MatteryContainer(listener, width * height), CraftingContainer {
|
||||
constructor(listener: () -> Unit, width: Int, height: Int) : this({ _, _, _ -> listener.invoke() }, width, height)
|
||||
constructor(width: Int, height: Int) : this(EmptyListener, width, height)
|
||||
|
||||
final override fun getWidth(): Int {
|
||||
return width
|
||||
}
|
||||
|
@ -10,8 +10,8 @@ import ru.dbotthepony.mc.otm.core.collect.reduce
|
||||
import ru.dbotthepony.mc.otm.core.math.Decimal
|
||||
import kotlin.math.pow
|
||||
|
||||
open class UpgradeContainer(slotCount: Int, open val allowedUpgrades: Set<UpgradeType> = UpgradeType.ALL, watcher: Runnable = Runnable {}) : MatteryContainer(watcher, slotCount), IMatteryUpgrade {
|
||||
constructor(watcher: Runnable, slotCount: Int, allowedUpgrades: Set<UpgradeType>) : this(slotCount, allowedUpgrades, watcher)
|
||||
open class UpgradeContainer(slotCount: Int, open val allowedUpgrades: Set<UpgradeType> = UpgradeType.ALL, listener: ContainerListener = EmptyListener) : MatteryContainer(listener, slotCount), IMatteryUpgrade {
|
||||
constructor(listener: () -> Unit, slotCount: Int, allowedUpgrades: Set<UpgradeType>) : this(slotCount, allowedUpgrades, { _, _, _ -> listener.invoke() })
|
||||
|
||||
final override val upgradeTypes: Set<UpgradeType>
|
||||
get() = setOf()
|
||||
|
Loading…
Reference in New Issue
Block a user