Update Upgrade Container to use SlottedContainer
This commit is contained in:
parent
83d11d531d
commit
861b94a30a
@ -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
|
||||
|
@ -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)))
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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() {
|
||||
|
@ -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 {
|
||||
|
@ -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() {
|
||||
|
@ -84,7 +84,7 @@ sealed class AbstractPoweredFurnaceBlockEntity<P : AbstractCookingRecipe, S : Ma
|
||||
init {
|
||||
exposeGlobally(Capabilities.FluidHandler.BLOCK, experience)
|
||||
|
||||
savetables.stateful(::upgrades)
|
||||
savetables.stateful(upgrades::container, "upgrades")
|
||||
savetables.stateful(::energy)
|
||||
|
||||
savetables.stateful(::experience)
|
||||
|
@ -50,7 +50,7 @@ class PlatePressBlockEntity(
|
||||
savetables.stateful(::inputContainer)
|
||||
savetables.stateful(::outputContainer)
|
||||
savetables.stateful(::experience)
|
||||
savetables.stateful(::upgrades)
|
||||
savetables.stateful(upgrades::container, "upgrades")
|
||||
}
|
||||
|
||||
override fun createMenu(containerID: Int, inventory: Inventory, ply: Player): AbstractContainerMenu {
|
||||
|
@ -5,6 +5,7 @@ import ru.dbotthepony.mc.otm.capability.MatteryCapability
|
||||
import ru.dbotthepony.mc.otm.capability.UpgradeType
|
||||
import ru.dbotthepony.mc.otm.config.EnergyBalanceValues
|
||||
import ru.dbotthepony.mc.otm.config.VerboseEnergyBalanceValues
|
||||
import ru.dbotthepony.mc.otm.container.slotted.SlottedContainer
|
||||
import ru.dbotthepony.mc.otm.core.collect.map
|
||||
import ru.dbotthepony.mc.otm.core.collect.reduce
|
||||
import ru.dbotthepony.mc.otm.core.math.Decimal
|
||||
@ -16,32 +17,34 @@ class UpgradeContainer(
|
||||
val allowedUpgrades: Set<UpgradeType> = 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<UpgradeType>
|
||||
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
|
||||
|
@ -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<Boolean>
|
||||
@ -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(
|
||||
|
Loading…
Reference in New Issue
Block a user