From c226a988c3f64a93581ee8df1f931cb80046b962 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Tue, 25 Jul 2023 19:39:10 +0700 Subject: [PATCH] Matter decomposer rebalanced values --- .../entity/matter/MatterBottlerBlockEntity.kt | 5 +- .../matter/MatterDecomposerBlockEntity.kt | 54 +++++----------- .../matter/MatterReconstructorBlockEntity.kt | 5 +- .../matter/MatterReplicatorBlockEntity.kt | 4 +- .../entity/matter/MatterScannerBlockEntity.kt | 4 +- .../block/entity/storage/StorageInterfaces.kt | 4 +- .../StoragePowerSupplierBlockEntity.kt | 4 +- .../energy/BlockEnergyStorageImpl.kt | 61 +++++++++---------- .../capability/matter/MatterStorageImpl.kt | 13 ++-- .../mc/otm/config/AbstractConfig.kt | 43 ++++++------- .../mc/otm/config/BalanceValues.kt | 23 +++---- .../mc/otm/config/MachinesConfig.kt | 31 ++++++---- .../mc/otm/container/UpgradeContainer.kt | 32 +++++----- .../ru/dbotthepony/mc/otm/item/BatteryItem.kt | 7 +-- .../mc/otm/item/QuantumBatteryItem.kt | 8 +-- .../mc/otm/item/SingleUseBatteryItem.kt | 5 +- 16 files changed, 137 insertions(+), 166 deletions(-) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterBottlerBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterBottlerBlockEntity.kt index 0cb9a6b8f..9b58cdd29 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterBottlerBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterBottlerBlockEntity.kt @@ -10,7 +10,7 @@ import net.minecraft.world.level.Level import net.minecraft.world.level.block.Block import net.minecraft.world.level.block.state.BlockState import net.minecraftforge.common.ForgeConfigSpec -import ru.dbotthepony.mc.otm.config.ConciseBalanceValues +import ru.dbotthepony.mc.otm.config.EnergyBalanceValues import ru.dbotthepony.mc.otm.block.matter.MatterBottlerBlock import ru.dbotthepony.mc.otm.block.entity.MatteryPoweredBlockEntity import ru.dbotthepony.mc.otm.block.entity.WorkerState @@ -33,7 +33,6 @@ import ru.dbotthepony.mc.otm.core.util.WriteOnce 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.MatterNode import ru.dbotthepony.mc.otm.graph.matter.SimpleMatterNode class MatterBottlerBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : @@ -294,7 +293,7 @@ class MatterBottlerBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : private var _EXTRACTION_TICKS: DecimalConfigValue by WriteOnce() private var _CAPACITY: DecimalConfigValue by WriteOnce() - var ENERGY_VALUES: ConciseBalanceValues by WriteOnce() + var ENERGY_VALUES: EnergyBalanceValues by WriteOnce() private set fun registerConfig(builder: ForgeConfigSpec.Builder) { diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterDecomposerBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterDecomposerBlockEntity.kt index 94af8254c..24fc3c4cf 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterDecomposerBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterDecomposerBlockEntity.kt @@ -3,7 +3,6 @@ package ru.dbotthepony.mc.otm.block.entity.matter import com.mojang.serialization.Codec import com.mojang.serialization.codecs.RecordCodecBuilder import net.minecraft.core.BlockPos -import net.minecraft.nbt.CompoundTag import net.minecraft.world.entity.player.Inventory import net.minecraft.world.entity.player.Player import net.minecraft.world.inventory.AbstractContainerMenu @@ -17,20 +16,20 @@ 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.BlockEnergyStorageImpl import ru.dbotthepony.mc.otm.capability.energy.ProfiledEnergyStorage import ru.dbotthepony.mc.otm.capability.energy.WorkerEnergyStorage import ru.dbotthepony.mc.otm.capability.matter.MatterStorageImpl import ru.dbotthepony.mc.otm.capability.matter.ProfiledMatterStorage -import ru.dbotthepony.mc.otm.config.ConciseBalanceValues +import ru.dbotthepony.mc.otm.config.EnergyBalanceValues +import ru.dbotthepony.mc.otm.config.MachinesConfig import ru.dbotthepony.mc.otm.container.HandlerFilter import ru.dbotthepony.mc.otm.container.MatteryContainer +import ru.dbotthepony.mc.otm.container.UpgradeContainer 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.core.math.getDecimal -import ru.dbotthepony.mc.otm.core.math.set -import ru.dbotthepony.mc.otm.core.nbt.set import ru.dbotthepony.mc.otm.core.util.WriteOnce import ru.dbotthepony.mc.otm.data.DecimalCodec import ru.dbotthepony.mc.otm.data.minRange @@ -103,7 +102,7 @@ class MatterDecomposerBlockEntity(pos: BlockPos, state: BlockState) val toDust: Boolean, var matterValue: Decimal, ticks: Double, - ) : Job(ticks, BASE_CONSUMPTION) { + ) : Job(ticks, MachinesConfig.MATTER_DECOMPOSER.powerConsumption) { companion object { val CODEC: Codec by lazy { RecordCodecBuilder.create { @@ -117,14 +116,15 @@ class MatterDecomposerBlockEntity(pos: BlockPos, state: BlockState) } } - val energy = ProfiledEnergyStorage(WorkerEnergyStorage(this, ENERGY_VALUES)) + override val upgrades = UpgradeContainer(this::setChangedLight, 4, UpgradeType.REPLICATOR) + val energy = ProfiledEnergyStorage(WorkerEnergyStorage(this, upgrades.transform(MachinesConfig.MATTER_DECOMPOSER))) val energyConfig = ConfigurableEnergy(energy) init { savetables.stateful(::energy, ENERGY_KEY) } - val matter = ProfiledMatterStorage(MatterStorageImpl(::setChangedLight, FlowDirection.OUTPUT, ::CAPACITY)) + val matter = ProfiledMatterStorage(MatterStorageImpl(::setChangedLight, FlowDirection.OUTPUT, upgrades.matterCapacity(MachinesConfig.MATTER_DECOMPOSER::matterCapacity))) val matterNode = SimpleMatterNode(matter = matter) init { @@ -185,7 +185,13 @@ class MatterDecomposerBlockEntity(pos: BlockPos, state: BlockState) val matter = MatterManager.get(copy) stack.count-- - return JobContainer.success(DecomposerJob((level?.random?.nextDouble() ?: 1.0) <= 0.2, matter.matter, matter.complexity)) + return JobContainer.success( + DecomposerJob( + (level?.random?.nextDouble() ?: 1.0) <= 0.2 * upgrades.failureMultiplier, + matter.matter, + matter.complexity * MachinesConfig.MATTER_DECOMPOSER.workTimeMultiplier + ) + ) } } @@ -205,36 +211,8 @@ class MatterDecomposerBlockEntity(pos: BlockPos, state: BlockState) override fun tick() { super.tick() - val grid = matterNode.graph as MatterGraph? ?: return - if (!matter.storedMatter.isZero) { - val diff = matter.extractMatter(matter.storedMatter, true) - val diff2 = grid.receiveMatter(diff, true) - - matter.extractMatter(diff2, false) - grid.receiveMatter(diff2, false) - } - } - - companion object { - val CAPACITY get() = _CAPACITY.get() - val BASE_CONSUMPTION get() = _BASE_CONSUMPTION.get() - - private var _CAPACITY: DecimalConfigValue by WriteOnce() - private var _BASE_CONSUMPTION: DecimalConfigValue by WriteOnce() - - var ENERGY_VALUES: ConciseBalanceValues by WriteOnce() - private set - - fun registerConfig(builder: ForgeConfigSpec.Builder) { - builder.push(MNames.MATTER_DECOMPOSER) - - ENERGY_VALUES = BlockEnergyStorageImpl.makeConfigEntry(builder, capacity = Decimal(400_000), throughput = Decimal(2_000)) - - _CAPACITY = builder.defineDecimal("matterCapacity", Decimal(500), Decimal.ONE_TENTH) - _BASE_CONSUMPTION = builder.defineDecimal("baseConsumption", Decimal(240), Decimal.ONE) - - builder.pop() + matter.extractMatter(matterNode.graph.receiveMatter(matter.storedMatter, false), false) } } } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterReconstructorBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterReconstructorBlockEntity.kt index 2cb36e21f..74976f0ba 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterReconstructorBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterReconstructorBlockEntity.kt @@ -24,7 +24,7 @@ import ru.dbotthepony.mc.otm.capability.matter.IMatterStorage import ru.dbotthepony.mc.otm.capability.matter.IPatternState import ru.dbotthepony.mc.otm.capability.matter.MatterStorageImpl import ru.dbotthepony.mc.otm.capability.matter.ProfiledMatterStorage -import ru.dbotthepony.mc.otm.config.ConciseBalanceValues +import ru.dbotthepony.mc.otm.config.EnergyBalanceValues import ru.dbotthepony.mc.otm.container.HandlerFilter import ru.dbotthepony.mc.otm.container.MatteryContainer import ru.dbotthepony.mc.otm.container.UpgradeContainer @@ -33,7 +33,6 @@ import ru.dbotthepony.mc.otm.core.math.DecimalConfigValue import ru.dbotthepony.mc.otm.core.math.defineDecimal import ru.dbotthepony.mc.otm.core.registryName import ru.dbotthepony.mc.otm.core.util.WriteOnce -import ru.dbotthepony.mc.otm.graph.matter.MatterGraph import ru.dbotthepony.mc.otm.graph.matter.MatterNode import ru.dbotthepony.mc.otm.matter.IMatterValue import ru.dbotthepony.mc.otm.matter.MatterManager @@ -308,7 +307,7 @@ class MatterReconstructorBlockEntity(blockPos: BlockPos, blockState: BlockState) private var _ONLY_ANVIL: ConfigValue by WriteOnce() private var _ALLOW_TO_SKIP_ANVIL: ConfigValue by WriteOnce() - var ENERGY_VALUES: ConciseBalanceValues by WriteOnce() + var ENERGY_VALUES: EnergyBalanceValues by WriteOnce() private set fun registerConfig(builder: ForgeConfigSpec.Builder) { diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterReplicatorBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterReplicatorBlockEntity.kt index 73147dbc3..23ef6a790 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterReplicatorBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterReplicatorBlockEntity.kt @@ -22,7 +22,7 @@ import ru.dbotthepony.mc.otm.capability.energy.BlockEnergyStorageImpl import ru.dbotthepony.mc.otm.capability.energy.ProfiledEnergyStorage import ru.dbotthepony.mc.otm.capability.energy.WorkerEnergyStorage import ru.dbotthepony.mc.otm.capability.matter.* -import ru.dbotthepony.mc.otm.config.ConciseBalanceValues +import ru.dbotthepony.mc.otm.config.EnergyBalanceValues import ru.dbotthepony.mc.otm.container.HandlerFilter import ru.dbotthepony.mc.otm.container.MatteryContainer import ru.dbotthepony.mc.otm.container.UpgradeContainer @@ -213,7 +213,7 @@ class MatterReplicatorBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : private var _DRAIN_MULT: DecimalConfigValue by WriteOnce() private var _MATTER_CAPACITY: DecimalConfigValue by WriteOnce() - var ENERGY_VALUES: ConciseBalanceValues by WriteOnce() + var ENERGY_VALUES: EnergyBalanceValues by WriteOnce() private set fun registerConfig(builder: ForgeConfigSpec.Builder) { diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterScannerBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterScannerBlockEntity.kt index 683957405..577220d47 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterScannerBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterScannerBlockEntity.kt @@ -12,7 +12,7 @@ import ru.dbotthepony.mc.otm.block.entity.JobContainer import ru.dbotthepony.mc.otm.block.entity.JobStatus import ru.dbotthepony.mc.otm.block.entity.ItemJob import ru.dbotthepony.mc.otm.block.entity.MachineJobEventLoop -import ru.dbotthepony.mc.otm.config.ConciseBalanceValues +import ru.dbotthepony.mc.otm.config.EnergyBalanceValues import ru.dbotthepony.mc.otm.block.entity.MatteryWorkerBlockEntity import ru.dbotthepony.mc.otm.capability.energy.BlockEnergyStorageImpl import ru.dbotthepony.mc.otm.capability.MatteryCapability @@ -187,7 +187,7 @@ class MatterScannerBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : private val BASE_CONSUMPTION get() = _BASE_CONSUMPTION.get() private var _BASE_CONSUMPTION: DecimalConfigValue by WriteOnce() - var ENERGY_VALUES: ConciseBalanceValues by WriteOnce() + var ENERGY_VALUES: EnergyBalanceValues by WriteOnce() private set fun registerConfig(builder: ForgeConfigSpec.Builder) { diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/storage/StorageInterfaces.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/storage/StorageInterfaces.kt index a37b4b10e..547ece08f 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/storage/StorageInterfaces.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/storage/StorageInterfaces.kt @@ -21,7 +21,7 @@ import ru.dbotthepony.mc.otm.block.entity.MatteryPoweredBlockEntity import ru.dbotthepony.mc.otm.capability.MatteryCapability import ru.dbotthepony.mc.otm.capability.energy.WorkerEnergyStorage import ru.dbotthepony.mc.otm.capability.energy.extractEnergyExact -import ru.dbotthepony.mc.otm.config.ConciseBalanceValues +import ru.dbotthepony.mc.otm.config.EnergyBalanceValues import ru.dbotthepony.mc.otm.config.MachinesConfig import ru.dbotthepony.mc.otm.container.ItemFilter import ru.dbotthepony.mc.otm.core.TranslatableComponent @@ -48,7 +48,7 @@ abstract class AbstractStorageImportExport( blockType: BlockEntityType<*>, blockPos: BlockPos, blockState: BlockState, - energyValues: ConciseBalanceValues = MachinesConfig.STORAGE_INTERFACES + energyValues: EnergyBalanceValues = MachinesConfig.STORAGE_INTERFACES ) : MatteryPoweredBlockEntity(blockType, blockPos, blockState) { val energy = WorkerEnergyStorage(::setChangedLight, energyValues) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/storage/StoragePowerSupplierBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/storage/StoragePowerSupplierBlockEntity.kt index 61c395979..3545cbbb0 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/storage/StoragePowerSupplierBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/storage/StoragePowerSupplierBlockEntity.kt @@ -1,7 +1,6 @@ package ru.dbotthepony.mc.otm.block.entity.storage import net.minecraft.core.BlockPos -import net.minecraft.server.level.ServerLevel import net.minecraft.world.entity.player.Inventory import net.minecraft.world.entity.player.Player import net.minecraft.world.inventory.AbstractContainerMenu @@ -14,7 +13,6 @@ import ru.dbotthepony.mc.otm.capability.energy.transferChecked import ru.dbotthepony.mc.otm.config.MachinesConfig import ru.dbotthepony.mc.otm.core.math.Decimal import ru.dbotthepony.mc.otm.graph.storage.StorageNode -import ru.dbotthepony.mc.otm.graph.storage.StorageGraph import ru.dbotthepony.mc.otm.menu.storage.StoragePowerSupplierMenu import ru.dbotthepony.mc.otm.registry.MBlockEntities @@ -65,7 +63,7 @@ class StoragePowerSupplierBlockEntity(blockPos: BlockPos, blockState: BlockState var demand = Decimal.ZERO var i = 0 - val available = energy.batteryLevel.coerceAtMost(MachinesConfig.STORAGE_POWER_SUPPLIER.throughput) + val available = energy.batteryLevel.coerceAtMost(MachinesConfig.STORAGE_POWER_SUPPLIER.energyThroughput) for (demanding in cell.graph.powerDemandingNodes) { val received = demanding.receiveEnergy(available, true) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/capability/energy/BlockEnergyStorageImpl.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/capability/energy/BlockEnergyStorageImpl.kt index 4abaceb73..d86e4dd58 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/capability/energy/BlockEnergyStorageImpl.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/capability/energy/BlockEnergyStorageImpl.kt @@ -14,12 +14,11 @@ import net.minecraftforge.common.ForgeConfigSpec import net.minecraftforge.common.util.INBTSerializable import net.minecraftforge.common.util.LazyOptional import ru.dbotthepony.mc.otm.block.entity.MatteryBlockEntity -import ru.dbotthepony.mc.otm.config.ConciseBalanceValues -import ru.dbotthepony.mc.otm.config.VerboseBalanceValues +import ru.dbotthepony.mc.otm.config.EnergyBalanceValues +import ru.dbotthepony.mc.otm.config.VerboseEnergyBalanceValues import ru.dbotthepony.mc.otm.capability.FlowDirection import ru.dbotthepony.mc.otm.core.math.Decimal import ru.dbotthepony.mc.otm.core.math.defineDecimal -import ru.dbotthepony.mc.otm.core.nbt.map import ru.dbotthepony.mc.otm.core.nbt.mapPresent import ru.dbotthepony.mc.otm.core.nbt.set @@ -166,13 +165,13 @@ sealed class BlockEnergyStorageImpl( const val MAX_INPUT_KEY = "max_input" const val MAX_OUTPUT_KEY = "max_output" - fun makeConfigEntry(builder: ForgeConfigSpec.Builder, name: String? = null, capacity: Decimal = DEFAULT_MAX_CAPACITY, throughput: Decimal = DEFAULT_MAX_IO, configurator: ForgeConfigSpec.Builder.() -> Unit = {}): ConciseBalanceValues { + fun makeConfigEntry(builder: ForgeConfigSpec.Builder, name: String? = null, capacity: Decimal = DEFAULT_MAX_CAPACITY, throughput: Decimal = DEFAULT_MAX_IO, configurator: ForgeConfigSpec.Builder.() -> Unit = {}): EnergyBalanceValues { if (name != null) builder.push(name) - val obj = object : ConciseBalanceValues { - override val capacity: Decimal by builder.defineDecimal("capacity", capacity, Decimal.ONE) - override val throughput: Decimal by builder.defineDecimal("throughput", throughput, Decimal.ONE) + val obj = object : EnergyBalanceValues { + override val energyCapacity: Decimal by builder.defineDecimal("capacity", capacity, Decimal.ONE) + override val energyThroughput: Decimal by builder.defineDecimal("throughput", throughput, Decimal.ONE) } configurator.invoke(builder) @@ -199,23 +198,23 @@ open class WorkerEnergyStorage( constructor( listener: () -> Unit, - values: ConciseBalanceValues - ) : this(listener, values::capacity, values::throughput, values::throughput) + values: EnergyBalanceValues + ) : this(listener, values::energyCapacity, values::energyThroughput, values::energyThroughput) constructor( listener: BlockEntity, - values: ConciseBalanceValues - ) : this(listener::setChanged, values::capacity, values::throughput, values::throughput) + values: EnergyBalanceValues + ) : this(listener::setChanged, values::energyCapacity, values::energyThroughput, values::energyThroughput) constructor( listener: () -> Unit, - values: VerboseBalanceValues - ) : this(listener, values::capacity, values::receive, values::extract) + values: VerboseEnergyBalanceValues + ) : this(listener, values::energyCapacity, values::maxEnergyReceive, values::maxEnergyExtract) constructor( listener: BlockEntity, - values: VerboseBalanceValues - ) : this(listener::setChanged, values::capacity, values::receive, values::extract) + values: VerboseEnergyBalanceValues + ) : this(listener::setChanged, values::energyCapacity, values::maxEnergyReceive, values::maxEnergyExtract) constructor( listener: BlockEntity, @@ -251,23 +250,23 @@ open class GeneratorEnergyStorage( constructor( listener: () -> Unit, - values: ConciseBalanceValues - ) : this(listener, values::capacity, values::throughput, values::throughput) + values: EnergyBalanceValues + ) : this(listener, values::energyCapacity, values::energyThroughput, values::energyThroughput) constructor( listener: BlockEntity, - values: ConciseBalanceValues - ) : this(listener::setChanged, values::capacity, values::throughput, values::throughput) + values: EnergyBalanceValues + ) : this(listener::setChanged, values::energyCapacity, values::energyThroughput, values::energyThroughput) constructor( listener: () -> Unit, - values: VerboseBalanceValues - ) : this(listener, values::capacity, values::receive, values::extract) + values: VerboseEnergyBalanceValues + ) : this(listener, values::energyCapacity, values::maxEnergyReceive, values::maxEnergyExtract) constructor( listener: BlockEntity, - values: VerboseBalanceValues - ) : this(listener::setChanged, values::capacity, values::receive, values::extract) + values: VerboseEnergyBalanceValues + ) : this(listener::setChanged, values::energyCapacity, values::maxEnergyReceive, values::maxEnergyExtract) constructor( listener: BlockEntity, @@ -303,23 +302,23 @@ open class CapacitorEnergyStorage( constructor( listener: () -> Unit, - values: ConciseBalanceValues - ) : this(listener, values::capacity, values::throughput, values::throughput) + values: EnergyBalanceValues + ) : this(listener, values::energyCapacity, values::energyThroughput, values::energyThroughput) constructor( listener: BlockEntity, - values: ConciseBalanceValues - ) : this(listener::setChanged, values::capacity, values::throughput, values::throughput) + values: EnergyBalanceValues + ) : this(listener::setChanged, values::energyCapacity, values::energyThroughput, values::energyThroughput) constructor( listener: () -> Unit, - values: VerboseBalanceValues - ) : this(listener, values::capacity, values::receive, values::extract) + values: VerboseEnergyBalanceValues + ) : this(listener, values::energyCapacity, values::maxEnergyReceive, values::maxEnergyExtract) constructor( listener: BlockEntity, - values: VerboseBalanceValues - ) : this(listener::setChanged, values::capacity, values::receive, values::extract) + values: VerboseEnergyBalanceValues + ) : this(listener::setChanged, values::energyCapacity, values::maxEnergyReceive, values::maxEnergyExtract) constructor( listener: BlockEntity, diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/capability/matter/MatterStorageImpl.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/capability/matter/MatterStorageImpl.kt index 4b60d458f..f15c6780c 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/capability/matter/MatterStorageImpl.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/capability/matter/MatterStorageImpl.kt @@ -2,9 +2,8 @@ package ru.dbotthepony.mc.otm.capability.matter import net.minecraft.nbt.CompoundTag import net.minecraftforge.common.util.INBTSerializable -import net.minecraftforge.common.util.LazyOptional -import ru.dbotthepony.mc.otm.config.ConciseBalanceValues -import ru.dbotthepony.mc.otm.config.VerboseBalanceValues +import ru.dbotthepony.mc.otm.config.EnergyBalanceValues +import ru.dbotthepony.mc.otm.config.VerboseEnergyBalanceValues import ru.dbotthepony.mc.otm.capability.FlowDirection import ru.dbotthepony.mc.otm.core.math.Decimal import ru.dbotthepony.mc.otm.core.nbt.set @@ -27,14 +26,14 @@ open class MatterStorageImpl @JvmOverloads constructor( constructor( listener: Runnable?, direction: FlowDirection, - values: ConciseBalanceValues - ) : this(listener, direction, values::capacity, values::throughput, values::throughput) + values: EnergyBalanceValues + ) : this(listener, direction, values::energyCapacity, values::energyThroughput, values::energyThroughput) constructor( listener: Runnable?, direction: FlowDirection, - values: VerboseBalanceValues - ) : this(listener, direction, values::capacity, values::receive, values::extract) + values: VerboseEnergyBalanceValues + ) : this(listener, direction, values::energyCapacity, values::maxEnergyReceive, values::maxEnergyExtract) val maxReceive get() = maxReceiveSupplier.invoke() val maxExtract get() = maxExtractSupplier.invoke() 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 08e49467c..1214d2f30 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/config/AbstractConfig.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/config/AbstractConfig.kt @@ -15,27 +15,13 @@ abstract class AbstractConfig(private val configName: String, private val type: protected val builder = ForgeConfigSpec.Builder() private var registered = false - fun verboseValues(name: String, storage: Decimal, receive: Decimal, extract: Decimal = receive): VerboseBalanceValues { - builder.push(name) - - val obj = object : VerboseBalanceValues { - override val capacity: Decimal by builder.defineDecimal("capacity", storage, minimum = Decimal.ONE) - override val receive: Decimal by builder.defineDecimal("receive", receive, minimum = Decimal.ONE) - override val extract: Decimal by builder.defineDecimal("extract", extract, minimum = Decimal.ONE) - } - - builder.pop() - - return obj - } - fun batteryValues(name: String, storage: Decimal, receive: Decimal, extract: Decimal = receive, initialBatteryLevel: Decimal = Decimal.ZERO): BatteryBalanceValues { builder.push(name) val obj = object : BatteryBalanceValues { - override val capacity: Decimal by builder.defineDecimal("capacity", storage, minimum = Decimal.ONE) - override val receive: Decimal by builder.defineDecimal("receive", receive, minimum = Decimal.ONE) - override val extract: Decimal by builder.defineDecimal("extract", extract, minimum = Decimal.ONE) + override val energyCapacity: Decimal by builder.defineDecimal("capacity", storage, minimum = Decimal.ONE) + override val maxEnergyReceive: Decimal by builder.defineDecimal("receive", receive, minimum = Decimal.ONE) + override val maxEnergyExtract: Decimal by builder.defineDecimal("extract", extract, minimum = Decimal.ONE) override val initialBatteryLevel: Decimal by builder.defineDecimal("initialBatteryLevel", initialBatteryLevel, minimum = Decimal.ZERO) } @@ -44,12 +30,12 @@ abstract class AbstractConfig(private val configName: String, private val type: return obj } - fun conciseValues(name: String, storage: Decimal, throughput: Decimal, configurator: ForgeConfigSpec.Builder.() -> Unit = {}): ConciseBalanceValues { + fun conciseValues(name: String, storage: Decimal, throughput: Decimal, configurator: ForgeConfigSpec.Builder.() -> Unit = {}): EnergyBalanceValues { builder.push(name) - val obj = object : ConciseBalanceValues { - override val capacity: Decimal by builder.defineDecimal("capacity", storage, minimum = Decimal.ONE) - override val throughput: Decimal by builder.defineDecimal("throughput", throughput, minimum = Decimal.ONE) + val obj = object : EnergyBalanceValues { + override val energyCapacity: Decimal by builder.defineDecimal("capacity", storage, minimum = Decimal.ONE) + override val energyThroughput: Decimal by builder.defineDecimal("throughput", throughput, minimum = Decimal.ONE) } configurator.invoke(builder) @@ -58,13 +44,22 @@ abstract class AbstractConfig(private val configName: String, private val type: return obj } - fun workerValues(name: String, storage: Decimal, throughput: Decimal, workTimeMultiplier: Double? = 1.0, powerConsumption: Decimal, configurator: ForgeConfigSpec.Builder.() -> Unit = {}): WorkerBalanceValues { + fun workerValues( + name: String, + energyStorage: Decimal, + energyThroughput: Decimal, + workTimeMultiplier: Double? = 1.0, + powerConsumption: Decimal, + matterCapacity: Decimal? = null, + configurator: ForgeConfigSpec.Builder.() -> Unit = {} + ): WorkerBalanceValues { builder.push(name) val obj = object : WorkerBalanceValues { - override val capacity: Decimal by builder.defineDecimal("capacity", storage, minimum = Decimal.ONE) - override val throughput: Decimal by builder.defineDecimal("throughput", throughput, minimum = Decimal.ONE) + override val energyCapacity: Decimal by builder.defineDecimal("capacity", energyStorage, minimum = Decimal.ONE) + override val energyThroughput: Decimal by builder.defineDecimal("throughput", energyThroughput, minimum = Decimal.ONE) override val powerConsumption: Decimal by builder.defineDecimal("powerConsumption", powerConsumption, minimum = Decimal.ONE) + override val matterCapacity: Decimal by (if (matterCapacity == null) GetterSetter.box(Decimal.ZERO) else builder.defineDecimal("matterCapacity", matterCapacity, minimum = Decimal.ONE)) override val workTimeMultiplier: Double by (if (workTimeMultiplier == null) GetterSetter.box(1.0) else builder.defineInRange("workTimeMultiplier", workTimeMultiplier, 0.0)) } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/config/BalanceValues.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/config/BalanceValues.kt index 5a7ed0fbc..6ff056147 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/config/BalanceValues.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/config/BalanceValues.kt @@ -2,22 +2,23 @@ package ru.dbotthepony.mc.otm.config import ru.dbotthepony.mc.otm.core.math.Decimal -interface ConciseBalanceValues { - val capacity: Decimal - val throughput: Decimal +interface EnergyBalanceValues { + val energyCapacity: Decimal + val energyThroughput: Decimal } -interface WorkerBalanceValues : ConciseBalanceValues { +interface WorkerBalanceValues : EnergyBalanceValues { val workTimeMultiplier: Double val powerConsumption: Decimal + val matterCapacity: Decimal } -interface BatteryBalanceValues : VerboseBalanceValues { +interface VerboseEnergyBalanceValues { + val energyCapacity: Decimal + val maxEnergyReceive: Decimal + val maxEnergyExtract: Decimal +} + +interface BatteryBalanceValues : VerboseEnergyBalanceValues { val initialBatteryLevel: Decimal } - -interface VerboseBalanceValues { - val capacity: Decimal - val receive: Decimal - val extract: Decimal -} 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 37e82edf8..cb9e1c4d7 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/config/MachinesConfig.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/config/MachinesConfig.kt @@ -1,10 +1,8 @@ package ru.dbotthepony.mc.otm.config -import net.minecraftforge.common.ForgeConfigSpec.ConfigValue import ru.dbotthepony.mc.otm.block.entity.matter.MatterReconstructorBlockEntity import ru.dbotthepony.mc.otm.block.entity.matter.MatterBottlerBlockEntity import ru.dbotthepony.mc.otm.block.entity.matter.MatterDecomposerBlockEntity -import ru.dbotthepony.mc.otm.block.entity.matter.MatterRecyclerBlockEntity import ru.dbotthepony.mc.otm.block.entity.matter.MatterReplicatorBlockEntity import ru.dbotthepony.mc.otm.block.entity.matter.MatterScannerBlockEntity import ru.dbotthepony.mc.otm.block.entity.tech.AndroidStationBlockEntity @@ -23,17 +21,24 @@ object MachinesConfig : AbstractConfig("machines") { MatterBottlerBlockEntity.registerConfig(builder) MatterReplicatorBlockEntity.registerConfig(builder) MatterScannerBlockEntity.registerConfig(builder) - MatterDecomposerBlockEntity.registerConfig(builder) MatterReconstructorBlockEntity.registerConfig(builder) } val PLATE_PRESS = workerValues( MNames.PLATE_PRESS, - storage = Decimal(40_000), - throughput = Decimal(200), + energyStorage = Decimal(40_000), + energyThroughput = Decimal(200), powerConsumption = Decimal(15) ) + val MATTER_DECOMPOSER = workerValues( + MNames.MATTER_DECOMPOSER, + energyStorage = Decimal(100_000), + energyThroughput = Decimal(400), + powerConsumption = Decimal(240), + matterCapacity = Decimal(400), + ) + var MATTER_RECYCLER_MATTER_PER_TICK: DecimalConfigValue by WriteOnce() private set @@ -42,8 +47,8 @@ object MachinesConfig : AbstractConfig("machines") { val MATTER_RECYCLER = workerValues( MNames.MATTER_RECYCLER, - storage = Decimal(80_000), - throughput = Decimal(400), + energyStorage = Decimal(80_000), + energyThroughput = Decimal(400), powerConsumption = Decimal(100), workTimeMultiplier = null ) { @@ -71,24 +76,24 @@ object MachinesConfig : AbstractConfig("machines") { val POWERED_FURNACE = workerValues( "POWERED_FURNACE", - storage = Decimal(40_000), - throughput = Decimal(200), + energyStorage = Decimal(40_000), + energyThroughput = Decimal(200), powerConsumption = Decimal(20), workTimeMultiplier = 0.75 ) val POWERED_BLAST_FURNACE = workerValues( "POWERED_BLAST_FURNACE", - storage = Decimal(40_000), - throughput = Decimal(200), + energyStorage = Decimal(40_000), + energyThroughput = Decimal(200), powerConsumption = Decimal(20), workTimeMultiplier = 0.75 ) val POWERED_SMOKER = workerValues( "POWERED_SMOKER", - storage = Decimal(40_000), - throughput = Decimal(200), + energyStorage = Decimal(40_000), + energyThroughput = Decimal(200), powerConsumption = Decimal(10), workTimeMultiplier = 0.75 ) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/container/UpgradeContainer.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/container/UpgradeContainer.kt index 1a1be7d62..8a54d54a0 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/container/UpgradeContainer.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/container/UpgradeContainer.kt @@ -3,8 +3,8 @@ package ru.dbotthepony.mc.otm.container import ru.dbotthepony.mc.otm.capability.IMatteryUpgrade import ru.dbotthepony.mc.otm.capability.MatteryCapability import ru.dbotthepony.mc.otm.capability.UpgradeType -import ru.dbotthepony.mc.otm.config.ConciseBalanceValues -import ru.dbotthepony.mc.otm.config.VerboseBalanceValues +import ru.dbotthepony.mc.otm.config.EnergyBalanceValues +import ru.dbotthepony.mc.otm.config.VerboseEnergyBalanceValues import ru.dbotthepony.mc.otm.core.collect.filter import ru.dbotthepony.mc.otm.core.collect.map import ru.dbotthepony.mc.otm.core.collect.mapToDouble @@ -49,23 +49,23 @@ open class UpgradeContainer(slotCount: Int, open val allowedUpgrades: Set Decimal? = { null }, properties: Properties = Properties().stacksTo(1) ) : Item(properties) { - constructor(values: ConciseBalanceValues, properties: Properties = Properties().stacksTo(1)) : this(values::capacity, values::throughput, properties) + constructor(values: EnergyBalanceValues, properties: Properties = Properties().stacksTo(1)) : this(values::energyCapacity, values::energyThroughput, properties) constructor(storage: Decimal, throughput: Decimal? = null, properties: Properties = Properties().stacksTo(1)) : this({ storage }, { throughput }, properties) val capacity get() = _capacity.invoke()