From 814328630cc74ea03858d8ee6819185f17cc197f Mon Sep 17 00:00:00 2001 From: YuRaNnNzZZ Date: Sun, 29 Oct 2023 00:42:48 +0300 Subject: [PATCH] fix upgrades not saving in matter decomposer and scanner; added upgrades to bottler and recycler --- .../entity/matter/MatterBottlerBlockEntity.kt | 10 +++++++--- .../entity/matter/MatterDecomposerBlockEntity.kt | 1 + .../entity/matter/MatterRecyclerBlockEntity.kt | 14 +++++++++----- .../entity/matter/MatterScannerBlockEntity.kt | 1 + 4 files changed, 18 insertions(+), 8 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 5b29c2dca..f01765e4a 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 @@ -15,6 +15,7 @@ import ru.dbotthepony.mc.otm.block.entity.WorkerState import ru.dbotthepony.mc.otm.capability.FlowDirection import ru.dbotthepony.mc.otm.capability.MatteryCapability import ru.dbotthepony.mc.otm.capability.ProxiedItemHandler +import ru.dbotthepony.mc.otm.capability.UpgradeType import ru.dbotthepony.mc.otm.capability.energy.ProfiledEnergyStorage import ru.dbotthepony.mc.otm.capability.energy.WorkerEnergyStorage import ru.dbotthepony.mc.otm.capability.matter.MatterStorageImpl @@ -22,6 +23,7 @@ import ru.dbotthepony.mc.otm.capability.matter.ProfiledMatterStorage import ru.dbotthepony.mc.otm.config.MachinesConfig import ru.dbotthepony.mc.otm.container.MatteryContainer import ru.dbotthepony.mc.otm.container.HandlerFilter +import ru.dbotthepony.mc.otm.container.UpgradeContainer import ru.dbotthepony.mc.otm.menu.matter.MatterBottlerMenu import ru.dbotthepony.mc.otm.registry.MBlockEntities import ru.dbotthepony.mc.otm.core.* @@ -31,7 +33,8 @@ import ru.dbotthepony.mc.otm.graph.matter.SimpleMatterNode class MatterBottlerBlockEntity(blockPos: BlockPos, blockState: BlockState) : MatteryPoweredBlockEntity(MBlockEntities.MATTER_BOTTLER, blockPos, blockState) { - override val energy = ProfiledEnergyStorage(WorkerEnergyStorage(this::markDirtyFast, MachinesConfig.MatterBottler.VALUES)) + val upgrades = UpgradeContainer(::markDirtyFast, 3, UpgradeType.BASIC_MATTER) + override val energy = ProfiledEnergyStorage(WorkerEnergyStorage(this::markDirtyFast, upgrades.transform(MachinesConfig.MatterBottler.VALUES))) val energyConfig = ConfigurableEnergy(energy) private inner class Container : MatteryContainer(3) { @@ -97,7 +100,7 @@ class MatterBottlerBlockEntity(blockPos: BlockPos, blockState: BlockState) : battery = batteryItemHandler ) - val matter: ProfiledMatterStorage = ProfiledMatterStorage(object : MatterStorageImpl(this::markDirtyFast, FlowDirection.BI_DIRECTIONAL, MachinesConfig.MatterBottler.VALUES::matterCapacity) { + val matter: ProfiledMatterStorage = ProfiledMatterStorage(object : MatterStorageImpl(this::markDirtyFast, FlowDirection.BI_DIRECTIONAL, upgrades.matterCapacity(MachinesConfig.MatterBottler.VALUES::matterCapacity)) { override val matterFlow: FlowDirection get() { return if (this@MatterBottlerBlockEntity.isBottling) FlowDirection.INPUT else FlowDirection.OUTPUT } @@ -115,6 +118,7 @@ class MatterBottlerBlockEntity(blockPos: BlockPos, blockState: BlockState) : savetable(::matter, MATTER_STORAGE_KEY) savetable(::bottling) savetable(::unbottling) + savetable(::upgrades) } var workProgress: Float = 0f @@ -193,7 +197,7 @@ class MatterBottlerBlockEntity(blockPos: BlockPos, blockState: BlockState) : } else { any = true initialCapacity = initialCapacity ?: it.storedMatter - val rate = MachinesConfig.MatterBottler.RATE + val rate = MachinesConfig.MatterBottler.RATE * (1.0 + upgrades.speedBonus) if (matter.storedMatter < rate) { matter.receiveMatter(matterNode.graph.extractMatter(matter.missingMatter 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 4e93fe6be..d454e94b3 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 @@ -60,6 +60,7 @@ class MatterDecomposerBlockEntity(pos: BlockPos, state: BlockState) init { savetables.stateful(::energy, ENERGY_KEY) + savetables.stateful(::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/MatterRecyclerBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterRecyclerBlockEntity.kt index 7bf692a9d..1602236fb 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 @@ -15,6 +15,7 @@ import ru.dbotthepony.mc.otm.block.entity.Job import ru.dbotthepony.mc.otm.block.entity.MatteryWorkerBlockEntity import ru.dbotthepony.mc.otm.capability.FlowDirection import ru.dbotthepony.mc.otm.capability.MatteryCapability +import ru.dbotthepony.mc.otm.capability.UpgradeType import ru.dbotthepony.mc.otm.capability.energy.ProfiledEnergyStorage import ru.dbotthepony.mc.otm.capability.energy.WorkerEnergyStorage import ru.dbotthepony.mc.otm.capability.matter.MatterStorageImpl @@ -22,6 +23,7 @@ import ru.dbotthepony.mc.otm.capability.matter.ProfiledMatterStorage import ru.dbotthepony.mc.otm.config.MachinesConfig import ru.dbotthepony.mc.otm.container.MatteryContainer import ru.dbotthepony.mc.otm.container.HandlerFilter +import ru.dbotthepony.mc.otm.container.UpgradeContainer import ru.dbotthepony.mc.otm.core.math.Decimal import ru.dbotthepony.mc.otm.graph.matter.MatterGraph import ru.dbotthepony.mc.otm.item.matter.MatterDustItem @@ -44,11 +46,12 @@ class MatterRecyclerBlockEntity(blockPos: BlockPos, blockState: BlockState) } } - val matter = ProfiledMatterStorage(MatterStorageImpl(::matterLevelUpdated, FlowDirection.OUTPUT, MachinesConfig.MatterRecycler.VALUES::matterCapacity)) + override val upgrades = UpgradeContainer(this::markDirtyFast, 3, UpgradeType.BASIC_MATTER) + val matter = ProfiledMatterStorage(MatterStorageImpl(::matterLevelUpdated, FlowDirection.OUTPUT, upgrades.matterCapacity(MachinesConfig.MatterRecycler.VALUES::matterCapacity))) val container = MatteryContainer(::itemContainerUpdated, 1).also(::addDroppableContainer) val matterNode = SimpleMatterNode(matter = matter) - override val energy = ProfiledEnergyStorage(WorkerEnergyStorage(::energyLevelUpdated, MachinesConfig.MatterRecycler.VALUES)) + override val energy = ProfiledEnergyStorage(WorkerEnergyStorage(::energyLevelUpdated, upgrades.transform(MachinesConfig.MatterRecycler.VALUES))) val itemConfig = ConfigurableItemHandler(input = container.handler(object : HandlerFilter { override fun canInsert(slot: Int, stack: ItemStack): Boolean { @@ -69,6 +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) } override fun setRemoved() { @@ -117,8 +121,8 @@ class MatterRecyclerBlockEntity(blockPos: BlockPos, blockState: BlockState) return JobContainer.success( RecyclerJob( - (actualMatter / MachinesConfig.MatterRecycler.MATTER_PER_TICK).toDouble(), - MachinesConfig.MatterRecycler.VALUES.energyConsumption, + (actualMatter / (MachinesConfig.MatterRecycler.MATTER_PER_TICK * (1.0 + upgrades.speedBonus))).toDouble(), + MachinesConfig.MatterRecycler.VALUES.energyConsumption * (1.0 + upgrades.speedBonus), actualMatter ) ) @@ -126,7 +130,7 @@ class MatterRecyclerBlockEntity(blockPos: BlockPos, blockState: BlockState) override fun onJobTick(status: JobStatus, id: Int) { val job = status.job - val toReceive = job.totalMatter.coerceAtMost(MachinesConfig.MatterRecycler.MATTER_PER_TICK * status.ticksAdvanced) + val toReceive = job.totalMatter.coerceAtMost(MachinesConfig.MatterRecycler.MATTER_PER_TICK * status.ticksAdvanced * (1.0 + upgrades.speedBonus)) if (toReceive.isZero) return status.success() 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 bd758bf51..dc22e5692 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 @@ -66,6 +66,7 @@ class MatterScannerBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : savetables.stateful(::container, INVENTORY_KEY) savetables.stateful(::energy, ENERGY_KEY) + savetables.stateful(::upgrades) } override fun invalidateCaps() {