Final cleanups regarding energy balance values

This commit is contained in:
DBotThePony 2023-08-04 22:59:20 +07:00
parent c3ed7f9556
commit 5c3f0e54c1
Signed by: DBot
GPG Key ID: DCC23B5715498507
7 changed files with 16 additions and 107 deletions

View File

@ -34,7 +34,7 @@ import ru.dbotthepony.mc.otm.graph.matter.SimpleMatterNode
class MatterBottlerBlockEntity(blockPos: BlockPos, blockState: BlockState) :
MatteryPoweredBlockEntity(MBlockEntities.MATTER_BOTTLER, blockPos, blockState) {
val energy = ProfiledEnergyStorage(WorkerEnergyStorage(this, MachinesConfig.MatterBottler.VALUES))
val energy = ProfiledEnergyStorage(WorkerEnergyStorage(this::setChangedLight, MachinesConfig.MatterBottler.VALUES))
val energyConfig = ConfigurableEnergy(energy)
private inner class Container : MatteryContainer(3) {

View File

@ -21,7 +21,7 @@ import ru.dbotthepony.mc.otm.storage.*
class DriveRackBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) :
MatteryPoweredBlockEntity(MBlockEntities.DRIVE_RACK, p_155229_, p_155230_) {
val energy = WorkerEnergyStorage(this, MachinesConfig.DRIVE_RACK)
val energy = WorkerEnergyStorage(this::setChangedLight, MachinesConfig.DRIVE_RACK)
val container: MatteryContainer = object : MatteryContainer(this::setChanged, 4) {
override fun setChanged(slot: Int, new: ItemStack, old: ItemStack) {

View File

@ -40,7 +40,7 @@ class DriveViewerBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : Matte
}
}
val energy = WorkerEnergyStorage(this, MachinesConfig.DRIVE_VIEWER)
val energy = WorkerEnergyStorage(this::setChangedLight, MachinesConfig.DRIVE_VIEWER)
val container: MatteryContainer = object : MatteryContainer(this::setChanged, 1) {
override fun setChanged(slot: Int, new: ItemStack, old: ItemStack) {

View File

@ -179,7 +179,7 @@ class ItemMonitorBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) :
MatteryPoweredBlockEntity(MBlockEntities.ITEM_MONITOR, p_155229_, p_155230_),
IStorageEventConsumer<ItemStackWrapper> {
val energy = WorkerEnergyStorage(this, MachinesConfig.ITEM_MONITOR)
val energy = WorkerEnergyStorage(this::setChangedLight, MachinesConfig.ITEM_MONITOR)
init {
exposeEnergyGlobally(energy)

View File

@ -22,7 +22,7 @@ class StoragePowerSupplierBlockEntity(blockPos: BlockPos, blockState: BlockState
}
val cell = StorageNode()
val energy = WorkerEnergyStorage(this, MachinesConfig.STORAGE_POWER_SUPPLIER)
val energy = WorkerEnergyStorage(this::setChangedLight, MachinesConfig.STORAGE_POWER_SUPPLIER)
init {
savetable(::energy, ENERGY_KEY)

View File

@ -29,14 +29,6 @@ sealed class BlockEnergyStorageImpl(
private val maxInputProvider: () -> Decimal?,
private val maxOutputProvider: () -> Decimal?,
) : IMatteryEnergyStorage, INBTSerializable<CompoundTag?>, IEnergyStorageImpl {
constructor(
listener: () -> Unit,
direction: FlowDirection,
maxBatteryLevel: Decimal,
maxInput: Decimal?,
maxOutput: Decimal?,
) : this(listener, direction, { maxBatteryLevel }, { maxInput }, { maxOutput })
private var maxInputStorage: Decimal? = null
private var maxOutputStorage: Decimal? = null
private var maxBatteryLevelStorage: Decimal? = null
@ -157,30 +149,13 @@ sealed class BlockEnergyStorageImpl(
}
companion object {
val DEFAULT_MAX_IO = Decimal(200)
val DEFAULT_MAX_CAPACITY = Decimal(60_000)
val DEFAULT_MAX_IO = Decimal(400)
val DEFAULT_MAX_CAPACITY = Decimal(40_000)
const val ENERGY_STORED_KEY = "energy_stored"
const val ENERGY_STORED_MAX_KEY = "energy_stored_max"
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 = {}): EnergyBalanceValues {
if (name != null)
builder.push(name)
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)
if (name != null)
builder.pop()
return obj
}
}
}
@ -190,42 +165,20 @@ open class WorkerEnergyStorage(
maxInput: () -> Decimal? = { DEFAULT_MAX_IO },
maxOutput: () -> Decimal? = maxInput
) : BlockEnergyStorageImpl(listener, FlowDirection.INPUT, maxBatteryLevel, maxInput, maxOutput) {
constructor(
listener: () -> Unit,
maxBatteryLevel: Decimal = DEFAULT_MAX_CAPACITY,
maxInput: Decimal? = DEFAULT_MAX_IO,
maxOutput: Decimal? = maxInput) : this(listener, { maxBatteryLevel }, { maxInput }, { maxOutput })
constructor(
listener: () -> Unit,
values: EnergyBalanceValues
) : this(listener, values::energyCapacity, values::energyThroughput, values::energyThroughput)
constructor(
listener: BlockEntity,
values: EnergyBalanceValues
) : this(listener::setChanged, values::energyCapacity, values::energyThroughput, values::energyThroughput)
constructor(
listener: () -> Unit,
values: VerboseEnergyBalanceValues
) : this(listener, values::energyCapacity, values::maxEnergyReceive, values::maxEnergyExtract)
constructor(
listener: BlockEntity,
values: VerboseEnergyBalanceValues
) : this(listener::setChanged, values::energyCapacity, values::maxEnergyReceive, values::maxEnergyExtract)
constructor(
listener: BlockEntity,
maxBatteryLevel: Decimal = DEFAULT_MAX_CAPACITY,
maxInput: Decimal? = DEFAULT_MAX_IO,
maxOutput: Decimal? = maxInput) : this(listener::setChanged, maxBatteryLevel, maxInput, maxOutput)
companion object {
fun appendHoverText(itemStack: ItemStack, tooltips: MutableList<Component>) {
val tag = (itemStack.tag?.get(BlockItem.BLOCK_ENTITY_TAG) as? CompoundTag)?.get(MatteryBlockEntity.ENERGY_KEY) as? CompoundTag ?: return
val cap = WorkerEnergyStorage({}, DEFAULT_MAX_CAPACITY)
val cap = WorkerEnergyStorage({}, { DEFAULT_MAX_CAPACITY })
cap.deserializeNBT(tag)
batteryLevel(cap, tooltips, false)
}
@ -242,42 +195,20 @@ open class GeneratorEnergyStorage(
maxInput: () -> Decimal? = { DEFAULT_MAX_IO },
maxOutput: () -> Decimal? = maxInput
) : BlockEnergyStorageImpl(listener, FlowDirection.OUTPUT, maxBatteryLevel, maxInput, maxOutput) {
constructor(
listener: () -> Unit,
maxBatteryLevel: Decimal = DEFAULT_MAX_CAPACITY,
maxInput: Decimal? = DEFAULT_MAX_IO,
maxOutput: Decimal? = maxInput) : this(listener, { maxBatteryLevel }, { maxInput }, { maxOutput })
constructor(
listener: () -> Unit,
values: EnergyBalanceValues
) : this(listener, values::energyCapacity, values::energyThroughput, values::energyThroughput)
constructor(
listener: BlockEntity,
values: EnergyBalanceValues
) : this(listener::setChanged, values::energyCapacity, values::energyThroughput, values::energyThroughput)
constructor(
listener: () -> Unit,
values: VerboseEnergyBalanceValues
) : this(listener, values::energyCapacity, values::maxEnergyReceive, values::maxEnergyExtract)
constructor(
listener: BlockEntity,
values: VerboseEnergyBalanceValues
) : this(listener::setChanged, values::energyCapacity, values::maxEnergyReceive, values::maxEnergyExtract)
constructor(
listener: BlockEntity,
maxBatteryLevel: Decimal = DEFAULT_MAX_CAPACITY,
maxInput: Decimal? = DEFAULT_MAX_IO,
maxOutput: Decimal? = maxInput) : this(listener::setChanged, maxBatteryLevel, maxInput, maxOutput)
companion object {
fun appendHoverText(itemStack: ItemStack, tooltips: MutableList<Component>) {
val tag = (itemStack.tag?.get(BlockItem.BLOCK_ENTITY_TAG) as? CompoundTag)?.get(MatteryBlockEntity.ENERGY_KEY) as? CompoundTag ?: return
val cap = GeneratorEnergyStorage({}, DEFAULT_MAX_CAPACITY)
val cap = GeneratorEnergyStorage({}, { DEFAULT_MAX_CAPACITY })
cap.deserializeNBT(tag)
batteryLevel(cap, tooltips)
}
@ -294,42 +225,20 @@ open class CapacitorEnergyStorage(
maxInput: () -> Decimal? = { DEFAULT_MAX_IO },
maxOutput: () -> Decimal? = maxInput
) : BlockEnergyStorageImpl(listener, FlowDirection.BI_DIRECTIONAL, maxBatteryLevel, maxInput, maxOutput) {
constructor(
listener: () -> Unit,
maxBatteryLevel: Decimal = DEFAULT_MAX_CAPACITY,
maxInput: Decimal? = DEFAULT_MAX_IO,
maxOutput: Decimal? = maxInput) : this(listener, { maxBatteryLevel }, { maxInput }, { maxOutput })
constructor(
listener: () -> Unit,
values: EnergyBalanceValues
) : this(listener, values::energyCapacity, values::energyThroughput, values::energyThroughput)
constructor(
listener: BlockEntity,
values: EnergyBalanceValues
) : this(listener::setChanged, values::energyCapacity, values::energyThroughput, values::energyThroughput)
constructor(
listener: () -> Unit,
values: VerboseEnergyBalanceValues
) : this(listener, values::energyCapacity, values::maxEnergyReceive, values::maxEnergyExtract)
constructor(
listener: BlockEntity,
values: VerboseEnergyBalanceValues
) : this(listener::setChanged, values::energyCapacity, values::maxEnergyReceive, values::maxEnergyExtract)
constructor(
listener: BlockEntity,
maxBatteryLevel: Decimal = DEFAULT_MAX_CAPACITY,
maxInput: Decimal? = DEFAULT_MAX_IO,
maxOutput: Decimal? = maxInput) : this(listener::setChanged, maxBatteryLevel, maxInput, maxOutput)
companion object {
fun appendHoverText(itemStack: ItemStack, tooltips: MutableList<Component>) {
val tag = (itemStack.tag?.get(BlockItem.BLOCK_ENTITY_TAG) as? CompoundTag)?.get(MatteryBlockEntity.ENERGY_KEY) as? CompoundTag ?: return
val cap = CapacitorEnergyStorage({}, DEFAULT_MAX_CAPACITY)
val cap = CapacitorEnergyStorage({}, { DEFAULT_MAX_CAPACITY })
cap.deserializeNBT(tag)
batteryLevel(cap, tooltips)
}

View File

@ -138,11 +138,11 @@ object MachinesConfig : AbstractConfig("machines") {
.defineInRange("DIVISOR", 3.0, 0.1, Double.MAX_VALUE)
}
val STORAGE_POWER_SUPPLIER = BlockEnergyStorageImpl.makeConfigEntry(builder, MNames.STORAGE_POWER_SUPPLIER, capacity = Decimal(100_000), throughput = Decimal(320))
val STORAGE_INTERFACES = BlockEnergyStorageImpl.makeConfigEntry(builder, "STORAGE_INTERFACES", capacity = Decimal(10_000))
val ITEM_MONITOR = BlockEnergyStorageImpl.makeConfigEntry(builder, MNames.ITEM_MONITOR)
val DRIVE_VIEWER = BlockEnergyStorageImpl.makeConfigEntry(builder, MNames.DRIVE_VIEWER)
val DRIVE_RACK = BlockEnergyStorageImpl.makeConfigEntry(builder, MNames.DRIVE_RACK, capacity = Decimal(80_000))
val STORAGE_POWER_SUPPLIER = conciseValues(MNames.STORAGE_POWER_SUPPLIER, Decimal(80_000), Decimal(2_000))
val STORAGE_INTERFACES = conciseValues("STORAGE_INTERFACES", Decimal(10_000), Decimal(100))
val ITEM_MONITOR = conciseValues(MNames.ITEM_MONITOR, Decimal(10_000), Decimal(100))
val DRIVE_VIEWER = conciseValues(MNames.DRIVE_VIEWER, Decimal(10_000), Decimal(100))
val DRIVE_RACK = conciseValues(MNames.DRIVE_RACK, Decimal(10_000), Decimal(100))
object AndroidCharger {
val RADIUS_WIDTH: Double by builder
@ -154,7 +154,7 @@ object MachinesConfig : AbstractConfig("machines") {
.defineInRange("RADIUS_HEIGHT", 4.0, 1.0, Double.MAX_VALUE)
}
val ANDROID_CHARGER = BlockEnergyStorageImpl.makeConfigEntry(builder, MNames.ANDROID_CHARGER, capacity = Decimal(1_000_000), throughput = Decimal(8192)) { AndroidCharger }
val ANDROID_CHARGER = conciseValues(MNames.ANDROID_CHARGER, Decimal(1_000_000), Decimal(8192)) { AndroidCharger }
val POWERED_FURNACE = workerValues(
"POWERED_FURNACE",