Redo chemical generator config values

This commit is contained in:
DBotThePony 2023-08-04 01:43:23 +07:00
parent cbb79c89b6
commit cef79cbe36
Signed by: DBot
GPG Key ID: DCC23B5715498507
2 changed files with 34 additions and 51 deletions

View File

@ -16,6 +16,7 @@ import ru.dbotthepony.mc.otm.block.entity.WorkerState
import ru.dbotthepony.mc.otm.capability.*
import ru.dbotthepony.mc.otm.capability.energy.GeneratorEnergyStorage
import ru.dbotthepony.mc.otm.capability.energy.ProfiledEnergyStorage
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.core.*
@ -40,7 +41,7 @@ class ChemicalGeneratorBlockEntity(pos: BlockPos, state: BlockState) : MatteryDe
val residueItemHandler = residueContainer.handler(HandlerFilter.OnlyOut)
val fuelItemHandler = fuelContainer.handler(HandlerFilter.ChemicalFuel)
val energy = ProfiledEnergyStorage(GeneratorEnergyStorage(::setChangedLight, CAPACITY, THROUGHPUT))
val energy = ProfiledEnergyStorage(GeneratorEnergyStorage(::setChangedLight, MachinesConfig.ChemicalGenerator.VALUES::energyCapacity, MachinesConfig.ChemicalGenerator.VALUES::energyThroughput))
val itemConfig = ConfigurableItemHandler(
input = fuelItemHandler,
@ -59,8 +60,8 @@ class ChemicalGeneratorBlockEntity(pos: BlockPos, state: BlockState) : MatteryDe
savetable(::residueContainer)
savetable(::fuelContainer)
savetables.int(::workTicks, WORK_TICKS_KEY)
savetables.int(::workTicksTotal, WORK_TICKS_TOTAL_KEY)
savetables.int(::workTicks)
savetables.int(::workTicksTotal)
}
override fun setChangedLight() {
@ -81,7 +82,7 @@ class ChemicalGeneratorBlockEntity(pos: BlockPos, state: BlockState) : MatteryDe
if (workTicks > 0) {
workTicks--
energy.receiveEnergy(GENERATION_SPEED, false)
energy.receiveEnergy(MachinesConfig.ChemicalGenerator.VALUES.energyConsumption, false)
if (workTicks == 0) {
workTicksTotal = 0
@ -97,61 +98,30 @@ class ChemicalGeneratorBlockEntity(pos: BlockPos, state: BlockState) : MatteryDe
if (workTicks == 0 && !redstoneControl.isBlockedByRedstone && checkFuelSlot) {
if (!fuelContainer[0].isEmpty) {
val ticks = ForgeHooks.getBurnTime(fuelContainer[0], null)
val residue = fuelContainer[0].item.getCraftingRemainingItem(fuelContainer[0].copy().also { it.count = 1 })
val canPutResidue = residue.isEmpty || residueContainer[0].isEmpty || ItemStack.isSameItemSameTags(residueContainer[0], residue) && residueContainer[0].count < residueContainer[0].maxStackSize
val ticks = ForgeHooks.getBurnTime(fuelContainer[0], null) / MachinesConfig.ChemicalGenerator.RATIO
if (canPutResidue && ticks >= 4 && (energy.batteryLevel < Decimal.ONE || GENERATION_SPEED * (ticks / 4) + energy.batteryLevel <= energy.maxBatteryLevel)) {
workTicksTotal = ticks / 4
workTicks = ticks / 4
fuelContainer[0].shrink(1)
if (!residue.isEmpty) {
if (residueContainer[0].isEmpty) {
residueContainer[0] = residue
} else {
residueContainer[0].count++
}
}
fuelContainer.setChanged(0)
if (
ticks > 0 &&
(energy.batteryLevel <= Decimal.ONE || MachinesConfig.ChemicalGenerator.VALUES.energyConsumption * ticks + energy.batteryLevel <= energy.maxBatteryLevel) &&
residueContainer.fullyAddItem(fuelContainer[0].item.getCraftingRemainingItem(fuelContainer[0].copyWithCount(1)))
) {
workTicksTotal = ticks
workTicks = workTicksTotal
fuelContainer.removeItem(0, 1)
}
}
checkFuelSlot = false
}
if (energy.batteryLevel.isZero) return
if (energy.batteryLevel.isPositive) {
val item = batteryContainer[0]
val item = batteryContainer[0]
if (!item.isEmpty) {
item.energy?.also {
moveEnergy(energy, it, THROUGHPUT, simulate = false)
if (!item.isEmpty) {
item.energy?.also {
moveEnergy(energy, it, MachinesConfig.ChemicalGenerator.VALUES.energyThroughput, simulate = false)
}
}
}
}
companion object {
private val THROUGHPUT get() = _THROUGHPUT.get()
private val GENERATION_SPEED get() = _GENERATION_SPEED.get()
private val CAPACITY get() = _CAPACITY.get()
private var _THROUGHPUT: DecimalConfigValue by WriteOnce()
private var _GENERATION_SPEED: DecimalConfigValue by WriteOnce()
private var _CAPACITY: DecimalConfigValue by WriteOnce()
fun registerConfig(builder: ForgeConfigSpec.Builder) {
builder.push(MNames.CHEMICAL_GENERATOR)
_THROUGHPUT = builder.defineDecimal("throughput", Decimal(160), Decimal.ONE)
_GENERATION_SPEED = builder.defineDecimal("generationSpeed", Decimal(40), Decimal.ONE)
_CAPACITY = builder.defineDecimal("capacity", Decimal(24_000), Decimal.ONE)
builder.pop()
}
const val WORK_TICKS_KEY = "workTicks"
const val WORK_TICKS_TOTAL_KEY = "workTicksTotal"
}
}

View File

@ -10,7 +10,6 @@ import ru.dbotthepony.mc.otm.registry.MNames
object MachinesConfig : AbstractConfig("machines") {
init {
AndroidStationBlockEntity.registerConfig(builder)
ChemicalGeneratorBlockEntity.registerConfig(builder)
}
val PLATE_PRESS = workerValues(
@ -64,6 +63,20 @@ object MachinesConfig : AbstractConfig("machines") {
MatterBottler
}
private val CHEMICAL_GENERATOR = workerValues(
MNames.CHEMICAL_GENERATOR,
energyStorage = Decimal(24_000),
energyThroughput = Decimal(160),
energyConsumption = Decimal(40)
) {
ChemicalGenerator
}
object ChemicalGenerator {
val VALUES by ::CHEMICAL_GENERATOR
val RATIO: Int by builder.comment("This amount of burn ticks result in 1 generation tick").defineInRange("RATIO", 4, 0)
}
object MatterBottler {
val VALUES by ::MATTER_BOTTLER
val RATE by builder.comment("Matter transferred per tick").defineDecimal("RATE", Decimal("2.0"), Decimal.ONE_TENTH)