diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/AndroidStationBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/AndroidStationBlockEntity.kt index a7550f5ac..4a918c9b1 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/AndroidStationBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/AndroidStationBlockEntity.kt @@ -16,6 +16,7 @@ import ru.dbotthepony.mc.otm.capability.MatteryCapability import ru.dbotthepony.mc.otm.capability.energy.ProfiledEnergyStorage import ru.dbotthepony.mc.otm.capability.energy.WorkerEnergyStorage import ru.dbotthepony.mc.otm.capability.moveEnergy +import ru.dbotthepony.mc.otm.config.MachinesConfig import ru.dbotthepony.mc.otm.core.math.Decimal import ru.dbotthepony.mc.otm.core.math.DecimalConfigValue import ru.dbotthepony.mc.otm.core.math.defineDecimal @@ -25,7 +26,6 @@ import ru.dbotthepony.mc.otm.registry.MBlockEntities import ru.dbotthepony.mc.otm.registry.MNames import ru.dbotthepony.mc.otm.core.util.WriteOnce -@Suppress("ObjectPropertyName") class AndroidStationBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : MatteryPoweredBlockEntity(MBlockEntities.ANDROID_STATION, p_155229_, p_155230_), MenuProvider { @@ -33,7 +33,7 @@ class AndroidStationBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : return AndroidStationMenu(containerID, inventory, this) } - val energy: ProfiledEnergyStorage = ProfiledEnergyStorage(object : WorkerEnergyStorage(this@AndroidStationBlockEntity::setChangedLight, ::CAPACITY, ::MAX_IO, { null }) { + val energy: ProfiledEnergyStorage = ProfiledEnergyStorage(object : WorkerEnergyStorage(::setChangedLight, MachinesConfig.AndroidStation.VALUES) { override fun extractEnergy(howMuch: Decimal, simulate: Boolean): Decimal { return super.extractEnergy(howMuch, simulate).also { if (!simulate && this.batteryLevel.isZero) { @@ -92,27 +92,4 @@ class AndroidStationBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : } } } - - companion object { - private var _CAPACITY: DecimalConfigValue by WriteOnce() - private var _MAX_IO: DecimalConfigValue by WriteOnce() - private var _ENERGY_PER_OPERATION: DecimalConfigValue by WriteOnce() - private var _ENERGY_PER_RESEARCH: DecimalConfigValue by WriteOnce() - - val CAPACITY get() = _CAPACITY.get() - val MAX_IO get() = _MAX_IO.get() - val ENERGY_PER_OPERATION get() = _ENERGY_PER_OPERATION.get() - val ENERGY_PER_RESEARCH get() = _ENERGY_PER_RESEARCH.get() - - fun registerConfig(builder: ForgeConfigSpec.Builder) { - builder.push(MNames.ANDROID_STATION) - - _CAPACITY = builder.defineDecimal("capacity", Decimal(100_000), Decimal.ONE) - _MAX_IO = builder.defineDecimal("throughput", Decimal.valueOf(2048), Decimal.ONE) - _ENERGY_PER_OPERATION = builder.comment("Swapping parts, etc").defineDecimal("energyPerOperation", Decimal.valueOf(2048), Decimal.ONE) - _ENERGY_PER_RESEARCH = builder.defineDecimal("energyPerResearch", Decimal.valueOf(16384), Decimal.ONE) - - builder.pop() - } - } } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/tech/AndroidStationScreen.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/tech/AndroidStationScreen.kt index 98f54410d..e1894af55 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/tech/AndroidStationScreen.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/tech/AndroidStationScreen.kt @@ -32,6 +32,7 @@ import ru.dbotthepony.mc.otm.client.screen.panels.slot.BatterySlotPanel import ru.dbotthepony.mc.otm.client.screen.panels.slot.EquipmentBatterySlotPanel import ru.dbotthepony.mc.otm.client.screen.panels.util.DraggableCanvasPanel import ru.dbotthepony.mc.otm.client.screen.widget.WideProfiledPowerGaugePanel +import ru.dbotthepony.mc.otm.config.MachinesConfig import ru.dbotthepony.mc.otm.core.math.RGBAColor import ru.dbotthepony.mc.otm.core.ifPresentK import ru.dbotthepony.mc.otm.menu.tech.AndroidStationMenu @@ -384,7 +385,7 @@ private class AndroidResearchButton( override fun mouseClickedInner(x: Double, y: Double, button: Int): Boolean { if (button == InputConstants.MOUSE_BUTTON_LEFT && minecraft.player?.isSpectator != true) { - if (node.canResearch && !node.isResearched && (parent?.screen as AndroidStationScreen).menu.energyWidget.level >= AndroidStationBlockEntity.ENERGY_PER_RESEARCH) { + if (node.canResearch && !node.isResearched && (parent?.screen as AndroidStationScreen).menu.energyWidget.level >= MachinesConfig.AndroidStation.ENERGY_PER_RESEARCH) { if (node.type.flatBlocking.isNotEmpty()) { queryUser( TranslatableComponent("otm.android_station.research.confirm", node.type.displayName), @@ -411,7 +412,7 @@ private class AndroidResearchButton( if (isHovered) { val list = ArrayList().also { it.addAll(node.screenTooltipLines) } - val enoughPower = (parent?.screen as AndroidStationScreen).menu.energyWidget.level >= AndroidStationBlockEntity.ENERGY_PER_RESEARCH + val enoughPower = (parent?.screen as AndroidStationScreen).menu.energyWidget.level >= MachinesConfig.AndroidStation.ENERGY_PER_RESEARCH if (node.isResearched) { list.add(TranslatableComponent("otm.android_station.research.researched").withStyle(ChatFormatting.DARK_AQUA)) @@ -648,10 +649,10 @@ class AndroidStationScreen constructor(p_97741_: AndroidStationMenu, p_97742_: I } override fun innerRender(graphics: GuiGraphics, mouseX: Float, mouseY: Float, partialTick: Float) { - if (menu.energyWidget.level >= AndroidStationBlockEntity.ENERGY_PER_RESEARCH) { + if (menu.energyWidget.level >= MachinesConfig.AndroidStation.ENERGY_PER_RESEARCH) { text = POWER_OK color = RGBAColor.LIGHT_GREEN - } else if (menu.energyWidget.level >= AndroidStationBlockEntity.ENERGY_PER_OPERATION) { + } else if (menu.energyWidget.level >= MachinesConfig.AndroidStation.ENERGY_PER_OPERATION) { text = LOW_POWER_1 color = RGBAColor.DARK_RED } else { diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/config/AbstractConfig.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/config/AbstractConfig.kt index aee16436d..7cf624353 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/config/AbstractConfig.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/config/AbstractConfig.kt @@ -49,7 +49,7 @@ abstract class AbstractConfig(private val configName: String, private val type: energyStorage: Decimal, energyThroughput: Decimal, workTimeMultiplier: Double? = 1.0, - energyConsumption: Decimal, + energyConsumption: Decimal?, matterCapacity: Decimal? = null, configurator: ForgeConfigSpec.Builder.() -> Unit = {} ): WorkerBalanceValues { @@ -58,7 +58,7 @@ abstract class AbstractConfig(private val configName: String, private val type: val obj = object : WorkerBalanceValues { override val energyCapacity: Decimal by builder.defineDecimal("ENERGY_CAPACITY", energyStorage, minimum = Decimal.ONE) override val energyThroughput: Decimal by builder.defineDecimal("ENERGY_THROUGHPUT", energyThroughput, minimum = Decimal.ONE) - override val energyConsumption: Decimal by builder.defineDecimal("ENERGY_CONSUMPTION", energyConsumption, minimum = Decimal.ONE) + override val energyConsumption: Decimal by (if (energyConsumption == null) GetterSetter.box(Decimal.ZERO) else builder.defineDecimal("ENERGY_CONSUMPTION", energyConsumption, minimum = Decimal.ONE)) override val matterCapacity: Decimal by (if (matterCapacity == null) GetterSetter.box(Decimal.ZERO) else builder.defineDecimal("MATTER_CAPACITY", matterCapacity, minimum = Decimal.ONE)) override val workTimeMultiplier: Double by (if (workTimeMultiplier == null) GetterSetter.box(1.0) else builder.defineInRange("WORK_TIME_MULTIPLIER", workTimeMultiplier, 0.0)) } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/config/MachinesConfig.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/config/MachinesConfig.kt index 75a167d7c..6a505862e 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/config/MachinesConfig.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/config/MachinesConfig.kt @@ -1,17 +1,11 @@ package ru.dbotthepony.mc.otm.config -import ru.dbotthepony.mc.otm.block.entity.tech.AndroidStationBlockEntity -import ru.dbotthepony.mc.otm.block.entity.tech.ChemicalGeneratorBlockEntity import ru.dbotthepony.mc.otm.capability.energy.BlockEnergyStorageImpl import ru.dbotthepony.mc.otm.core.math.Decimal import ru.dbotthepony.mc.otm.core.math.defineDecimal import ru.dbotthepony.mc.otm.registry.MNames object MachinesConfig : AbstractConfig("machines") { - init { - AndroidStationBlockEntity.registerConfig(builder) - } - val PLATE_PRESS = workerValues( MNames.PLATE_PRESS, energyStorage = Decimal(40_000), @@ -58,7 +52,8 @@ object MachinesConfig : AbstractConfig("machines") { energyStorage = Decimal(40_000), energyConsumption = Decimal(10), energyThroughput = Decimal(200), - matterCapacity = Decimal(400) + matterCapacity = Decimal(400), + workTimeMultiplier = null ) { MatterBottler } @@ -67,7 +62,8 @@ object MachinesConfig : AbstractConfig("machines") { MNames.CHEMICAL_GENERATOR, energyStorage = Decimal(24_000), energyThroughput = Decimal(160), - energyConsumption = Decimal(40) + energyConsumption = Decimal(40), + workTimeMultiplier = null ) { ChemicalGenerator } @@ -87,6 +83,22 @@ object MachinesConfig : AbstractConfig("machines") { val MATTER_PER_TICK by builder.defineDecimal("MATTER_PER_TICK", Decimal("0.5")) } + private val ANDROID_STATION = workerValues( + MNames.ANDROID_STATION, + energyStorage = Decimal(40_000), + energyThroughput = Decimal(8_000), + energyConsumption = null, + workTimeMultiplier = null, + ) { + AndroidStation + } + + object AndroidStation { + val VALUES by ::ANDROID_STATION + val ENERGY_PER_OPERATION by builder.comment("Swapping parts").defineDecimal("ENERGY_PER_OPERATION", Decimal(2_000), Decimal.ZERO) + val ENERGY_PER_RESEARCH by builder.comment("Researching android stuff").defineDecimal("ENERGY_PER_RESEARCH", Decimal(16_000), Decimal.ZERO) + } + private val MATTER_RECONSTRUCTOR = workerValues( MNames.MATTER_RECONSTRUCTOR, energyStorage = Decimal(100_000), diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/tech/AndroidStationMenu.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/tech/AndroidStationMenu.kt index e3203da1d..60caf7fcb 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/tech/AndroidStationMenu.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/tech/AndroidStationMenu.kt @@ -10,6 +10,7 @@ import net.minecraftforge.common.capabilities.ForgeCapabilities import ru.dbotthepony.mc.otm.block.entity.tech.AndroidStationBlockEntity import ru.dbotthepony.mc.otm.capability.MatteryPlayerCapability import ru.dbotthepony.mc.otm.capability.matteryPlayer +import ru.dbotthepony.mc.otm.config.MachinesConfig import ru.dbotthepony.mc.otm.menu.MatteryPoweredMenu import ru.dbotthepony.mc.otm.menu.MatterySlot import ru.dbotthepony.mc.otm.menu.input.EnergyConfigPlayerInput @@ -52,10 +53,10 @@ class AndroidStationMenu @JvmOverloads constructor( } override fun removeItem(p_18942_: Int, p_18943_: Int): ItemStack { - if (p_18942_ != 0 || energyWidget.level < AndroidStationBlockEntity.ENERGY_PER_OPERATION || item.isEmpty) + if (p_18942_ != 0 || energyWidget.level < MachinesConfig.AndroidStation.ENERGY_PER_OPERATION || item.isEmpty) return ItemStack.EMPTY - (tile as AndroidStationBlockEntity).energy.extractEnergy(AndroidStationBlockEntity.ENERGY_PER_OPERATION, false) + (tile as AndroidStationBlockEntity).energy.extractEnergy(MachinesConfig.AndroidStation.ENERGY_PER_OPERATION, false) return removeItemNoUpdate(p_18942_) } @@ -72,7 +73,7 @@ class AndroidStationMenu @JvmOverloads constructor( if (p_18944_ != 0) return - (tile as AndroidStationBlockEntity).energy.extractEnergy(AndroidStationBlockEntity.ENERGY_PER_OPERATION, false) + (tile as AndroidStationBlockEntity).energy.extractEnergy(MachinesConfig.AndroidStation.ENERGY_PER_OPERATION, false) item = p_18945_ } @@ -92,18 +93,18 @@ class AndroidStationMenu @JvmOverloads constructor( private inner class AndroidSlot(container: Container, private val condition: (ItemStack) -> Boolean) : MatterySlot(container, 0) { override fun mayPickup(player: Player): Boolean { if (tile is AndroidStationBlockEntity) { - return super.mayPickup(player) && tile.energy.batteryLevel >= AndroidStationBlockEntity.ENERGY_PER_OPERATION + return super.mayPickup(player) && tile.energy.batteryLevel >= MachinesConfig.AndroidStation.ENERGY_PER_OPERATION } - return super.mayPickup(player) && energyWidget.level >= AndroidStationBlockEntity.ENERGY_PER_OPERATION + return super.mayPickup(player) && energyWidget.level >= MachinesConfig.AndroidStation.ENERGY_PER_OPERATION } override fun mayPlace(itemStack: ItemStack): Boolean { if (tile is AndroidStationBlockEntity) { - return tile.energy.batteryLevel >= AndroidStationBlockEntity.ENERGY_PER_OPERATION && condition.invoke(itemStack) + return tile.energy.batteryLevel >= MachinesConfig.AndroidStation.ENERGY_PER_OPERATION && condition.invoke(itemStack) } - return energyWidget.level >= AndroidStationBlockEntity.ENERGY_PER_OPERATION && condition.invoke(itemStack) + return energyWidget.level >= MachinesConfig.AndroidStation.ENERGY_PER_OPERATION && condition.invoke(itemStack) } }