Final cleanups regarding energy balance values
This commit is contained in:
parent
c3ed7f9556
commit
5c3f0e54c1
@ -34,7 +34,7 @@ import ru.dbotthepony.mc.otm.graph.matter.SimpleMatterNode
|
|||||||
class MatterBottlerBlockEntity(blockPos: BlockPos, blockState: BlockState) :
|
class MatterBottlerBlockEntity(blockPos: BlockPos, blockState: BlockState) :
|
||||||
MatteryPoweredBlockEntity(MBlockEntities.MATTER_BOTTLER, blockPos, 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)
|
val energyConfig = ConfigurableEnergy(energy)
|
||||||
|
|
||||||
private inner class Container : MatteryContainer(3) {
|
private inner class Container : MatteryContainer(3) {
|
||||||
|
@ -21,7 +21,7 @@ import ru.dbotthepony.mc.otm.storage.*
|
|||||||
|
|
||||||
class DriveRackBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) :
|
class DriveRackBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) :
|
||||||
MatteryPoweredBlockEntity(MBlockEntities.DRIVE_RACK, p_155229_, p_155230_) {
|
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) {
|
val container: MatteryContainer = object : MatteryContainer(this::setChanged, 4) {
|
||||||
override fun setChanged(slot: Int, new: ItemStack, old: ItemStack) {
|
override fun setChanged(slot: Int, new: ItemStack, old: ItemStack) {
|
||||||
|
@ -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) {
|
val container: MatteryContainer = object : MatteryContainer(this::setChanged, 1) {
|
||||||
override fun setChanged(slot: Int, new: ItemStack, old: ItemStack) {
|
override fun setChanged(slot: Int, new: ItemStack, old: ItemStack) {
|
||||||
|
@ -179,7 +179,7 @@ class ItemMonitorBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) :
|
|||||||
MatteryPoweredBlockEntity(MBlockEntities.ITEM_MONITOR, p_155229_, p_155230_),
|
MatteryPoweredBlockEntity(MBlockEntities.ITEM_MONITOR, p_155229_, p_155230_),
|
||||||
IStorageEventConsumer<ItemStackWrapper> {
|
IStorageEventConsumer<ItemStackWrapper> {
|
||||||
|
|
||||||
val energy = WorkerEnergyStorage(this, MachinesConfig.ITEM_MONITOR)
|
val energy = WorkerEnergyStorage(this::setChangedLight, MachinesConfig.ITEM_MONITOR)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
exposeEnergyGlobally(energy)
|
exposeEnergyGlobally(energy)
|
||||||
|
@ -22,7 +22,7 @@ class StoragePowerSupplierBlockEntity(blockPos: BlockPos, blockState: BlockState
|
|||||||
}
|
}
|
||||||
|
|
||||||
val cell = StorageNode()
|
val cell = StorageNode()
|
||||||
val energy = WorkerEnergyStorage(this, MachinesConfig.STORAGE_POWER_SUPPLIER)
|
val energy = WorkerEnergyStorage(this::setChangedLight, MachinesConfig.STORAGE_POWER_SUPPLIER)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
savetable(::energy, ENERGY_KEY)
|
savetable(::energy, ENERGY_KEY)
|
||||||
|
@ -29,14 +29,6 @@ sealed class BlockEnergyStorageImpl(
|
|||||||
private val maxInputProvider: () -> Decimal?,
|
private val maxInputProvider: () -> Decimal?,
|
||||||
private val maxOutputProvider: () -> Decimal?,
|
private val maxOutputProvider: () -> Decimal?,
|
||||||
) : IMatteryEnergyStorage, INBTSerializable<CompoundTag?>, IEnergyStorageImpl {
|
) : 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 maxInputStorage: Decimal? = null
|
||||||
private var maxOutputStorage: Decimal? = null
|
private var maxOutputStorage: Decimal? = null
|
||||||
private var maxBatteryLevelStorage: Decimal? = null
|
private var maxBatteryLevelStorage: Decimal? = null
|
||||||
@ -157,30 +149,13 @@ sealed class BlockEnergyStorageImpl(
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val DEFAULT_MAX_IO = Decimal(200)
|
val DEFAULT_MAX_IO = Decimal(400)
|
||||||
val DEFAULT_MAX_CAPACITY = Decimal(60_000)
|
val DEFAULT_MAX_CAPACITY = Decimal(40_000)
|
||||||
|
|
||||||
const val ENERGY_STORED_KEY = "energy_stored"
|
const val ENERGY_STORED_KEY = "energy_stored"
|
||||||
const val ENERGY_STORED_MAX_KEY = "energy_stored_max"
|
const val ENERGY_STORED_MAX_KEY = "energy_stored_max"
|
||||||
const val MAX_INPUT_KEY = "max_input"
|
const val MAX_INPUT_KEY = "max_input"
|
||||||
const val MAX_OUTPUT_KEY = "max_output"
|
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 },
|
maxInput: () -> Decimal? = { DEFAULT_MAX_IO },
|
||||||
maxOutput: () -> Decimal? = maxInput
|
maxOutput: () -> Decimal? = maxInput
|
||||||
) : BlockEnergyStorageImpl(listener, FlowDirection.INPUT, maxBatteryLevel, maxInput, maxOutput) {
|
) : 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(
|
constructor(
|
||||||
listener: () -> Unit,
|
listener: () -> Unit,
|
||||||
values: EnergyBalanceValues
|
values: EnergyBalanceValues
|
||||||
) : this(listener, values::energyCapacity, values::energyThroughput, values::energyThroughput)
|
) : this(listener, values::energyCapacity, values::energyThroughput, values::energyThroughput)
|
||||||
|
|
||||||
constructor(
|
|
||||||
listener: BlockEntity,
|
|
||||||
values: EnergyBalanceValues
|
|
||||||
) : this(listener::setChanged, values::energyCapacity, values::energyThroughput, values::energyThroughput)
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
listener: () -> Unit,
|
listener: () -> Unit,
|
||||||
values: VerboseEnergyBalanceValues
|
values: VerboseEnergyBalanceValues
|
||||||
) : this(listener, values::energyCapacity, values::maxEnergyReceive, values::maxEnergyExtract)
|
) : 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 {
|
companion object {
|
||||||
fun appendHoverText(itemStack: ItemStack, tooltips: MutableList<Component>) {
|
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 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)
|
cap.deserializeNBT(tag)
|
||||||
batteryLevel(cap, tooltips, false)
|
batteryLevel(cap, tooltips, false)
|
||||||
}
|
}
|
||||||
@ -242,42 +195,20 @@ open class GeneratorEnergyStorage(
|
|||||||
maxInput: () -> Decimal? = { DEFAULT_MAX_IO },
|
maxInput: () -> Decimal? = { DEFAULT_MAX_IO },
|
||||||
maxOutput: () -> Decimal? = maxInput
|
maxOutput: () -> Decimal? = maxInput
|
||||||
) : BlockEnergyStorageImpl(listener, FlowDirection.OUTPUT, maxBatteryLevel, maxInput, maxOutput) {
|
) : 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(
|
constructor(
|
||||||
listener: () -> Unit,
|
listener: () -> Unit,
|
||||||
values: EnergyBalanceValues
|
values: EnergyBalanceValues
|
||||||
) : this(listener, values::energyCapacity, values::energyThroughput, values::energyThroughput)
|
) : this(listener, values::energyCapacity, values::energyThroughput, values::energyThroughput)
|
||||||
|
|
||||||
constructor(
|
|
||||||
listener: BlockEntity,
|
|
||||||
values: EnergyBalanceValues
|
|
||||||
) : this(listener::setChanged, values::energyCapacity, values::energyThroughput, values::energyThroughput)
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
listener: () -> Unit,
|
listener: () -> Unit,
|
||||||
values: VerboseEnergyBalanceValues
|
values: VerboseEnergyBalanceValues
|
||||||
) : this(listener, values::energyCapacity, values::maxEnergyReceive, values::maxEnergyExtract)
|
) : 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 {
|
companion object {
|
||||||
fun appendHoverText(itemStack: ItemStack, tooltips: MutableList<Component>) {
|
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 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)
|
cap.deserializeNBT(tag)
|
||||||
batteryLevel(cap, tooltips)
|
batteryLevel(cap, tooltips)
|
||||||
}
|
}
|
||||||
@ -294,42 +225,20 @@ open class CapacitorEnergyStorage(
|
|||||||
maxInput: () -> Decimal? = { DEFAULT_MAX_IO },
|
maxInput: () -> Decimal? = { DEFAULT_MAX_IO },
|
||||||
maxOutput: () -> Decimal? = maxInput
|
maxOutput: () -> Decimal? = maxInput
|
||||||
) : BlockEnergyStorageImpl(listener, FlowDirection.BI_DIRECTIONAL, maxBatteryLevel, maxInput, maxOutput) {
|
) : 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(
|
constructor(
|
||||||
listener: () -> Unit,
|
listener: () -> Unit,
|
||||||
values: EnergyBalanceValues
|
values: EnergyBalanceValues
|
||||||
) : this(listener, values::energyCapacity, values::energyThroughput, values::energyThroughput)
|
) : this(listener, values::energyCapacity, values::energyThroughput, values::energyThroughput)
|
||||||
|
|
||||||
constructor(
|
|
||||||
listener: BlockEntity,
|
|
||||||
values: EnergyBalanceValues
|
|
||||||
) : this(listener::setChanged, values::energyCapacity, values::energyThroughput, values::energyThroughput)
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
listener: () -> Unit,
|
listener: () -> Unit,
|
||||||
values: VerboseEnergyBalanceValues
|
values: VerboseEnergyBalanceValues
|
||||||
) : this(listener, values::energyCapacity, values::maxEnergyReceive, values::maxEnergyExtract)
|
) : 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 {
|
companion object {
|
||||||
fun appendHoverText(itemStack: ItemStack, tooltips: MutableList<Component>) {
|
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 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)
|
cap.deserializeNBT(tag)
|
||||||
batteryLevel(cap, tooltips)
|
batteryLevel(cap, tooltips)
|
||||||
}
|
}
|
||||||
|
@ -138,11 +138,11 @@ object MachinesConfig : AbstractConfig("machines") {
|
|||||||
.defineInRange("DIVISOR", 3.0, 0.1, Double.MAX_VALUE)
|
.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_POWER_SUPPLIER = conciseValues(MNames.STORAGE_POWER_SUPPLIER, Decimal(80_000), Decimal(2_000))
|
||||||
val STORAGE_INTERFACES = BlockEnergyStorageImpl.makeConfigEntry(builder, "STORAGE_INTERFACES", capacity = Decimal(10_000))
|
val STORAGE_INTERFACES = conciseValues("STORAGE_INTERFACES", Decimal(10_000), Decimal(100))
|
||||||
val ITEM_MONITOR = BlockEnergyStorageImpl.makeConfigEntry(builder, MNames.ITEM_MONITOR)
|
val ITEM_MONITOR = conciseValues(MNames.ITEM_MONITOR, Decimal(10_000), Decimal(100))
|
||||||
val DRIVE_VIEWER = BlockEnergyStorageImpl.makeConfigEntry(builder, MNames.DRIVE_VIEWER)
|
val DRIVE_VIEWER = conciseValues(MNames.DRIVE_VIEWER, Decimal(10_000), Decimal(100))
|
||||||
val DRIVE_RACK = BlockEnergyStorageImpl.makeConfigEntry(builder, MNames.DRIVE_RACK, capacity = Decimal(80_000))
|
val DRIVE_RACK = conciseValues(MNames.DRIVE_RACK, Decimal(10_000), Decimal(100))
|
||||||
|
|
||||||
object AndroidCharger {
|
object AndroidCharger {
|
||||||
val RADIUS_WIDTH: Double by builder
|
val RADIUS_WIDTH: Double by builder
|
||||||
@ -154,7 +154,7 @@ object MachinesConfig : AbstractConfig("machines") {
|
|||||||
.defineInRange("RADIUS_HEIGHT", 4.0, 1.0, Double.MAX_VALUE)
|
.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(
|
val POWERED_FURNACE = workerValues(
|
||||||
"POWERED_FURNACE",
|
"POWERED_FURNACE",
|
||||||
|
Loading…
Reference in New Issue
Block a user