fix upgrades not saving in matter decomposer and scanner; added upgrades to bottler and recycler

This commit is contained in:
YuRaNnNzZZ 2023-10-29 00:42:48 +03:00
parent 0bf5ec5487
commit 814328630c
Signed by: YuRaNnNzZZ
GPG Key ID: 5F71738C85A6006D
4 changed files with 18 additions and 8 deletions

View File

@ -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<MatterStorageImpl> = ProfiledMatterStorage(object : MatterStorageImpl(this::markDirtyFast, FlowDirection.BI_DIRECTIONAL, MachinesConfig.MatterBottler.VALUES::matterCapacity) {
val matter: ProfiledMatterStorage<MatterStorageImpl> = 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

View File

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

View File

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

View File

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