Merge branch 'master' into 1.19.4

This commit is contained in:
DBotThePony 2024-01-01 12:01:06 +07:00
commit 31268e33ef
Signed by: DBot
GPG Key ID: DCC23B5715498507
3 changed files with 26 additions and 8 deletions

View File

@ -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 {

View File

@ -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?> {
constructor(width: Int, height: Int) : this({}, width, height)
constructor(watcher: Runnable, width: Int, height: Int) : this(watcher, width, height, MatteryContainer(watcher, width * height))
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(MatteryContainer.EmptyListener, 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 {
return parent.serializeNBT()

View File

@ -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()