Merge branch 'master' into 1.19.4
This commit is contained in:
commit
31268e33ef
@ -44,8 +44,17 @@ import java.util.stream.StreamSupport
|
|||||||
import kotlin.collections.ArrayList
|
import kotlin.collections.ArrayList
|
||||||
|
|
||||||
@Suppress("UNUSED")
|
@Suppress("UNUSED")
|
||||||
open class MatteryContainer(protected val watcher: Runnable, private val size: Int) : IMatteryContainer, INBTSerializable<Tag?>, StackedContentsCompatible {
|
open class MatteryContainer(var listener: ContainerListener, private val size: Int) : IMatteryContainer, INBTSerializable<Tag?>, StackedContentsCompatible {
|
||||||
constructor(size: Int) : this({}, size)
|
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 {
|
init {
|
||||||
require(size >= 0) { "Invalid container size $size" }
|
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) {
|
protected open fun setChanged(slot: Int, new: ItemStack, old: ItemStack) {
|
||||||
watcher.run()
|
listener.setChanged(slot, new, old)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun serializeNBT(): CompoundTag {
|
override fun serializeNBT(): CompoundTag {
|
||||||
|
@ -23,9 +23,18 @@ object DummyMenu : AbstractContainerMenu(null, 0) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// урод
|
// урод
|
||||||
open class MatteryCraftingContainer private constructor(watcher: Runnable, width: Int, height: Int, private val parent: MatteryContainer) : CraftingContainer(DummyMenu, width, height), IMatteryContainer by parent, INBTSerializable<CompoundTag?> {
|
open class MatteryCraftingContainer private constructor(private val listener: MatteryContainer.ContainerListener, width: Int, height: Int, private val parent: MatteryContainer) : CraftingContainer(DummyMenu, width, height), IMatteryContainer by parent, INBTSerializable<CompoundTag?> {
|
||||||
constructor(width: Int, height: Int) : this({}, width, height)
|
constructor(width: Int, height: Int) : this(MatteryContainer.EmptyListener, width, height)
|
||||||
constructor(watcher: Runnable, width: Int, height: Int) : this(watcher, width, height, MatteryContainer(watcher, width * height))
|
constructor(listener: () -> Unit, width: Int, height: Int) : this({ _, _, _ -> listener.invoke() }, width, height, MatteryContainer(width * height))
|
||||||
|
constructor(listener: MatteryContainer.ContainerListener, width: Int, height: Int) : this(listener, width, height, MatteryContainer(width * height))
|
||||||
|
|
||||||
|
init {
|
||||||
|
parent.listener = MatteryContainer.ContainerListener { slot, new, old -> this@MatteryCraftingContainer.setChanged(slot, new, old) }
|
||||||
|
}
|
||||||
|
|
||||||
|
protected open fun setChanged(slot: Int, new: ItemStack, old: ItemStack) {
|
||||||
|
listener.setChanged(slot, new, old)
|
||||||
|
}
|
||||||
|
|
||||||
override fun serializeNBT(): CompoundTag {
|
override fun serializeNBT(): CompoundTag {
|
||||||
return parent.serializeNBT()
|
return parent.serializeNBT()
|
||||||
|
@ -10,8 +10,8 @@ import ru.dbotthepony.mc.otm.core.collect.reduce
|
|||||||
import ru.dbotthepony.mc.otm.core.math.Decimal
|
import ru.dbotthepony.mc.otm.core.math.Decimal
|
||||||
import kotlin.math.pow
|
import kotlin.math.pow
|
||||||
|
|
||||||
open class UpgradeContainer(slotCount: Int, open val allowedUpgrades: Set<UpgradeType> = UpgradeType.ALL, watcher: Runnable = Runnable {}) : MatteryContainer(watcher, slotCount), IMatteryUpgrade {
|
open class UpgradeContainer(slotCount: Int, open val allowedUpgrades: Set<UpgradeType> = UpgradeType.ALL, listener: ContainerListener = EmptyListener) : MatteryContainer(listener, slotCount), IMatteryUpgrade {
|
||||||
constructor(watcher: Runnable, slotCount: Int, allowedUpgrades: Set<UpgradeType>) : this(slotCount, allowedUpgrades, watcher)
|
constructor(listener: () -> Unit, slotCount: Int, allowedUpgrades: Set<UpgradeType>) : this(slotCount, allowedUpgrades, { _, _, _ -> listener.invoke() })
|
||||||
|
|
||||||
final override val upgradeTypes: Set<UpgradeType>
|
final override val upgradeTypes: Set<UpgradeType>
|
||||||
get() = setOf()
|
get() = setOf()
|
||||||
|
Loading…
Reference in New Issue
Block a user