fix upgrades not saving in matter decomposer and scanner; added upgrades to bottler and recycler
This commit is contained in:
parent
0bf5ec5487
commit
814328630c
@ -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.FlowDirection
|
||||||
import ru.dbotthepony.mc.otm.capability.MatteryCapability
|
import ru.dbotthepony.mc.otm.capability.MatteryCapability
|
||||||
import ru.dbotthepony.mc.otm.capability.ProxiedItemHandler
|
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.ProfiledEnergyStorage
|
||||||
import ru.dbotthepony.mc.otm.capability.energy.WorkerEnergyStorage
|
import ru.dbotthepony.mc.otm.capability.energy.WorkerEnergyStorage
|
||||||
import ru.dbotthepony.mc.otm.capability.matter.MatterStorageImpl
|
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.config.MachinesConfig
|
||||||
import ru.dbotthepony.mc.otm.container.MatteryContainer
|
import ru.dbotthepony.mc.otm.container.MatteryContainer
|
||||||
import ru.dbotthepony.mc.otm.container.HandlerFilter
|
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.menu.matter.MatterBottlerMenu
|
||||||
import ru.dbotthepony.mc.otm.registry.MBlockEntities
|
import ru.dbotthepony.mc.otm.registry.MBlockEntities
|
||||||
import ru.dbotthepony.mc.otm.core.*
|
import ru.dbotthepony.mc.otm.core.*
|
||||||
@ -31,7 +33,8 @@ import ru.dbotthepony.mc.otm.graph.matter.SimpleMatterNode
|
|||||||
class MatterBottlerBlockEntity(blockPos: BlockPos, blockState: BlockState) :
|
class MatterBottlerBlockEntity(blockPos: BlockPos, blockState: BlockState) :
|
||||||
MatteryPoweredBlockEntity(MBlockEntities.MATTER_BOTTLER, blockPos, 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)
|
val energyConfig = ConfigurableEnergy(energy)
|
||||||
|
|
||||||
private inner class Container : MatteryContainer(3) {
|
private inner class Container : MatteryContainer(3) {
|
||||||
@ -97,7 +100,7 @@ class MatterBottlerBlockEntity(blockPos: BlockPos, blockState: BlockState) :
|
|||||||
battery = batteryItemHandler
|
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() {
|
override val matterFlow: FlowDirection get() {
|
||||||
return if (this@MatterBottlerBlockEntity.isBottling) FlowDirection.INPUT else FlowDirection.OUTPUT
|
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(::matter, MATTER_STORAGE_KEY)
|
||||||
savetable(::bottling)
|
savetable(::bottling)
|
||||||
savetable(::unbottling)
|
savetable(::unbottling)
|
||||||
|
savetable(::upgrades)
|
||||||
}
|
}
|
||||||
|
|
||||||
var workProgress: Float = 0f
|
var workProgress: Float = 0f
|
||||||
@ -193,7 +197,7 @@ class MatterBottlerBlockEntity(blockPos: BlockPos, blockState: BlockState) :
|
|||||||
} else {
|
} else {
|
||||||
any = true
|
any = true
|
||||||
initialCapacity = initialCapacity ?: it.storedMatter
|
initialCapacity = initialCapacity ?: it.storedMatter
|
||||||
val rate = MachinesConfig.MatterBottler.RATE
|
val rate = MachinesConfig.MatterBottler.RATE * (1.0 + upgrades.speedBonus)
|
||||||
|
|
||||||
if (matter.storedMatter < rate) {
|
if (matter.storedMatter < rate) {
|
||||||
matter.receiveMatter(matterNode.graph.extractMatter(matter.missingMatter
|
matter.receiveMatter(matterNode.graph.extractMatter(matter.missingMatter
|
||||||
|
@ -60,6 +60,7 @@ class MatterDecomposerBlockEntity(pos: BlockPos, state: BlockState)
|
|||||||
|
|
||||||
init {
|
init {
|
||||||
savetables.stateful(::energy, ENERGY_KEY)
|
savetables.stateful(::energy, ENERGY_KEY)
|
||||||
|
savetables.stateful(::upgrades)
|
||||||
}
|
}
|
||||||
|
|
||||||
val matter = ProfiledMatterStorage(MatterStorageImpl(::markDirtyFast, FlowDirection.OUTPUT, upgrades.matterCapacity(MachinesConfig.MATTER_DECOMPOSER::matterCapacity)))
|
val matter = ProfiledMatterStorage(MatterStorageImpl(::markDirtyFast, FlowDirection.OUTPUT, upgrades.matterCapacity(MachinesConfig.MATTER_DECOMPOSER::matterCapacity)))
|
||||||
|
@ -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.block.entity.MatteryWorkerBlockEntity
|
||||||
import ru.dbotthepony.mc.otm.capability.FlowDirection
|
import ru.dbotthepony.mc.otm.capability.FlowDirection
|
||||||
import ru.dbotthepony.mc.otm.capability.MatteryCapability
|
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.ProfiledEnergyStorage
|
||||||
import ru.dbotthepony.mc.otm.capability.energy.WorkerEnergyStorage
|
import ru.dbotthepony.mc.otm.capability.energy.WorkerEnergyStorage
|
||||||
import ru.dbotthepony.mc.otm.capability.matter.MatterStorageImpl
|
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.config.MachinesConfig
|
||||||
import ru.dbotthepony.mc.otm.container.MatteryContainer
|
import ru.dbotthepony.mc.otm.container.MatteryContainer
|
||||||
import ru.dbotthepony.mc.otm.container.HandlerFilter
|
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.core.math.Decimal
|
||||||
import ru.dbotthepony.mc.otm.graph.matter.MatterGraph
|
import ru.dbotthepony.mc.otm.graph.matter.MatterGraph
|
||||||
import ru.dbotthepony.mc.otm.item.matter.MatterDustItem
|
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 container = MatteryContainer(::itemContainerUpdated, 1).also(::addDroppableContainer)
|
||||||
|
|
||||||
val matterNode = SimpleMatterNode(matter = matter)
|
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 {
|
val itemConfig = ConfigurableItemHandler(input = container.handler(object : HandlerFilter {
|
||||||
override fun canInsert(slot: Int, stack: ItemStack): Boolean {
|
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(::energy, ENERGY_KEY)
|
||||||
savetables.stateful(::container, INVENTORY_KEY)
|
savetables.stateful(::container, INVENTORY_KEY)
|
||||||
savetables.stateful(::matter, MATTER_STORAGE_KEY)
|
savetables.stateful(::matter, MATTER_STORAGE_KEY)
|
||||||
|
savetables.stateful(::upgrades)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setRemoved() {
|
override fun setRemoved() {
|
||||||
@ -117,8 +121,8 @@ class MatterRecyclerBlockEntity(blockPos: BlockPos, blockState: BlockState)
|
|||||||
|
|
||||||
return JobContainer.success(
|
return JobContainer.success(
|
||||||
RecyclerJob(
|
RecyclerJob(
|
||||||
(actualMatter / MachinesConfig.MatterRecycler.MATTER_PER_TICK).toDouble(),
|
(actualMatter / (MachinesConfig.MatterRecycler.MATTER_PER_TICK * (1.0 + upgrades.speedBonus))).toDouble(),
|
||||||
MachinesConfig.MatterRecycler.VALUES.energyConsumption,
|
MachinesConfig.MatterRecycler.VALUES.energyConsumption * (1.0 + upgrades.speedBonus),
|
||||||
actualMatter
|
actualMatter
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@ -126,7 +130,7 @@ class MatterRecyclerBlockEntity(blockPos: BlockPos, blockState: BlockState)
|
|||||||
|
|
||||||
override fun onJobTick(status: JobStatus<RecyclerJob>, id: Int) {
|
override fun onJobTick(status: JobStatus<RecyclerJob>, id: Int) {
|
||||||
val job = status.job
|
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)
|
if (toReceive.isZero)
|
||||||
return status.success()
|
return status.success()
|
||||||
|
@ -66,6 +66,7 @@ class MatterScannerBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) :
|
|||||||
|
|
||||||
savetables.stateful(::container, INVENTORY_KEY)
|
savetables.stateful(::container, INVENTORY_KEY)
|
||||||
savetables.stateful(::energy, ENERGY_KEY)
|
savetables.stateful(::energy, ENERGY_KEY)
|
||||||
|
savetables.stateful(::upgrades)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun invalidateCaps() {
|
override fun invalidateCaps() {
|
||||||
|
Loading…
Reference in New Issue
Block a user