Rebalanced matter bottler values
This commit is contained in:
parent
c69fb5107c
commit
2614fd1f02
@ -9,36 +9,29 @@ import net.minecraft.world.item.ItemStack
|
|||||||
import net.minecraft.world.level.Level
|
import net.minecraft.world.level.Level
|
||||||
import net.minecraft.world.level.block.Block
|
import net.minecraft.world.level.block.Block
|
||||||
import net.minecraft.world.level.block.state.BlockState
|
import net.minecraft.world.level.block.state.BlockState
|
||||||
import net.minecraftforge.common.ForgeConfigSpec
|
|
||||||
import ru.dbotthepony.mc.otm.config.EnergyBalanceValues
|
|
||||||
import ru.dbotthepony.mc.otm.block.matter.MatterBottlerBlock
|
import ru.dbotthepony.mc.otm.block.matter.MatterBottlerBlock
|
||||||
import ru.dbotthepony.mc.otm.block.entity.MatteryPoweredBlockEntity
|
import ru.dbotthepony.mc.otm.block.entity.MatteryPoweredBlockEntity
|
||||||
import ru.dbotthepony.mc.otm.block.entity.WorkerState
|
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.energy.BlockEnergyStorageImpl
|
|
||||||
import ru.dbotthepony.mc.otm.capability.MatteryCapability
|
import ru.dbotthepony.mc.otm.capability.MatteryCapability
|
||||||
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.IMatterStorage
|
import ru.dbotthepony.mc.otm.capability.matter.IMatterStorage
|
||||||
import ru.dbotthepony.mc.otm.capability.matter.MatterStorageImpl
|
import ru.dbotthepony.mc.otm.capability.matter.MatterStorageImpl
|
||||||
import ru.dbotthepony.mc.otm.capability.matter.ProfiledMatterStorage
|
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.MatteryContainer
|
||||||
import ru.dbotthepony.mc.otm.container.HandlerFilter
|
import ru.dbotthepony.mc.otm.container.HandlerFilter
|
||||||
import ru.dbotthepony.mc.otm.graph.matter.MatterGraph
|
|
||||||
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.*
|
||||||
import ru.dbotthepony.mc.otm.registry.MNames
|
|
||||||
import ru.dbotthepony.mc.otm.core.util.WriteOnce
|
|
||||||
import ru.dbotthepony.mc.otm.core.math.Decimal
|
import ru.dbotthepony.mc.otm.core.math.Decimal
|
||||||
import ru.dbotthepony.mc.otm.core.math.DecimalConfigValue
|
|
||||||
import ru.dbotthepony.mc.otm.core.math.defineDecimal
|
|
||||||
import ru.dbotthepony.mc.otm.graph.matter.SimpleMatterNode
|
import ru.dbotthepony.mc.otm.graph.matter.SimpleMatterNode
|
||||||
|
|
||||||
class MatterBottlerBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) :
|
class MatterBottlerBlockEntity(blockPos: BlockPos, blockState: BlockState) :
|
||||||
MatteryPoweredBlockEntity(MBlockEntities.MATTER_BOTTLER, p_155229_, p_155230_) {
|
MatteryPoweredBlockEntity(MBlockEntities.MATTER_BOTTLER, blockPos, blockState) {
|
||||||
|
|
||||||
val energy = ProfiledEnergyStorage(WorkerEnergyStorage(this, ENERGY_VALUES))
|
val energy = ProfiledEnergyStorage(WorkerEnergyStorage(this, MachinesConfig.MatterBottler.VALUES))
|
||||||
|
|
||||||
var isBottling: Boolean = true
|
var isBottling: Boolean = true
|
||||||
set(value) {
|
set(value) {
|
||||||
@ -99,7 +92,7 @@ class MatterBottlerBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) :
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
val matter: ProfiledMatterStorage<MatterStorageImpl> = ProfiledMatterStorage(object : MatterStorageImpl(this::setChangedLight, FlowDirection.BI_DIRECTIONAL, ::CAPACITY) {
|
val matter: ProfiledMatterStorage<MatterStorageImpl> = ProfiledMatterStorage(object : MatterStorageImpl(this::setChangedLight, FlowDirection.BI_DIRECTIONAL, 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
|
||||||
}
|
}
|
||||||
@ -172,10 +165,10 @@ class MatterBottlerBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) :
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var work_stack: ItemStack? = null
|
var workStack: ItemStack? = null
|
||||||
var capability: IMatterStorage? = null
|
var capability: IMatterStorage? = null
|
||||||
val align = if (isBottling) 0 else 3
|
val align = if (isBottling) 0 else 3
|
||||||
var work_slot = -1
|
var workSlot = -1
|
||||||
val unexpectedDirection = if (isBottling) FlowDirection.OUTPUT else FlowDirection.INPUT
|
val unexpectedDirection = if (isBottling) FlowDirection.OUTPUT else FlowDirection.INPUT
|
||||||
|
|
||||||
for (i in align until align + 3) {
|
for (i in align until align + 3) {
|
||||||
@ -186,50 +179,52 @@ class MatterBottlerBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) :
|
|||||||
|
|
||||||
if (cap.matterFlow != unexpectedDirection) {
|
if (cap.matterFlow != unexpectedDirection) {
|
||||||
if (this.isBottling && cap.missingMatter > Decimal.ZERO || !this.isBottling && cap.storedMatter > Decimal.ZERO) {
|
if (this.isBottling && cap.missingMatter > Decimal.ZERO || !this.isBottling && cap.storedMatter > Decimal.ZERO) {
|
||||||
work_stack = itemStack
|
workStack = itemStack
|
||||||
capability = cap
|
capability = cap
|
||||||
work_slot = i
|
workSlot = i
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (work_stack == null) {
|
if (workStack == null) {
|
||||||
lastWorkStack = null
|
lastWorkStack = null
|
||||||
initialCapacity = null
|
initialCapacity = null
|
||||||
} else if (work_stack != lastWorkStack) {
|
} else if (workStack != lastWorkStack) {
|
||||||
lastWorkStack = work_stack
|
lastWorkStack = workStack
|
||||||
initialCapacity = capability!!.storedMatter
|
initialCapacity = capability!!.storedMatter
|
||||||
}
|
}
|
||||||
|
|
||||||
val graph = matterNode.graph as MatterGraph?
|
|
||||||
|
|
||||||
if (capability != null) {
|
if (capability != null) {
|
||||||
if (blockState.getValue(WorkerState.SEMI_WORKER_STATE) !== WorkerState.WORKING) {
|
if (blockState.getValue(WorkerState.SEMI_WORKER_STATE) !== WorkerState.WORKING) {
|
||||||
level?.setBlock(blockPos, blockState.setValue(WorkerState.SEMI_WORKER_STATE, WorkerState.WORKING), Block.UPDATE_CLIENTS)
|
level?.setBlock(blockPos, blockState.setValue(WorkerState.SEMI_WORKER_STATE, WorkerState.WORKING), Block.UPDATE_CLIENTS)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val rate = MachinesConfig.MatterBottler.RATE
|
||||||
|
val consumption = MachinesConfig.MatterBottler.VALUES.energyConsumption
|
||||||
|
|
||||||
if (isBottling) {
|
if (isBottling) {
|
||||||
if (matter.storedMatter < MATTER_EXCHANGE_RATE && graph != null) {
|
if (matter.storedMatter < rate) {
|
||||||
val extracted = graph.extractMatter(
|
val extracted = matterNode.graph.extractMatter(
|
||||||
matter.missingMatter.coerceAtMost(MATTER_EXCHANGE_RATE * EXTRACTION_TICKS).coerceAtMost(capability.missingMatter - matter.storedMatter), true
|
matter.missingMatter
|
||||||
)
|
.coerceAtMost(rate * 200)
|
||||||
|
.coerceAtMost(capability.missingMatter - matter.storedMatter), true)
|
||||||
|
|
||||||
if (extracted > Decimal.ZERO) {
|
if (extracted > Decimal.ZERO) {
|
||||||
val received = matter.receiveMatter(extracted, false)
|
val received = matter.receiveMatter(extracted, false)
|
||||||
graph.extractMatter(received, false)
|
matterNode.graph.extractMatter(received, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (matter.storedMatter > Decimal.ZERO) {
|
if (matter.storedMatter > Decimal.ZERO) {
|
||||||
val energyExtracted = energy.extractEnergy(ENERGY_CONSUMPTION, true)
|
val energyExtracted = energy.extractEnergy(consumption, true)
|
||||||
|
|
||||||
if (!energyExtracted.isZero) {
|
if (!energyExtracted.isZero) {
|
||||||
val matter = capability.receiveMatter(MATTER_EXCHANGE_RATE.coerceAtMost(matter.storedMatter) * energyExtracted / ENERGY_CONSUMPTION, true)
|
val matter = capability.receiveMatter(rate.coerceAtMost(matter.storedMatter) * energyExtracted / consumption, true)
|
||||||
|
|
||||||
if (!matter.isZero) {
|
if (!matter.isZero) {
|
||||||
energy.extractEnergy(ENERGY_CONSUMPTION * matter / MATTER_EXCHANGE_RATE, false)
|
energy.extractEnergy(consumption * matter / rate, false)
|
||||||
|
|
||||||
capability.receiveMatter(matter, false)
|
capability.receiveMatter(matter, false)
|
||||||
this.matter.extractMatter(matter, false)
|
this.matter.extractMatter(matter, false)
|
||||||
@ -237,8 +232,8 @@ class MatterBottlerBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) :
|
|||||||
if (capability.missingMatter.isZero) {
|
if (capability.missingMatter.isZero) {
|
||||||
for (i in 3..5) {
|
for (i in 3..5) {
|
||||||
if (container.getItem(i).isEmpty) {
|
if (container.getItem(i).isEmpty) {
|
||||||
container.setItem(work_slot, ItemStack.EMPTY)
|
container.setItem(workSlot, ItemStack.EMPTY)
|
||||||
container.setItem(i, work_stack!!)
|
container.setItem(i, workStack!!)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -247,13 +242,13 @@ class MatterBottlerBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
val energyExtracted = energy.extractEnergy(ENERGY_CONSUMPTION, true)
|
val energyExtracted = energy.extractEnergy(consumption, true)
|
||||||
|
|
||||||
if (!energyExtracted.isZero) {
|
if (!energyExtracted.isZero) {
|
||||||
val matter = capability.extractMatter(MATTER_EXCHANGE_RATE.coerceAtMost(matter.missingMatter) * energyExtracted / ENERGY_CONSUMPTION, true)
|
val matter = capability.extractMatter(rate.coerceAtMost(matter.missingMatter) * energyExtracted / consumption, true)
|
||||||
|
|
||||||
if (!matter.isZero) {
|
if (!matter.isZero) {
|
||||||
this.energy.extractEnergy(ENERGY_CONSUMPTION * matter / MATTER_EXCHANGE_RATE,false)
|
this.energy.extractEnergy(consumption * matter / rate, false)
|
||||||
|
|
||||||
capability.extractMatter(matter, false)
|
capability.extractMatter(matter, false)
|
||||||
this.matter.receiveMatter(matter, false)
|
this.matter.receiveMatter(matter, false)
|
||||||
@ -261,8 +256,8 @@ class MatterBottlerBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) :
|
|||||||
if (capability.storedMatter.isZero) {
|
if (capability.storedMatter.isZero) {
|
||||||
for (i in 2 downTo 0) {
|
for (i in 2 downTo 0) {
|
||||||
if (container.getItem(i).isEmpty) {
|
if (container.getItem(i).isEmpty) {
|
||||||
container.setItem(work_slot, ItemStack.EMPTY)
|
container.setItem(workSlot, ItemStack.EMPTY)
|
||||||
container.setItem(i, work_stack!!)
|
container.setItem(i, workStack!!)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -271,42 +266,14 @@ class MatterBottlerBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
level!!.setBlock(blockPos, blockState.setValue(WorkerState.SEMI_WORKER_STATE, WorkerState.IDLE), Block.UPDATE_CLIENTS)
|
level?.setBlock(blockPos, blockState.setValue(WorkerState.SEMI_WORKER_STATE, WorkerState.IDLE), Block.UPDATE_CLIENTS)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isBottling && !matter.storedMatter.isZero && graph != null) {
|
if (!isBottling && !matter.storedMatter.isZero) {
|
||||||
val diff = matter.extractMatter(matter.storedMatter, true)
|
val diff = matter.extractMatter(matter.storedMatter, true)
|
||||||
val diff2 = graph.receiveMatter(diff, true)
|
val diff2 = matterNode.graph.receiveMatter(diff, true)
|
||||||
matter.extractMatter(diff2, false)
|
matter.extractMatter(diff2, false)
|
||||||
graph.receiveMatter(diff2, false)
|
matterNode.graph.receiveMatter(diff2, false)
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
val MATTER_EXCHANGE_RATE get() = _MATTER_EXCHANGE_RATE.get()
|
|
||||||
val ENERGY_CONSUMPTION get() = _ENERGY_CONSUMPTION.get()
|
|
||||||
val EXTRACTION_TICKS get() = _EXTRACTION_TICKS.get()
|
|
||||||
val CAPACITY get() = _CAPACITY.get()
|
|
||||||
|
|
||||||
private var _MATTER_EXCHANGE_RATE: DecimalConfigValue by WriteOnce()
|
|
||||||
private var _ENERGY_CONSUMPTION: DecimalConfigValue by WriteOnce()
|
|
||||||
private var _EXTRACTION_TICKS: DecimalConfigValue by WriteOnce()
|
|
||||||
private var _CAPACITY: DecimalConfigValue by WriteOnce()
|
|
||||||
|
|
||||||
var ENERGY_VALUES: EnergyBalanceValues by WriteOnce()
|
|
||||||
private set
|
|
||||||
|
|
||||||
fun registerConfig(builder: ForgeConfigSpec.Builder) {
|
|
||||||
builder.push(MNames.MATTER_BOTTLER)
|
|
||||||
|
|
||||||
ENERGY_VALUES = BlockEnergyStorageImpl.makeConfigEntry(builder)
|
|
||||||
|
|
||||||
_MATTER_EXCHANGE_RATE = builder.defineDecimal("matterExchangeRate", Decimal("0.04"), Decimal("0.0001"))
|
|
||||||
_ENERGY_CONSUMPTION = builder.defineDecimal("energyConsumption", Decimal(20), Decimal.ONE)
|
|
||||||
_EXTRACTION_TICKS = builder.defineDecimal("extractionTicks", Decimal(200), Decimal.ONE)
|
|
||||||
_CAPACITY = builder.defineDecimal("matterCapacity", Decimal(4_000), Decimal.ONE_TENTH)
|
|
||||||
|
|
||||||
builder.pop()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package ru.dbotthepony.mc.otm.config
|
package ru.dbotthepony.mc.otm.config
|
||||||
|
|
||||||
import ru.dbotthepony.mc.otm.block.entity.matter.MatterBottlerBlockEntity
|
|
||||||
import ru.dbotthepony.mc.otm.block.entity.tech.AndroidStationBlockEntity
|
import ru.dbotthepony.mc.otm.block.entity.tech.AndroidStationBlockEntity
|
||||||
import ru.dbotthepony.mc.otm.block.entity.tech.ChemicalGeneratorBlockEntity
|
import ru.dbotthepony.mc.otm.block.entity.tech.ChemicalGeneratorBlockEntity
|
||||||
import ru.dbotthepony.mc.otm.capability.energy.BlockEnergyStorageImpl
|
import ru.dbotthepony.mc.otm.capability.energy.BlockEnergyStorageImpl
|
||||||
@ -12,7 +11,6 @@ object MachinesConfig : AbstractConfig("machines") {
|
|||||||
init {
|
init {
|
||||||
AndroidStationBlockEntity.registerConfig(builder)
|
AndroidStationBlockEntity.registerConfig(builder)
|
||||||
ChemicalGeneratorBlockEntity.registerConfig(builder)
|
ChemicalGeneratorBlockEntity.registerConfig(builder)
|
||||||
MatterBottlerBlockEntity.registerConfig(builder)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val PLATE_PRESS = workerValues(
|
val PLATE_PRESS = workerValues(
|
||||||
@ -56,6 +54,21 @@ object MachinesConfig : AbstractConfig("machines") {
|
|||||||
MatterRecycler
|
MatterRecycler
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val MATTER_BOTTLER = workerValues(
|
||||||
|
MNames.MATTER_BOTTLER,
|
||||||
|
energyStorage = Decimal(40_000),
|
||||||
|
energyConsumption = Decimal(10),
|
||||||
|
energyThroughput = Decimal(200),
|
||||||
|
matterCapacity = Decimal(400)
|
||||||
|
) {
|
||||||
|
MatterBottler
|
||||||
|
}
|
||||||
|
|
||||||
|
object MatterBottler {
|
||||||
|
val VALUES by ::MATTER_BOTTLER
|
||||||
|
val RATE by builder.comment("Matter transferred per tick").defineDecimal("RATE", Decimal("2.0"), Decimal.ONE_TENTH)
|
||||||
|
}
|
||||||
|
|
||||||
object MatterRecycler {
|
object MatterRecycler {
|
||||||
val VALUES by ::MATTER_RECYCLER
|
val VALUES by ::MATTER_RECYCLER
|
||||||
val MATTER_PER_TICK by builder.defineDecimal("MATTER_PER_TICK", Decimal("0.5"))
|
val MATTER_PER_TICK by builder.defineDecimal("MATTER_PER_TICK", Decimal("0.5"))
|
||||||
|
Loading…
Reference in New Issue
Block a user