From 861b94a30a84f08af7d6778e6f6b53bb658e0c47 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Wed, 5 Mar 2025 15:30:13 +0700 Subject: [PATCH] Update Upgrade Container to use SlottedContainer --- .../entity/matter/MatterBottlerBlockEntity.kt | 2 +- .../matter/MatterDecomposerBlockEntity.kt | 2 +- .../matter/MatterEntanglerBlockEntity.kt | 2 +- .../matter/MatterReconstructorBlockEntity.kt | 5 ++--- .../matter/MatterRecyclerBlockEntity.kt | 2 +- .../matter/MatterReplicatorBlockEntity.kt | 2 +- .../entity/matter/MatterScannerBlockEntity.kt | 2 +- .../tech/AbstractPoweredFurnaceBlockEntity.kt | 2 +- .../entity/tech/PlatePressBlockEntity.kt | 2 +- .../mc/otm/container/UpgradeContainer.kt | 19 +++++++++++-------- .../ru/dbotthepony/mc/otm/menu/Slots.kt | 5 +++-- 11 files changed, 24 insertions(+), 21 deletions(-) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterBottlerBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterBottlerBlockEntity.kt index e9fe053a1..3bf343fd6 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterBottlerBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterBottlerBlockEntity.kt @@ -106,7 +106,7 @@ class MatterBottlerBlockEntity(blockPos: BlockPos, blockState: BlockState) : savetables.stateful(::matter, MATTER_STORAGE_KEY) savetables.stateful(::bottling) savetables.stateful(::unbottling) - savetables.stateful(::upgrades) + savetables.stateful(upgrades::container, "upgrades") } var workProgress: Float = 0f diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterDecomposerBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterDecomposerBlockEntity.kt index 8a7836f9e..bb70e2ca1 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterDecomposerBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterDecomposerBlockEntity.kt @@ -64,7 +64,7 @@ class MatterDecomposerBlockEntity(pos: BlockPos, state: BlockState) init { savetables.stateful(::energy, ENERGY_KEY) - savetables.stateful(::upgrades) + savetables.stateful(upgrades::container, "upgrades") } val matter = ProfiledMatterStorage(MatterStorageImpl(::markDirtyFast, FlowDirection.OUTPUT, upgrades.matterCapacity(MachinesConfig.MATTER_DECOMPOSER::matterCapacity))) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterEntanglerBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterEntanglerBlockEntity.kt index 82def3e57..9d4e37098 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterEntanglerBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterEntanglerBlockEntity.kt @@ -144,7 +144,7 @@ class MatterEntanglerBlockEntity(blockPos: BlockPos, blockState: BlockState) : M savetables.stateful(::energy, ENERGY_KEY) savetables.stateful(::matter, MATTER_STORAGE_KEY) - savetables.stateful(::upgrades) + savetables.stateful(upgrades::container, "upgrades") savetables.stateful(inputs::parent, "inputs") savetables.stateful(::output) savetables.stateful(::experience) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterReconstructorBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterReconstructorBlockEntity.kt index 2ce185aca..9a9a9bc87 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterReconstructorBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterReconstructorBlockEntity.kt @@ -37,8 +37,7 @@ import ru.dbotthepony.mc.otm.menu.matter.MatterReconstructorMenu import ru.dbotthepony.mc.otm.registry.game.MBlockEntities import java.util.function.BooleanSupplier -class MatterReconstructorBlockEntity(blockPos: BlockPos, blockState: BlockState) : MatteryPoweredBlockEntity( - MBlockEntities.MATTER_RECONSTRUCTOR, blockPos, blockState) { +class MatterReconstructorBlockEntity(blockPos: BlockPos, blockState: BlockState) : MatteryPoweredBlockEntity(MBlockEntities.MATTER_RECONSTRUCTOR, blockPos, blockState) { val repairContainer = MatteryContainer(::containerChanged, 1).also(::addDroppableContainer) private var matterPerTick = Decimal.ZERO @@ -86,7 +85,7 @@ class MatterReconstructorBlockEntity(blockPos: BlockPos, blockState: BlockState) savetables.stateful(::repairContainer) savetables.stateful(::matter) savetables.stateful(::energy) - savetables.stateful(::upgrades) + savetables.stateful(upgrades::container, "upgrades") savetables.decimal(::matterPerTick) savetables.double(::progressPerTick) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterRecyclerBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterRecyclerBlockEntity.kt index d8fe21afe..6f6616193 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterRecyclerBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterRecyclerBlockEntity.kt @@ -72,7 +72,7 @@ class MatterRecyclerBlockEntity(blockPos: BlockPos, blockState: BlockState) savetables.stateful(::energy, ENERGY_KEY) savetables.stateful(::container, INVENTORY_KEY) savetables.stateful(::matter, MATTER_STORAGE_KEY) - savetables.stateful(::upgrades) + savetables.stateful(upgrades::container, "upgrades") } override fun setRemoved() { diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterReplicatorBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterReplicatorBlockEntity.kt index ac9f9c181..e97ae3b62 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterReplicatorBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterReplicatorBlockEntity.kt @@ -103,7 +103,7 @@ class MatterReplicatorBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : savetables.stateful(::matter, MATTER_STORAGE_KEY) savetables.stateful(::outputContainer, INVENTORY_KEY) savetables.stateful(::dustContainer) - savetables.stateful(::upgrades) + savetables.stateful(upgrades::container, "upgrades") } override fun createMenu(containerID: Int, inventory: Inventory, ply: Player): AbstractContainerMenu { diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterScannerBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterScannerBlockEntity.kt index d57799340..15609ed92 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterScannerBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterScannerBlockEntity.kt @@ -68,7 +68,7 @@ class MatterScannerBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : savetables.stateful(::container, INVENTORY_KEY) savetables.stateful(::energy, ENERGY_KEY) - savetables.stateful(::upgrades) + savetables.stateful(upgrades::container, "upgrades") } override fun setRemoved() { diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/AbstractPoweredFurnaceBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/AbstractPoweredFurnaceBlockEntity.kt index 6defd22b6..beecf43c4 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/AbstractPoweredFurnaceBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/AbstractPoweredFurnaceBlockEntity.kt @@ -84,7 +84,7 @@ sealed class AbstractPoweredFurnaceBlockEntity

= UpgradeType.ALL, val shouldLockUpgradeSlots: BooleanSupplier = BooleanSupplier { false }, listener: Runnable = Runnable {} -) : MatteryContainer(listener, slotCount), IMatteryUpgrade { +) : IMatteryUpgrade { + val container = SlottedContainer.simple(slotCount, listener) + override val upgradeTypes: Set get() = setOf() private fun positiveDecimals(fn: (IMatteryUpgrade) -> Decimal, reducer: (Decimal, Decimal) -> Decimal): Decimal { - if (isEmpty) + if (container.isEmpty) return Decimal.ZERO - return iterator() + return container.iterator() .map { (it.getCapability(MatteryCapability.UPGRADE)?.let(fn) ?: Decimal.ZERO).moreThanZero() * it.count } .reduce(Decimal.ZERO, reducer) } private fun anyDecimals(fn: (IMatteryUpgrade) -> Decimal, reducer: (Decimal, Decimal) -> Decimal): Decimal { - if (isEmpty) + if (container.isEmpty) return Decimal.ZERO - return iterator() + return container.iterator() .map { (it.getCapability(MatteryCapability.UPGRADE)?.let(fn) ?: Decimal.ZERO) * it.count } .reduce(Decimal.ZERO, reducer) } override val speedBonus: Double - get() = iterator().map { (it.getCapability(MatteryCapability.UPGRADE)?.speedBonus ?: 0.0) * it.count }.reduce(0.0) { a, b -> a + b } + get() = container.iterator().map { (it.getCapability(MatteryCapability.UPGRADE)?.speedBonus ?: 0.0) * it.count }.reduce(0.0) { a, b -> a + b } override val processingItems: Int - get() = iterator().map { (it.getCapability(MatteryCapability.UPGRADE)?.processingItems ?: 0).coerceAtLeast(0) * it.count }.reduce(0) { a, b -> a + b } + get() = container.iterator().map { (it.getCapability(MatteryCapability.UPGRADE)?.processingItems ?: 0).coerceAtLeast(0) * it.count }.reduce(0) { a, b -> a + b } override val energyStorageFlat: Decimal get() = positiveDecimals(IMatteryUpgrade::energyStorageFlat, Decimal::plus) override val energyStorage: Decimal @@ -53,7 +56,7 @@ class UpgradeContainer( override val energyConsumed: Decimal get() = anyDecimals(IMatteryUpgrade::energyConsumed, Decimal::plus) override val failureMultiplier: Double - get() = iterator().map { (it.getCapability(MatteryCapability.UPGRADE)?.failureMultiplier ?: 1.0).coerceAtLeast(0.0).pow(it.count.toDouble()) }.reduce(1.0) { a, b -> a * b } + get() = container.iterator().map { (it.getCapability(MatteryCapability.UPGRADE)?.failureMultiplier ?: 1.0).coerceAtLeast(0.0).pow(it.count.toDouble()) }.reduce(1.0) { a, b -> a * b } override val energyThroughputFlat: Decimal get() = positiveDecimals(IMatteryUpgrade::energyThroughputFlat, Decimal::plus) override val energyThroughput: Decimal diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/Slots.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/Slots.kt index 35ae8b6b5..70711603d 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/Slots.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/Slots.kt @@ -22,6 +22,7 @@ import ru.dbotthepony.mc.otm.container.IFilteredContainerSlot import ru.dbotthepony.mc.otm.container.IMatteryContainer import ru.dbotthepony.mc.otm.container.ItemFilter import ru.dbotthepony.mc.otm.container.UpgradeContainer +import ru.dbotthepony.mc.otm.container.slotted.SlottedContainer import ru.dbotthepony.mc.otm.container.util.containerSlotOrNull import ru.dbotthepony.mc.otm.core.collect.ConditionalEnumSet import ru.dbotthepony.mc.otm.core.immutableList @@ -261,7 +262,7 @@ data class UpgradeSlots( fun MatteryMenu.makeUpgradeSlots(count: Int, container: UpgradeContainer?): UpgradeSlots { if (container != null) { - require(count == container.containerSize) { "Upgrade container size ${container.containerSize} does not match with provided size $count" } + require(count == container.container.containerSize) { "Upgrade container size ${container.container.containerSize} does not match with provided size $count" } } val shouldLockUpgradeSlots: Supplier @@ -283,7 +284,7 @@ fun MatteryMenu.makeUpgradeSlots(count: Int, container: UpgradeContainer?): Upgr allowedTypes[value] = BooleanSupplier { b.get() } } - val syncContainer = container ?: SimpleContainer(count) + val syncContainer = container?.container ?: SlottedContainer.simple(count) val isOpen = InstantBooleanInput(this) return UpgradeSlots(