Matter decomposer rebalanced values

This commit is contained in:
DBotThePony 2023-07-25 19:39:10 +07:00
parent 325ee5da2e
commit c226a988c3
Signed by: DBot
GPG Key ID: DCC23B5715498507
16 changed files with 137 additions and 166 deletions

View File

@ -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) {

View File

@ -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<DecomposerJob> 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)
}
}
}

View File

@ -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<Boolean> by WriteOnce()
private var _ALLOW_TO_SKIP_ANVIL: ConfigValue<Boolean> by WriteOnce()
var ENERGY_VALUES: ConciseBalanceValues by WriteOnce()
var ENERGY_VALUES: EnergyBalanceValues by WriteOnce()
private set
fun registerConfig(builder: ForgeConfigSpec.Builder) {

View File

@ -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) {

View File

@ -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) {

View File

@ -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<T>(
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)

View File

@ -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)

View File

@ -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,

View File

@ -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()

View File

@ -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))
}

View File

@ -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
}

View File

@ -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
)

View File

@ -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<Upgrad
override val energyThroughput: Decimal
get() = decimals(IMatteryUpgrade::energyThroughput, Decimal::plus)
fun transform(values: ConciseBalanceValues): ConciseBalanceValues {
return object : ConciseBalanceValues {
override val capacity: Decimal
get() = values.capacity * (energyStorage + Decimal.ONE) + energyStorageFlat
override val throughput: Decimal
get() = values.throughput * (energyThroughput + Decimal.ONE) + energyThroughputFlat
fun transform(values: EnergyBalanceValues): EnergyBalanceValues {
return object : EnergyBalanceValues {
override val energyCapacity: Decimal
get() = values.energyCapacity * (energyStorage + Decimal.ONE) + energyStorageFlat
override val energyThroughput: Decimal
get() = values.energyThroughput * (this@UpgradeContainer.energyThroughput + Decimal.ONE) + energyThroughputFlat
}
}
fun transform(values: VerboseBalanceValues): VerboseBalanceValues {
return object : VerboseBalanceValues {
override val capacity: Decimal
get() = values.capacity * (energyStorage + Decimal.ONE) + energyStorageFlat
override val receive: Decimal
get() = values.receive * (energyThroughput + Decimal.ONE) + energyThroughputFlat
override val extract: Decimal
get() = values.extract * (energyThroughput + Decimal.ONE) + energyThroughputFlat
fun transform(values: VerboseEnergyBalanceValues): VerboseEnergyBalanceValues {
return object : VerboseEnergyBalanceValues {
override val energyCapacity: Decimal
get() = values.energyCapacity * (energyStorage + Decimal.ONE) + energyStorageFlat
override val maxEnergyReceive: Decimal
get() = values.maxEnergyReceive * (energyThroughput + Decimal.ONE) + energyThroughputFlat
override val maxEnergyExtract: Decimal
get() = values.maxEnergyExtract * (energyThroughput + Decimal.ONE) + energyThroughputFlat
}
}

View File

@ -25,7 +25,6 @@ import ru.dbotthepony.mc.otm.config.ItemsConfig
import ru.dbotthepony.mc.otm.core.*
import ru.dbotthepony.mc.otm.core.math.Decimal
import ru.dbotthepony.mc.otm.registry.MDamageTypes
import ru.dbotthepony.mc.otm.registry.MRegistry
import ru.dbotthepony.mc.otm.registry.MatteryDamageSource
import ru.dbotthepony.mc.otm.runIfClient
import kotlin.math.roundToInt
@ -100,9 +99,9 @@ open class BatteryItem : Item {
constructor(values: BatteryBalanceValues) : super(Properties().stacksTo(1)) {
isCreative = false
this._capacity = values::capacity
this._receive = values::receive
this._extract = values::extract
this._capacity = values::energyCapacity
this._receive = values::maxEnergyReceive
this._extract = values::maxEnergyExtract
this._initialBatteryLevel = values::initialBatteryLevel
}

View File

@ -28,7 +28,7 @@ import ru.dbotthepony.mc.otm.capability.energy.IMatteryEnergyStorage
import ru.dbotthepony.mc.otm.capability.energy.getBarColor
import ru.dbotthepony.mc.otm.capability.energy.getBarWidth
import ru.dbotthepony.mc.otm.compat.mekanism.Mattery2MekanismEnergyWrapper
import ru.dbotthepony.mc.otm.config.ConciseBalanceValues
import ru.dbotthepony.mc.otm.config.EnergyBalanceValues
import ru.dbotthepony.mc.otm.core.*
import ru.dbotthepony.mc.otm.core.math.Decimal
import ru.dbotthepony.mc.otm.core.math.readDecimal
@ -322,10 +322,10 @@ class QuantumBatteryItem : Item {
this.saveDataID = "otm_$saveDataID".intern()
}
constructor(saveDataID: String, values: ConciseBalanceValues) : super(Properties().stacksTo(1)) {
constructor(saveDataID: String, values: EnergyBalanceValues) : super(Properties().stacksTo(1)) {
isCreative = false
_capacity = values::capacity
_throughput = values::throughput
_capacity = values::energyCapacity
_throughput = values::energyThroughput
this.saveDataID = "otm_$saveDataID".intern()
}

View File

@ -9,8 +9,7 @@ import net.minecraft.world.item.Rarity
import net.minecraft.world.item.TooltipFlag
import net.minecraft.world.level.Level
import net.minecraftforge.common.capabilities.ICapabilityProvider
import ru.dbotthepony.mc.otm.config.ConciseBalanceValues
import ru.dbotthepony.mc.otm.OverdriveThatMatters
import ru.dbotthepony.mc.otm.config.EnergyBalanceValues
import ru.dbotthepony.mc.otm.capability.*
import ru.dbotthepony.mc.otm.capability.energy.EnergyProducerItem
import ru.dbotthepony.mc.otm.capability.energy.ItemEnergyStorageImpl
@ -25,7 +24,7 @@ open class SingleUseBatteryItem(
private val _throughput: () -> 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()