diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/GlobalEventHandler.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/GlobalEventHandler.kt index d52964449..8eaa30141 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/GlobalEventHandler.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/GlobalEventHandler.kt @@ -15,6 +15,7 @@ import net.minecraftforge.event.server.ServerStoppedEvent import net.minecraftforge.event.server.ServerStoppingEvent import net.minecraftforge.fml.loading.FMLLoader import org.apache.logging.log4j.LogManager +import ru.dbotthepony.mc.otm.capability.energy.ProfiledEnergyStorage import ru.dbotthepony.mc.otm.client.minecraft import ru.dbotthepony.mc.otm.core.util.IConditionalTickable import ru.dbotthepony.mc.otm.core.util.ITickable @@ -148,6 +149,7 @@ fun onServerTick(event: ServerTickEvent) { postServerTick.tick() // чтоб не плодить кучу подписчиков, вызовем напрямую отсюда Abstract6Graph.tick() + ProfiledEnergyStorage.onServerPostTick() } } 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 799e86601..87d3d7b84 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 @@ -17,6 +17,7 @@ import ru.dbotthepony.mc.otm.block.entity.WorkerState import ru.dbotthepony.mc.otm.capability.FlowDirection import ru.dbotthepony.mc.otm.capability.energy.BlockEnergyStorageImpl import ru.dbotthepony.mc.otm.capability.MatteryCapability +import ru.dbotthepony.mc.otm.capability.energy.ProfiledEnergyStorage import ru.dbotthepony.mc.otm.capability.energy.WorkerEnergyStorage import ru.dbotthepony.mc.otm.capability.matter.IMatterStorage import ru.dbotthepony.mc.otm.capability.matter.MatterStorageImpl @@ -37,7 +38,7 @@ import ru.dbotthepony.mc.otm.graph.matter.SimpleMatterNode class MatterBottlerBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : MatteryPoweredBlockEntity(MBlockEntities.MATTER_BOTTLER, p_155229_, p_155230_) { - val energy = WorkerEnergyStorage(this, ENERGY_VALUES) + val energy = ProfiledEnergyStorage(WorkerEnergyStorage(this, ENERGY_VALUES)) var isBottling: Boolean = true set(value) { 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 2fb8ecca8..1a4b1df23 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 @@ -13,6 +13,7 @@ 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.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.config.ConciseBalanceValues @@ -117,7 +118,7 @@ class MatterDecomposerBlockEntity(pos: BlockPos, state: BlockState) } } - val energy = WorkerEnergyStorage(this, ENERGY_VALUES) + val energy = ProfiledEnergyStorage(WorkerEnergyStorage(this, ENERGY_VALUES)) val energyConfig = ConfigurableEnergy(energy) init { 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 c1a99e6cf..65f5b559b 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 @@ -17,6 +17,7 @@ import ru.dbotthepony.mc.otm.block.entity.MatteryPoweredBlockEntity import ru.dbotthepony.mc.otm.capability.FlowDirection import ru.dbotthepony.mc.otm.capability.MatteryCapability 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.IMatterStorage import ru.dbotthepony.mc.otm.capability.matter.IPatternState @@ -54,7 +55,7 @@ class MatterReconstructorBlockEntity(blockPos: BlockPos, blockState: BlockState) private set val matter = MatterStorageImpl(::setChangedLight, FlowDirection.INPUT, ::CAPACITY) - val energy = WorkerEnergyStorage(::setChangedLight, ENERGY_VALUES) + val energy = ProfiledEnergyStorage(WorkerEnergyStorage(::setChangedLight, ENERGY_VALUES)) val matterNode = object : MatterNode() { override fun getMatterHandler(): IMatterStorage { diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterRecyclerBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterRecyclerBlockEntity.kt index 6625247d8..410079f8e 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterRecyclerBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterRecyclerBlockEntity.kt @@ -16,6 +16,7 @@ import ru.dbotthepony.mc.otm.block.entity.MatteryWorkerBlockEntity import ru.dbotthepony.mc.otm.capability.FlowDirection import ru.dbotthepony.mc.otm.capability.energy.BlockEnergyStorageImpl import ru.dbotthepony.mc.otm.capability.MatteryCapability +import ru.dbotthepony.mc.otm.capability.energy.ProfiledEnergyStorage import ru.dbotthepony.mc.otm.capability.energy.WorkerEnergyStorage import ru.dbotthepony.mc.otm.capability.matter.IMatterStorage import ru.dbotthepony.mc.otm.capability.matter.MatterStorageImpl @@ -68,7 +69,7 @@ class MatterRecyclerBlockEntity(blockPos: BlockPos, blockState: BlockState) val container = MatteryContainer(::itemContainerUpdated, 1).also(::addDroppableContainer) val matterNode = SimpleMatterNode(matter = matter) - val energy = WorkerEnergyStorage(::powerLevelUpdated, ENERGY_CONFIG) + val energy = ProfiledEnergyStorage(WorkerEnergyStorage(::powerLevelUpdated, ENERGY_CONFIG)) val itemConfig = ConfigurableItemHandler(input = container.handler(object : HandlerFilter { override fun canInsert(slot: Int, stack: ItemStack): Boolean { 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 c85da2531..494df7e09 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 @@ -13,6 +13,7 @@ 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.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.IMatterStorage import ru.dbotthepony.mc.otm.capability.matter.IPatternState @@ -99,7 +100,7 @@ class MatterReplicatorBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : } } - val energy = WorkerEnergyStorage(::powerLevelUpdated, ENERGY_VALUES) + val energy = ProfiledEnergyStorage(WorkerEnergyStorage(::powerLevelUpdated, ENERGY_VALUES)) val matter = MatterStorageImpl(::matterLevelUpdated, FlowDirection.INPUT, ::MATTER_CAPACITY) val container = MatteryContainer(::itemContainerUpdated, 5).also(::addDroppableContainer) 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 7936b0ffd..fff551547 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 @@ -13,6 +13,7 @@ import ru.dbotthepony.mc.otm.config.ConciseBalanceValues import ru.dbotthepony.mc.otm.block.entity.MatteryWorkerBlockEntity import ru.dbotthepony.mc.otm.capability.energy.BlockEnergyStorageImpl import ru.dbotthepony.mc.otm.capability.MatteryCapability +import ru.dbotthepony.mc.otm.capability.energy.ProfiledEnergyStorage import ru.dbotthepony.mc.otm.capability.energy.WorkerEnergyStorage import ru.dbotthepony.mc.otm.capability.matter.IPatternState import ru.dbotthepony.mc.otm.capability.matter.PatternState @@ -36,7 +37,7 @@ class MatterScannerBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : MatteryWorkerBlockEntity(MBlockEntities.MATTER_SCANNER, p_155229_, p_155230_, ::ItemJob) { val container = MatteryContainer(::itemContainerUpdated, 1).also(::addDroppableContainer) - val energy = WorkerEnergyStorage(::powerLevelUpdated, ENERGY_VALUES) + val energy = ProfiledEnergyStorage(WorkerEnergyStorage(::powerLevelUpdated, ENERGY_VALUES)) val itemConfig = ConfigurableItemHandler(inputOutput = container.handler(object : HandlerFilter { override fun canInsert(slot: Int, stack: ItemStack): Boolean { diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/AndroidStationBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/AndroidStationBlockEntity.kt index e892a19e2..a7550f5ac 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/AndroidStationBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/AndroidStationBlockEntity.kt @@ -13,6 +13,7 @@ import net.minecraftforge.common.ForgeConfigSpec import ru.dbotthepony.mc.otm.block.entity.MatteryPoweredBlockEntity import ru.dbotthepony.mc.otm.block.entity.WorkerState import ru.dbotthepony.mc.otm.capability.MatteryCapability +import ru.dbotthepony.mc.otm.capability.energy.ProfiledEnergyStorage import ru.dbotthepony.mc.otm.capability.energy.WorkerEnergyStorage import ru.dbotthepony.mc.otm.capability.moveEnergy import ru.dbotthepony.mc.otm.core.math.Decimal @@ -32,7 +33,7 @@ class AndroidStationBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : return AndroidStationMenu(containerID, inventory, this) } - val energy = object : WorkerEnergyStorage(this@AndroidStationBlockEntity::setChangedLight, ::CAPACITY, ::MAX_IO, { null }) { + val energy: ProfiledEnergyStorage = ProfiledEnergyStorage(object : WorkerEnergyStorage(this@AndroidStationBlockEntity::setChangedLight, ::CAPACITY, ::MAX_IO, { null }) { override fun extractEnergy(howMuch: Decimal, simulate: Boolean): Decimal { return super.extractEnergy(howMuch, simulate).also { if (!simulate && this.batteryLevel.isZero) { @@ -55,7 +56,7 @@ class AndroidStationBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : } } } - } + }) val energyConfig = ConfigurableEnergy(energy) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/BatteryBankBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/BatteryBankBlockEntity.kt index 064bc1cae..9aa980d64 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/BatteryBankBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/BatteryBankBlockEntity.kt @@ -11,6 +11,7 @@ import ru.dbotthepony.mc.otm.block.entity.MatteryDeviceBlockEntity import ru.dbotthepony.mc.otm.capability.FlowDirection import ru.dbotthepony.mc.otm.capability.energy import ru.dbotthepony.mc.otm.capability.energy.IMatteryEnergyStorage +import ru.dbotthepony.mc.otm.capability.energy.ProfiledEnergyStorage import ru.dbotthepony.mc.otm.capability.energyStoredMattery import ru.dbotthepony.mc.otm.capability.matteryEnergy import ru.dbotthepony.mc.otm.capability.maxEnergyStoredMattery @@ -21,6 +22,7 @@ import ru.dbotthepony.mc.otm.core.immutableList import ru.dbotthepony.mc.otm.core.math.Decimal import ru.dbotthepony.mc.otm.menu.tech.BatteryBankMenu import ru.dbotthepony.mc.otm.registry.MBlockEntities +import java.util.function.Supplier class BatteryBankBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : MatteryDeviceBlockEntity(MBlockEntities.BATTERY_BANK, p_155229_, p_155230_), IMatteryEnergyStorage { var gaugeLevel by synchronizer.float().property @@ -168,7 +170,7 @@ class BatteryBankBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : Matte } val energyConfig = ConfigurableEnergy( - this, + ProfiledEnergyStorage(this), frontDefault = FlowDirection.OUTPUT, backDefault = FlowDirection.INPUT, leftDefault = FlowDirection.INPUT, @@ -179,6 +181,7 @@ class BatteryBankBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : Matte init { energyConfig.front.automatePush = true + savetables.stateful(Supplier { energyConfig.capability.savedata }, "energyUsageHistory") } override fun createMenu(containerID: Int, inventory: Inventory, ply: Player): AbstractContainerMenu { diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/ChemicalGeneratorBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/ChemicalGeneratorBlockEntity.kt index 382295cce..2bf45d05b 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/ChemicalGeneratorBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/ChemicalGeneratorBlockEntity.kt @@ -78,7 +78,6 @@ class ChemicalGeneratorBlockEntity(pos: BlockPos, state: BlockState) : MatteryDe override fun tick() { super.tick() - energy.tick() if (workTicks > 0) { workTicks-- diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/EnergyServoBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/EnergyServoBlockEntity.kt index a179552fd..e50396454 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/EnergyServoBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/EnergyServoBlockEntity.kt @@ -11,6 +11,7 @@ import ru.dbotthepony.mc.otm.capability.FlowDirection import ru.dbotthepony.mc.otm.capability.energy.IMatteryEnergyStorage import ru.dbotthepony.mc.otm.capability.canSetBatteryMattery import ru.dbotthepony.mc.otm.capability.energy +import ru.dbotthepony.mc.otm.capability.energy.ProfiledEnergyStorage import ru.dbotthepony.mc.otm.capability.energyStoredMattery import ru.dbotthepony.mc.otm.capability.extractEnergy import ru.dbotthepony.mc.otm.capability.maxEnergyStoredMattery @@ -25,7 +26,7 @@ class EnergyServoBlockEntity(blockPos: BlockPos, blockState: BlockState) : Matte val discharge = MatteryContainer(::setChangedLight, 1).also(::addDroppableContainer) val charge = MatteryContainer(::setChangedLight, 1).also(::addDroppableContainer) - val energy = object : IMatteryEnergyStorage { + val energy: ProfiledEnergyStorage = ProfiledEnergyStorage(object : IMatteryEnergyStorage { override val energyFlow: FlowDirection get() { val discharge = discharge[0].energy val charge = charge[0].energy @@ -58,7 +59,7 @@ class EnergyServoBlockEntity(blockPos: BlockPos, blockState: BlockState) : Matte override val maxBatteryLevel: Decimal get() = charge[0].energy?.maxEnergyStoredMattery ?: discharge[0].energy?.maxEnergyStoredMattery ?: Decimal.ZERO - } + }) val energyConfig = ConfigurableEnergy(energy, possibleModes = FlowDirection.BI_DIRECTIONAL) val itemConfig = ConfigurableItemHandler( diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/PlatePressBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/PlatePressBlockEntity.kt index 9d93cff3f..d3bf3ac99 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/PlatePressBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/PlatePressBlockEntity.kt @@ -10,6 +10,7 @@ import net.minecraft.world.inventory.AbstractContainerMenu import net.minecraft.world.item.ItemStack import net.minecraft.world.level.block.state.BlockState import ru.dbotthepony.mc.otm.block.entity.MatteryWorkerBlockEntity +import ru.dbotthepony.mc.otm.capability.energy.ProfiledEnergyStorage import ru.dbotthepony.mc.otm.capability.energy.WorkerEnergyStorage import ru.dbotthepony.mc.otm.config.MachinesConfig import ru.dbotthepony.mc.otm.container.MatteryContainer @@ -23,7 +24,7 @@ class PlatePressBlockEntity( p_155229_: BlockPos, p_155230_: BlockState ) : MatteryWorkerBlockEntity(MBlockEntities.PLATE_PRESS, p_155229_, p_155230_, ::ItemJob) { - val energy = WorkerEnergyStorage(this::setChangedLight, MachinesConfig.PLATE_PRESS) + val energy = ProfiledEnergyStorage(WorkerEnergyStorage(this::setChangedLight, MachinesConfig.PLATE_PRESS)) val inputContainer = MatteryContainer(this::itemContainerUpdated, 1).also(::addDroppableContainer) val outputContainer = MatteryContainer(this::itemContainerUpdated, 1).also(::addDroppableContainer) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/capability/energy/ProfiledEnergyStorage.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/capability/energy/ProfiledEnergyStorage.kt index 7bb2efad4..a176e5d65 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/capability/energy/ProfiledEnergyStorage.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/capability/energy/ProfiledEnergyStorage.kt @@ -6,15 +6,20 @@ import net.minecraft.nbt.NumericTag import net.minecraft.nbt.Tag import net.minecraftforge.common.util.INBTSerializable import ru.dbotthepony.mc.otm.capability.FlowDirection +import ru.dbotthepony.mc.otm.core.forValidRefs import ru.dbotthepony.mc.otm.core.math.Decimal import ru.dbotthepony.mc.otm.core.math.set import ru.dbotthepony.mc.otm.core.nbt.map import ru.dbotthepony.mc.otm.core.nbt.set -import ru.dbotthepony.mc.otm.core.util.ITickable +import java.lang.ref.WeakReference import java.util.* import kotlin.collections.ArrayList -class ProfiledEnergyStorage(val parent: E) : IMatteryEnergyStorage, ITickable, INBTSerializable { +class ProfiledEnergyStorage(val parent: E) : IMatteryEnergyStorage, INBTSerializable { + init { + storages.add(WeakReference(this)) + } + override fun extractEnergy(howMuch: Decimal, simulate: Boolean): Decimal { return recordTransfer(parent.extractEnergy(howMuch, simulate), simulate) } @@ -45,24 +50,28 @@ class ProfiledEnergyStorage(val parent: E) : IMattery override var batteryLevel: Decimal get() = parent.batteryLevel set(value) { parent.batteryLevel = value } + override val maxBatteryLevel: Decimal get() = parent.maxBatteryLevel override val energyFlow: FlowDirection get() = parent.energyFlow - var lastTickReceive = Decimal.ZERO - private set - - var lastTickTransfer = Decimal.ZERO - private set - - var tick = 0 - private set - - private val historyReceiveInternal = ArrayList() - private val historyTransferInternal = ArrayList() + private val historyReceiveInternal = ArrayList(HISTORY_SIZE) + private val historyTransferInternal = ArrayList(HISTORY_SIZE) val historyReceive: List = Collections.unmodifiableList(historyReceiveInternal) val historyTransfer: List = Collections.unmodifiableList(historyTransferInternal) + val lastTickReceive + get() = historyReceiveInternal[tick] + + val lastTickTransfer + get() = historyTransferInternal[tick] + + private var thisTickReceive = Decimal.ZERO + private var thisTickTransfer = Decimal.ZERO + + var tick = 0 + private set + init { for (i in 0 until HISTORY_SIZE) { historyReceiveInternal.add(Decimal.ZERO) @@ -72,7 +81,7 @@ class ProfiledEnergyStorage(val parent: E) : IMattery private fun recordTransfer(value: Decimal, simulate: Boolean): Decimal { if (!simulate) { - lastTickTransfer += value + thisTickTransfer += value } return value @@ -80,75 +89,57 @@ class ProfiledEnergyStorage(val parent: E) : IMattery private fun recordReceive(value: Decimal, simulate: Boolean): Decimal { if (!simulate) { - lastTickReceive += value + thisTickReceive += value } return value } - override fun tick() { + private fun tick() { tick = (tick + 1) % HISTORY_SIZE - historyReceiveInternal[tick] = lastTickReceive - historyTransferInternal[tick] = lastTickTransfer - lastTickReceive = Decimal.ZERO - lastTickTransfer = Decimal.ZERO + historyReceiveInternal[tick] = thisTickReceive + historyTransferInternal[tick] = thisTickTransfer + + thisTickReceive = Decimal.ZERO + thisTickTransfer = Decimal.ZERO } - override fun serializeNBT(): CompoundTag { - val tag: CompoundTag + val savedata: INBTSerializable = object : INBTSerializable { + override fun serializeNBT(): CompoundTag { + return CompoundTag().also { tag -> + tag["historyReceive"] = ListTag().also { + for (value in historyReceiveInternal) { + it.add(value.serializeNBT()) + } + } - if (parent is INBTSerializable<*>) { - tag = (parent as INBTSerializable).serializeNBT() ?: CompoundTag() - } else { - tag = CompoundTag() - } + tag["historyTransfer"] = ListTag().also { + for (value in historyTransferInternal) { + it.add(value.serializeNBT()) + } + } - tag["historyReceive"] = ListTag().also { - for (value in historyReceiveInternal) { - it.add(value.serializeNBT()) + tag["historyTick"] = tick } } - tag["historyTransfer"] = ListTag().also { - for (value in historyTransferInternal) { - it.add(value.serializeNBT()) - } - } - - tag["historyTick"] = tick - tag["lastTickReceive"] = lastTickReceive - tag["lastTickTransfer"] = lastTickTransfer - - return tag - } - - override fun deserializeNBT(nbt: CompoundTag?) { - if (parent is INBTSerializable<*>) { - (parent as INBTSerializable).deserializeNBT(nbt) - } - - if (nbt != null) { - historyReceiveInternal.clear() - historyTransferInternal.clear() + override fun deserializeNBT(nbt: CompoundTag?) { + tick = 0 + thisTickReceive = Decimal.ZERO + thisTickTransfer = Decimal.ZERO for (i in 0 until HISTORY_SIZE) { - historyReceiveInternal.add(Decimal.ZERO) - historyTransferInternal.add(Decimal.ZERO) + historyReceiveInternal[i] = Decimal.ZERO + historyTransferInternal[i] = Decimal.ZERO } + nbt ?: return + nbt.map("historyTick") { it: NumericTag -> tick = it.asInt } - nbt.map("lastTickReceive") { it: Tag -> - lastTickReceive = Decimal.deserializeNBT(it) - } - - nbt.map("lastTickTransfer") { it: Tag -> - lastTickReceive = Decimal.deserializeNBT(it) - } - nbt.map("historyReceive") { it: ListTag -> for (i in 0 until HISTORY_SIZE.coerceAtMost(it.size)) { historyReceiveInternal[i] = Decimal.deserializeNBT(it[i]) @@ -163,7 +154,42 @@ class ProfiledEnergyStorage(val parent: E) : IMattery } } + override fun serializeNBT(): CompoundTag { + val tag: CompoundTag + + if (parent is INBTSerializable<*>) { + tag = (parent as INBTSerializable).serializeNBT() ?: CompoundTag() + } else { + tag = CompoundTag() + } + + val tag2 = savedata.serializeNBT()!! + + for (k in tag2.allKeys) { + tag[k] = tag2[k]!! + } + + return tag + } + + override fun deserializeNBT(nbt: CompoundTag?) { + if (parent is INBTSerializable<*>) { + (parent as INBTSerializable).deserializeNBT(nbt) + } + + savedata.deserializeNBT(nbt) + } + companion object { const val HISTORY_SIZE = 20 + private val storages = ArrayList>>() + + // после раздумий, наиболее корректное место для обновления состояния профилированных + // хранилищ энергии будет после всех остальных хуков на тики после тика сервера + // разумеется, такое решение может несколько снизить производительность сервера, + // но ничего страшного произойти не должно + internal fun onServerPostTick() { + storages.forValidRefs { it.tick() } + } } } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/matter/MatterBottlerScreen.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/matter/MatterBottlerScreen.kt index e6bd13407..def4b18a2 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/matter/MatterBottlerScreen.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/matter/MatterBottlerScreen.kt @@ -11,6 +11,7 @@ import ru.dbotthepony.mc.otm.client.screen.panels.slot.BatterySlotPanel import ru.dbotthepony.mc.otm.client.screen.panels.slot.MatterCapacitorSlotPanel import ru.dbotthepony.mc.otm.client.screen.widget.MatterGaugePanel import ru.dbotthepony.mc.otm.client.screen.widget.PowerGaugePanel +import ru.dbotthepony.mc.otm.client.screen.widget.ProfiledPowerGaugePanel import ru.dbotthepony.mc.otm.client.screen.widget.ProgressGaugePanel import ru.dbotthepony.mc.otm.menu.matter.MatterBottlerMenu @@ -22,7 +23,7 @@ class MatterBottlerScreen(menu: MatterBottlerMenu, inventory: Inventory, title: override fun makeMainFrame(): FramePanel> { val frame = super.makeMainFrame()!! - val p = PowerGaugePanel(this, frame, menu.powerWidget, LEFT_MARGIN, GAUGE_TOP_WITH_SLOT) + val p = ProfiledPowerGaugePanel(this, frame, menu.profiledEnergy, LEFT_MARGIN, GAUGE_TOP_WITH_SLOT) MatterGaugePanel(this, frame, menu.matterWidget, LEFT_MARGIN + p.width, GAUGE_TOP_WITH_SLOT) BatterySlotPanel(this, frame, menu.batterySlot, LEFT_MARGIN, SLOT_TOP_UNDER_GAUGE) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/matter/MatterDecomposerScreen.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/matter/MatterDecomposerScreen.kt index de53ba607..81a6488d0 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/matter/MatterDecomposerScreen.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/matter/MatterDecomposerScreen.kt @@ -10,6 +10,7 @@ import ru.dbotthepony.mc.otm.client.screen.panels.button.makeDeviceControls import ru.dbotthepony.mc.otm.client.screen.panels.slot.SlotPanel import ru.dbotthepony.mc.otm.client.screen.widget.MatterGaugePanel import ru.dbotthepony.mc.otm.client.screen.widget.PowerGaugePanel +import ru.dbotthepony.mc.otm.client.screen.widget.ProfiledPowerGaugePanel import ru.dbotthepony.mc.otm.client.screen.widget.ProgressGaugePanel class MatterDecomposerScreen(p_97741_: MatterDecomposerMenu, p_97742_: Inventory, p_97743_: Component) : @@ -18,7 +19,7 @@ class MatterDecomposerScreen(p_97741_: MatterDecomposerMenu, p_97742_: Inventory override fun makeMainFrame(): FramePanel> { val frame = super.makeMainFrame()!! - val m = PowerGaugePanel(this, frame, menu.powerWidget, LEFT_MARGIN, GAUGE_TOP_WITH_SLOT) + val m = ProfiledPowerGaugePanel(this, frame, menu.profiledEnergy, LEFT_MARGIN, GAUGE_TOP_WITH_SLOT) MatterGaugePanel(this, frame, menu.matterWidget, LEFT_MARGIN + m.width, GAUGE_TOP_WITH_SLOT) BatterySlotPanel(this, frame, menu.batterySlot, LEFT_MARGIN, SLOT_TOP_UNDER_GAUGE) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/matter/MatterReconstructorScreen.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/matter/MatterReconstructorScreen.kt index cbfdf5b89..29c2c6163 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/matter/MatterReconstructorScreen.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/matter/MatterReconstructorScreen.kt @@ -13,6 +13,7 @@ import ru.dbotthepony.mc.otm.client.screen.panels.slot.BatterySlotPanel import ru.dbotthepony.mc.otm.client.screen.panels.slot.SlotPanel import ru.dbotthepony.mc.otm.client.screen.widget.MatterGaugePanel import ru.dbotthepony.mc.otm.client.screen.widget.PowerGaugePanel +import ru.dbotthepony.mc.otm.client.screen.widget.ProfiledPowerGaugePanel import ru.dbotthepony.mc.otm.client.screen.widget.ProgressGaugePanel import ru.dbotthepony.mc.otm.menu.matter.MatterReconstructorMenu @@ -20,7 +21,7 @@ class MatterReconstructorScreen(menu: MatterReconstructorMenu, inventory: Invent override fun makeMainFrame(): FramePanel> { val frame = super.makeMainFrame()!! - val p = PowerGaugePanel(this, frame, menu.powerWidget, LEFT_MARGIN, GAUGE_TOP_WITH_SLOT) + val p = ProfiledPowerGaugePanel(this, frame, menu.profiledEnergy, LEFT_MARGIN, GAUGE_TOP_WITH_SLOT) MatterGaugePanel(this, frame, menu.matterWidget, LEFT_MARGIN + p.width, GAUGE_TOP_WITH_SLOT) BatterySlotPanel(this, frame, menu.batterySlot, LEFT_MARGIN, SLOT_TOP_UNDER_GAUGE) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/matter/MatterRecyclerScreen.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/matter/MatterRecyclerScreen.kt index cdb8c55ad..3763dee00 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/matter/MatterRecyclerScreen.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/matter/MatterRecyclerScreen.kt @@ -9,6 +9,7 @@ import ru.dbotthepony.mc.otm.client.screen.panels.button.makeDeviceControls import ru.dbotthepony.mc.otm.client.screen.panels.slot.SlotPanel import ru.dbotthepony.mc.otm.client.screen.widget.MatterGaugePanel import ru.dbotthepony.mc.otm.client.screen.widget.PowerGaugePanel +import ru.dbotthepony.mc.otm.client.screen.widget.ProfiledPowerGaugePanel import ru.dbotthepony.mc.otm.client.screen.widget.ProgressGaugePanel import ru.dbotthepony.mc.otm.menu.matter.MatterRecyclerMenu @@ -16,7 +17,7 @@ class MatterRecyclerScreen(menu: MatterRecyclerMenu, inventory: Inventory, title override fun makeMainFrame(): FramePanel> { val frame = super.makeMainFrame()!! - val m = PowerGaugePanel(this, frame, menu.powerWidget, LEFT_MARGIN, GAUGE_TOP_WITH_SLOT) + val m = ProfiledPowerGaugePanel(this, frame, menu.profiledEnergy, LEFT_MARGIN, GAUGE_TOP_WITH_SLOT) MatterGaugePanel(this, frame, menu.matter, LEFT_MARGIN + m.width, GAUGE_TOP_WITH_SLOT) BatterySlotPanel(this, frame, menu.batterySlot, LEFT_MARGIN, SLOT_TOP_UNDER_GAUGE) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/matter/MatterReplicatorScreen.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/matter/MatterReplicatorScreen.kt index 58af3e175..a74d83ae8 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/matter/MatterReplicatorScreen.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/matter/MatterReplicatorScreen.kt @@ -9,6 +9,7 @@ import ru.dbotthepony.mc.otm.client.screen.panels.button.makeDeviceControls import ru.dbotthepony.mc.otm.client.screen.panels.slot.SlotPanel import ru.dbotthepony.mc.otm.client.screen.widget.MatterGaugePanel import ru.dbotthepony.mc.otm.client.screen.widget.PowerGaugePanel +import ru.dbotthepony.mc.otm.client.screen.widget.ProfiledPowerGaugePanel import ru.dbotthepony.mc.otm.client.screen.widget.ProgressGaugePanel import ru.dbotthepony.mc.otm.menu.matter.MatterReplicatorMenu @@ -17,7 +18,7 @@ class MatterReplicatorScreen(p_97741_: MatterReplicatorMenu, p_97742_: Inventory override fun makeMainFrame(): FramePanel> { val frame = super.makeMainFrame()!! - val m = PowerGaugePanel(this, frame, menu.powerWidget, LEFT_MARGIN, GAUGE_TOP_WITH_SLOT) + val m = ProfiledPowerGaugePanel(this, frame, menu.profiledEnergy, LEFT_MARGIN, GAUGE_TOP_WITH_SLOT) MatterGaugePanel(this, frame, menu.matter, LEFT_MARGIN + m.width, GAUGE_TOP_WITH_SLOT) BatterySlotPanel(this, frame, menu.batterySlot, LEFT_MARGIN, SLOT_TOP_UNDER_GAUGE) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/matter/MatterScannerScreen.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/matter/MatterScannerScreen.kt index 201f208bb..3af6b5302 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/matter/MatterScannerScreen.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/matter/MatterScannerScreen.kt @@ -10,14 +10,15 @@ import ru.dbotthepony.mc.otm.client.screen.panels.button.makeDeviceControls import ru.dbotthepony.mc.otm.client.screen.panels.slot.SlotPanel import ru.dbotthepony.mc.otm.client.screen.widget.PatternGaugePanel import ru.dbotthepony.mc.otm.client.screen.widget.PowerGaugePanel +import ru.dbotthepony.mc.otm.client.screen.widget.ProfiledPowerGaugePanel import ru.dbotthepony.mc.otm.client.screen.widget.ProgressGaugePanel class MatterScannerScreen(p_97741_: MatterScannerMenu, p_97742_: Inventory, p_97743_: Component) : MatteryScreen(p_97741_, p_97742_, p_97743_) { - override fun makeMainFrame(): FramePanel> { + override fun makeMainFrame(): FramePanel> { val frame = super.makeMainFrame()!! - val m = PowerGaugePanel(this, frame, menu.powerWidget, LEFT_MARGIN, GAUGE_TOP_WITH_SLOT) + val m = ProfiledPowerGaugePanel(this, frame, menu.profiledEnergy, LEFT_MARGIN, GAUGE_TOP_WITH_SLOT) PatternGaugePanel(this, frame, menu.patterns, LEFT_MARGIN + m.width, GAUGE_TOP_WITH_SLOT) BatterySlotPanel(this, frame, menu.batterySlot, LEFT_MARGIN, SLOT_TOP_UNDER_GAUGE) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/storage/DriveRackScreen.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/storage/DriveRackScreen.kt index 237e9c72e..171e9725c 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/storage/DriveRackScreen.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/storage/DriveRackScreen.kt @@ -15,7 +15,7 @@ class DriveRackScreen(menu: DriveRackMenu, inventory: Inventory, title: Componen override fun makeMainFrame(): FramePanel> { val frame = super.makeMainFrame()!! - WidePowerGaugePanel(this, frame, menu.powerWidget, LEFT_MARGIN, GAUGE_TOP_WITH_SLOT) + WidePowerGaugePanel(this, frame, menu.energyWidget, LEFT_MARGIN, GAUGE_TOP_WITH_SLOT) BatterySlotPanel(this, frame, menu.batterySlot, LEFT_MARGIN, SLOT_TOP_UNDER_GAUGE) SlotPanel(this, frame, menu.storageSlots[0], 71f, 32f) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/storage/DriveViewerScreen.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/storage/DriveViewerScreen.kt index ca4ec029c..f7ba4e1c8 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/storage/DriveViewerScreen.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/storage/DriveViewerScreen.kt @@ -50,7 +50,7 @@ class DriveViewerScreen(menu: DriveViewerMenu, inventory: Inventory, title: Comp } }) - views.add(PowerGaugePanel(this, frame, menu.powerWidget, 8f, 16f)) + views.add(PowerGaugePanel(this, frame, menu.energyWidget, 8f, 16f)) views.add(BatterySlotPanel(this, frame, menu.batterySlot, 8f, 67f)) views.add(SlotPanel(this, frame, menu.driveSlot, 8f, 85f)) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/storage/ItemMonitorScreen.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/storage/ItemMonitorScreen.kt index 902b1e211..b920f15a4 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/storage/ItemMonitorScreen.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/storage/ItemMonitorScreen.kt @@ -205,7 +205,7 @@ class ItemMonitorScreen(menu: ItemMonitorMenu, inventory: Inventory, title: Comp leftStrip.height += it.height } - WidePowerGaugePanel(this, leftStrip, menu.powerWidget).also { + WidePowerGaugePanel(this, leftStrip, menu.energyWidget).also { it.dock = Dock.FILL it.dockResize = DockResizeMode.NONE leftStrip.height += it.height diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/storage/StorageBusScreen.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/storage/StorageBusScreen.kt index 1b9314e50..71e3497d2 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/storage/StorageBusScreen.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/storage/StorageBusScreen.kt @@ -18,7 +18,7 @@ class StorageBusScreen(menu: StorageBusMenu, inventory: Inventory, title: Compon override fun makeMainFrame(): FramePanel> { val frame = super.makeMainFrame()!! - WidePowerGaugePanel(this, frame, menu.powerWidget, LEFT_MARGIN, GAUGE_TOP_WITH_SLOT) + WidePowerGaugePanel(this, frame, menu.energyWidget, LEFT_MARGIN, GAUGE_TOP_WITH_SLOT) BatterySlotPanel(this, frame, menu.batterySlot, LEFT_MARGIN, SLOT_TOP_UNDER_GAUGE) for (row in 0 .. 2) { diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/storage/StorageExporterScreen.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/storage/StorageExporterScreen.kt index c896eb6e9..8299b3879 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/storage/StorageExporterScreen.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/storage/StorageExporterScreen.kt @@ -18,7 +18,7 @@ class StorageExporterScreen(menu: StorageExporterMenu, inventory: Inventory, tit override fun makeMainFrame(): FramePanel> { val frame = super.makeMainFrame()!! - WidePowerGaugePanel(this, frame, menu.powerWidget, LEFT_MARGIN, GAUGE_TOP_WITH_SLOT) + WidePowerGaugePanel(this, frame, menu.energyWidget, LEFT_MARGIN, GAUGE_TOP_WITH_SLOT) BatterySlotPanel(this, frame, menu.batterySlot, LEFT_MARGIN, SLOT_TOP_UNDER_GAUGE) for (row in 0 .. 2) { diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/storage/StorageImporterScreen.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/storage/StorageImporterScreen.kt index 19ea22c86..97ad88d5e 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/storage/StorageImporterScreen.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/storage/StorageImporterScreen.kt @@ -18,7 +18,7 @@ class StorageImporterScreen(menu: StorageImporterMenu, inventory: Inventory, tit override fun makeMainFrame(): FramePanel> { val frame = super.makeMainFrame()!! - WidePowerGaugePanel(this, frame, menu.powerWidget, LEFT_MARGIN, GAUGE_TOP_WITH_SLOT) + WidePowerGaugePanel(this, frame, menu.energyWidget, LEFT_MARGIN, GAUGE_TOP_WITH_SLOT) BatterySlotPanel(this, frame, menu.batterySlot, LEFT_MARGIN, SLOT_TOP_UNDER_GAUGE) for (row in 0 .. 2) { diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/storage/StoragePowerSupplierScreen.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/storage/StoragePowerSupplierScreen.kt index dd113f6e1..69a5f9cf3 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/storage/StoragePowerSupplierScreen.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/storage/StoragePowerSupplierScreen.kt @@ -18,7 +18,7 @@ class StoragePowerSupplierScreen(menu: StoragePowerSupplierMenu, inventory: Inve override fun makeMainFrame(): FramePanel> { val frame = FramePanel(this, width = 200f, height = 60f, title) - HorizontalPowerGaugePanel(this, frame, menu.powerWidget).also { + HorizontalPowerGaugePanel(this, frame, menu.energyWidget).also { it.dock = Dock.BOTTOM it.dockResize = DockResizeMode.NONE } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/tech/AndroidStationScreen.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/tech/AndroidStationScreen.kt index d492f5f75..51d1fc00c 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/tech/AndroidStationScreen.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/tech/AndroidStationScreen.kt @@ -35,6 +35,7 @@ import ru.dbotthepony.mc.otm.client.screen.panels.slot.BatterySlotPanel import ru.dbotthepony.mc.otm.client.screen.panels.slot.EquipmentBatterySlotPanel import ru.dbotthepony.mc.otm.client.screen.panels.util.DraggableCanvasPanel import ru.dbotthepony.mc.otm.client.screen.widget.WidePowerGaugePanel +import ru.dbotthepony.mc.otm.client.screen.widget.WideProfiledPowerGaugePanel import ru.dbotthepony.mc.otm.core.math.RGBAColor import ru.dbotthepony.mc.otm.core.ifPresentK import ru.dbotthepony.mc.otm.menu.tech.AndroidStationMenu @@ -421,7 +422,7 @@ private class AndroidResearchButton( override fun mouseClickedInner(x: Double, y: Double, button: Int): Boolean { if (button == InputConstants.MOUSE_BUTTON_LEFT && minecraft.player?.isSpectator != true) { - if (node.canResearch && !node.isResearched && (parent?.screen as AndroidStationScreen).menu.powerWidget.level >= AndroidStationBlockEntity.ENERGY_PER_RESEARCH) { + if (node.canResearch && !node.isResearched && (parent?.screen as AndroidStationScreen).menu.energyWidget.level >= AndroidStationBlockEntity.ENERGY_PER_RESEARCH) { if (node.type.flatBlocking.isNotEmpty()) { queryUser( TranslatableComponent("otm.android_station.research.confirm", node.type.displayName), @@ -448,7 +449,7 @@ private class AndroidResearchButton( if (isHovered) { val list = ArrayList().also { it.addAll(node.screenTooltipLines) } - val enoughPower = (parent?.screen as AndroidStationScreen).menu.powerWidget.level >= AndroidStationBlockEntity.ENERGY_PER_RESEARCH + val enoughPower = (parent?.screen as AndroidStationScreen).menu.energyWidget.level >= AndroidStationBlockEntity.ENERGY_PER_RESEARCH if (node.isResearched) { list.add(TranslatableComponent("otm.android_station.research.researched").withStyle(ChatFormatting.DARK_AQUA)) @@ -680,10 +681,10 @@ class AndroidStationScreen constructor(p_97741_: AndroidStationMenu, p_97742_: I } override fun innerRender(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float) { - if (menu.powerWidget.level >= AndroidStationBlockEntity.ENERGY_PER_RESEARCH) { + if (menu.energyWidget.level >= AndroidStationBlockEntity.ENERGY_PER_RESEARCH) { text = POWER_OK color = RGBAColor.LIGHT_GREEN - } else if (menu.powerWidget.level >= AndroidStationBlockEntity.ENERGY_PER_OPERATION) { + } else if (menu.energyWidget.level >= AndroidStationBlockEntity.ENERGY_PER_OPERATION) { text = LOW_POWER_1 color = RGBAColor.DARK_RED } else { @@ -700,7 +701,7 @@ class AndroidStationScreen constructor(p_97741_: AndroidStationMenu, p_97742_: I stripLeft.dock = Dock.LEFT stripLeft.dockRight = 3f - WidePowerGaugePanel(this, stripLeft, menu.powerWidget).also { + WideProfiledPowerGaugePanel(this, stripLeft, menu.profiledEnergy).also { it.dock = Dock.TOP } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/tech/BatteryBankScreen.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/tech/BatteryBankScreen.kt index 3555ddb66..6b8035b4b 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/tech/BatteryBankScreen.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/tech/BatteryBankScreen.kt @@ -7,7 +7,7 @@ import ru.dbotthepony.mc.otm.client.screen.MatteryScreen import ru.dbotthepony.mc.otm.client.screen.panels.slot.BatterySlotPanel import ru.dbotthepony.mc.otm.client.screen.panels.FramePanel import ru.dbotthepony.mc.otm.client.screen.panels.button.makeDeviceControls -import ru.dbotthepony.mc.otm.client.screen.widget.WidePowerGaugePanel +import ru.dbotthepony.mc.otm.client.screen.widget.WideProfiledPowerGaugePanel class BatteryBankScreen(menu: BatteryBankMenu, p_97742_: Inventory, p_97743_: Component) : MatteryScreen(menu, p_97742_, p_97743_) { @@ -15,7 +15,7 @@ class BatteryBankScreen(menu: BatteryBankMenu, p_97742_: Inventory, p_97743_: Co override fun makeMainFrame(): FramePanel> { val frame = super.makeMainFrame()!! - WidePowerGaugePanel(this, frame, menu.powerLevel, LEFT_MARGIN, GAUGE_TOP_WITHOUT_SLOT) + WideProfiledPowerGaugePanel(this, frame, menu.powerLevel, LEFT_MARGIN, GAUGE_TOP_WITHOUT_SLOT) for (i in 0 .. 5) BatterySlotPanel(this, frame, menu.storageSlots[i], 44f + 18 * i, 32f) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/tech/EnergyServoScreen.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/tech/EnergyServoScreen.kt index c167d665d..52fa32c17 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/tech/EnergyServoScreen.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/tech/EnergyServoScreen.kt @@ -16,6 +16,7 @@ import ru.dbotthepony.mc.otm.client.screen.panels.makeCuriosPanel import ru.dbotthepony.mc.otm.client.screen.widget.HorizontalPowerGaugePanel import ru.dbotthepony.mc.otm.client.screen.widget.ProgressGaugePanel import ru.dbotthepony.mc.otm.client.screen.widget.TallHorizontalPowerGaugePanel +import ru.dbotthepony.mc.otm.client.screen.widget.TallHorizontalProfiledPowerGaugePanel import ru.dbotthepony.mc.otm.menu.tech.EnergyServoMenu class EnergyServoScreen(menu: EnergyServoMenu, inventory: Inventory, title: Component) : MatteryScreen(menu, inventory, title) { @@ -51,7 +52,7 @@ class EnergyServoScreen(menu: EnergyServoMenu, inventory: Inventory, title: Comp } } - TallHorizontalPowerGaugePanel(this, strip, menu.powerGauge).also { + TallHorizontalProfiledPowerGaugePanel(this, strip, menu.powerGauge).also { it.dock = Dock.LEFT it.dockRight = 2f } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/tech/PlatePressScreen.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/tech/PlatePressScreen.kt index 45b347412..8decb70d3 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/tech/PlatePressScreen.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/tech/PlatePressScreen.kt @@ -16,7 +16,7 @@ class PlatePressScreen(menu: PlatePressMenu, inventory: Inventory, title: Compon override fun makeMainFrame(): FramePanel> { val frame = super.makeMainFrame()!! - WidePowerGaugePanel(this, frame, menu.powerWidget, LEFT_MARGIN, GAUGE_TOP_WITH_SLOT) + WidePowerGaugePanel(this, frame, menu.energyWidget, LEFT_MARGIN, GAUGE_TOP_WITH_SLOT) BatterySlotPanel(this, frame, menu.batterySlot, LEFT_MARGIN, SLOT_TOP_UNDER_GAUGE) SlotPanel(this, frame, menu.inputSlot, 56f, PROGRESS_SLOT_TOP) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/widget/HorizontalPowerGaugePanel.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/widget/HorizontalPowerGaugePanel.kt index e04e54281..1a4df3e36 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/widget/HorizontalPowerGaugePanel.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/widget/HorizontalPowerGaugePanel.kt @@ -6,6 +6,31 @@ import ru.dbotthepony.mc.otm.client.render.UVWindingOrder import ru.dbotthepony.mc.otm.client.render.WidgetLocation import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel import ru.dbotthepony.mc.otm.menu.widget.LevelGaugeWidget +import ru.dbotthepony.mc.otm.menu.widget.ProfiledEnergyGaugeWidget + +private fun PowerGaugePanel<*>.doRender(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float, flop: Boolean) { + if (height >= 18f) { + if (flop) { + HorizontalPowerGaugePanel.GAUGE_BACKGROUND_TALL.render(stack, height = height, width = this.width, winding = UVWindingOrder.U1_V0_U0_V1) + val width = this.width * widget.percentage + HorizontalPowerGaugePanel.GAUGE_FOREGROUND_TALL.renderPartial(stack, x = this.width - width, height = height, width = width, winding = UVWindingOrder.U1_V0_U0_V1) + } else { + HorizontalPowerGaugePanel.GAUGE_BACKGROUND_TALL.render(stack, height = height, width = this.width) + val width = this.width * widget.percentage + HorizontalPowerGaugePanel.GAUGE_FOREGROUND_TALL.renderPartial(stack, height = height, width = width) + } + } else { + if (flop) { + HorizontalPowerGaugePanel.GAUGE_BACKGROUND.render(stack, height = height, width = this.width, winding = UVWindingOrder.U1_V0_U0_V1) + val width = this.width * widget.percentage + HorizontalPowerGaugePanel.GAUGE_FOREGROUND.renderPartial(stack, x = this.width - width, height = height, width = width, winding = UVWindingOrder.U1_V0_U0_V1) + } else { + HorizontalPowerGaugePanel.GAUGE_BACKGROUND.render(stack, height = height, width = this.width) + val width = this.width * widget.percentage + HorizontalPowerGaugePanel.GAUGE_FOREGROUND.renderPartial(stack, height = height, width = width) + } + } +} open class HorizontalPowerGaugePanel( screen: S, @@ -19,27 +44,7 @@ open class HorizontalPowerGaugePanel( var flop = false override fun innerRender(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float) { - if (height >= 18f) { - if (flop) { - GAUGE_BACKGROUND_TALL.render(stack, height = height, width = this.width, winding = UVWindingOrder.U1_V0_U0_V1) - val width = this.width * widget.percentage - GAUGE_FOREGROUND_TALL.renderPartial(stack, x = this.width - width, height = height, width = width, winding = UVWindingOrder.U1_V0_U0_V1) - } else { - GAUGE_BACKGROUND_TALL.render(stack, height = height, width = this.width) - val width = this.width * widget.percentage - GAUGE_FOREGROUND_TALL.renderPartial(stack, height = height, width = width) - } - } else { - if (flop) { - GAUGE_BACKGROUND.render(stack, height = height, width = this.width, winding = UVWindingOrder.U1_V0_U0_V1) - val width = this.width * widget.percentage - GAUGE_FOREGROUND.renderPartial(stack, x = this.width - width, height = height, width = width, winding = UVWindingOrder.U1_V0_U0_V1) - } else { - GAUGE_BACKGROUND.render(stack, height = height, width = this.width) - val width = this.width * widget.percentage - GAUGE_FOREGROUND.renderPartial(stack, height = height, width = width) - } - } + doRender(stack, mouseX, mouseY, partialTick, flop) } companion object { @@ -54,6 +59,7 @@ open class HorizontalPowerGaugePanel( /** * Shortcut to [HorizontalPowerGaugePanel] with doubled height */ +@Suppress("FunctionName") fun TallHorizontalPowerGaugePanel( screen: S, parent: EditablePanel<*>? = null, @@ -63,3 +69,33 @@ fun TallHorizontalPowerGaugePanel( width: Float = HorizontalPowerGaugePanel.GAUGE_BACKGROUND_TALL.width, height: Float = HorizontalPowerGaugePanel.GAUGE_BACKGROUND_TALL.height ) = HorizontalPowerGaugePanel(screen, parent, widget, x, y, width, height) + +open class HorizontalProfiledPowerGaugePanel( + screen: S, + parent: EditablePanel<*>? = null, + widget: ProfiledEnergyGaugeWidget, + x: Float = 0f, + y: Float = 0f, + width: Float = HorizontalPowerGaugePanel.GAUGE_BACKGROUND.width, + height: Float = HorizontalPowerGaugePanel.GAUGE_BACKGROUND.height +) : ProfiledPowerGaugePanel(screen, parent, widget, x, y, width, height) { + var flop = false + + override fun innerRender(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float) { + doRender(stack, mouseX, mouseY, partialTick, flop) + } +} + +/** + * Shortcut to [HorizontalProfiledPowerGaugePanel] with doubled height + */ +@Suppress("FunctionName") +fun TallHorizontalProfiledPowerGaugePanel( + screen: S, + parent: EditablePanel<*>? = null, + widget: ProfiledEnergyGaugeWidget, + x: Float = 0f, + y: Float = 0f, + width: Float = HorizontalPowerGaugePanel.GAUGE_BACKGROUND_TALL.width, + height: Float = HorizontalPowerGaugePanel.GAUGE_BACKGROUND_TALL.height +) = HorizontalProfiledPowerGaugePanel(screen, parent, widget, x, y, width, height) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/MatteryPoweredMenu.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/MatteryPoweredMenu.kt index 5e924f71f..a9b5cec8a 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/MatteryPoweredMenu.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/MatteryPoweredMenu.kt @@ -15,7 +15,7 @@ abstract class MatteryPoweredMenu protected constructor( inventory: Inventory, tile: MatteryPoweredBlockEntity? = null ) : MatteryMenu(menuType, containerID, inventory, tile) { - val powerWidget = LevelGaugeWidget(this, tile?.matteryEnergy) + val energyWidget = LevelGaugeWidget(this, tile?.matteryEnergy) val batterySlot = BatterySlot(tile?.batteryContainer ?: SimpleContainer(1), 0) val redstoneConfig = EnumInputWithFeedback(this) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/matter/MatterBottlerMenu.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/matter/MatterBottlerMenu.kt index dd089b9ed..492ba1891 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/matter/MatterBottlerMenu.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/matter/MatterBottlerMenu.kt @@ -14,6 +14,7 @@ import ru.dbotthepony.mc.otm.menu.widget.ProgressGaugeWidget import ru.dbotthepony.mc.otm.core.orNull import ru.dbotthepony.mc.otm.menu.MatteryPoweredMenu import ru.dbotthepony.mc.otm.menu.MatterySlot +import ru.dbotthepony.mc.otm.menu.widget.ProfiledEnergyGaugeWidget import ru.dbotthepony.mc.otm.registry.MMenus class MatterBottlerMenu @JvmOverloads constructor( @@ -27,6 +28,7 @@ class MatterBottlerMenu @JvmOverloads constructor( val progressWidget = ProgressGaugeWidget(this) val matterWidget = LevelGaugeWidget(this) val storageSlots: List + val profiledEnergy = ProfiledEnergyGaugeWidget(this, tile?.energy, energyWidget) init { val container = tile?.container ?: SimpleContainer(6) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/matter/MatterDecomposerMenu.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/matter/MatterDecomposerMenu.kt index be015e85e..3a2084fff 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/matter/MatterDecomposerMenu.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/matter/MatterDecomposerMenu.kt @@ -15,6 +15,7 @@ import ru.dbotthepony.mc.otm.menu.MatteryPoweredMenu import ru.dbotthepony.mc.otm.menu.MatterySlot import ru.dbotthepony.mc.otm.menu.input.EnergyConfigPlayerInput import ru.dbotthepony.mc.otm.menu.input.ItemConfigPlayerInput +import ru.dbotthepony.mc.otm.menu.widget.ProfiledEnergyGaugeWidget import ru.dbotthepony.mc.otm.registry.MMenus class MatterDecomposerMenu @JvmOverloads constructor( @@ -32,6 +33,7 @@ class MatterDecomposerMenu @JvmOverloads constructor( val matterWidget = LevelGaugeWidget(this, tile?.getCapability(MatteryCapability.MATTER)?.orNull()) val itemConfig = ItemConfigPlayerInput(this, tile?.itemConfig) val energyConfig = EnergyConfigPlayerInput(this, tile?.energyConfig) + val profiledEnergy = ProfiledEnergyGaugeWidget(this, tile?.energy, energyWidget) init { val container = tile?.outputContainer ?: SimpleContainer(2) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/matter/MatterReconstructorMenu.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/matter/MatterReconstructorMenu.kt index 180005809..96e7bb91c 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/matter/MatterReconstructorMenu.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/matter/MatterReconstructorMenu.kt @@ -9,6 +9,7 @@ import ru.dbotthepony.mc.otm.menu.MatterySlot import ru.dbotthepony.mc.otm.menu.input.EnergyConfigPlayerInput import ru.dbotthepony.mc.otm.menu.input.ItemConfigPlayerInput import ru.dbotthepony.mc.otm.menu.widget.LevelGaugeWidget +import ru.dbotthepony.mc.otm.menu.widget.ProfiledEnergyGaugeWidget import ru.dbotthepony.mc.otm.menu.widget.ProgressGaugeWidget import ru.dbotthepony.mc.otm.registry.MMenus @@ -29,6 +30,7 @@ class MatterReconstructorMenu( val energyConfig = EnergyConfigPlayerInput(this, tile?.energyConfig) val itemConfig = ItemConfigPlayerInput(this, tile?.itemConfig) + val profiledEnergy = ProfiledEnergyGaugeWidget(this, tile?.energy, energyWidget) init { addStorageSlot(slot) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/matter/MatterRecyclerMenu.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/matter/MatterRecyclerMenu.kt index c2cb229ac..a999638b2 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/matter/MatterRecyclerMenu.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/matter/MatterRecyclerMenu.kt @@ -10,6 +10,7 @@ import ru.dbotthepony.mc.otm.menu.MatterySlot import ru.dbotthepony.mc.otm.menu.input.EnergyConfigPlayerInput import ru.dbotthepony.mc.otm.menu.input.ItemConfigPlayerInput import ru.dbotthepony.mc.otm.menu.widget.LevelGaugeWidget +import ru.dbotthepony.mc.otm.menu.widget.ProfiledEnergyGaugeWidget import ru.dbotthepony.mc.otm.menu.widget.ProgressGaugeWidget import ru.dbotthepony.mc.otm.registry.MMenus @@ -28,6 +29,7 @@ class MatterRecyclerMenu @JvmOverloads constructor( val matter = LevelGaugeWidget(this, tile?.matter) val itemConfig = ItemConfigPlayerInput(this, tile?.itemConfig) val energyConfig = EnergyConfigPlayerInput(this, tile?.energyConfig) + val profiledEnergy = ProfiledEnergyGaugeWidget(this, tile?.energy, energyWidget) init { addStorageSlot(input) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/matter/MatterReplicatorMenu.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/matter/MatterReplicatorMenu.kt index 67278d79b..09ca29654 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/matter/MatterReplicatorMenu.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/matter/MatterReplicatorMenu.kt @@ -11,6 +11,7 @@ import ru.dbotthepony.mc.otm.menu.MachineOutputSlot import ru.dbotthepony.mc.otm.menu.MatteryPoweredMenu import ru.dbotthepony.mc.otm.menu.input.EnergyConfigPlayerInput import ru.dbotthepony.mc.otm.menu.input.ItemConfigPlayerInput +import ru.dbotthepony.mc.otm.menu.widget.ProfiledEnergyGaugeWidget import ru.dbotthepony.mc.otm.registry.MMenus class MatterReplicatorMenu @JvmOverloads constructor( @@ -23,6 +24,7 @@ class MatterReplicatorMenu @JvmOverloads constructor( val storageSlots: List val itemConfig = ItemConfigPlayerInput(this, tile?.itemConfig) val energyConfig = EnergyConfigPlayerInput(this, tile?.energyConfig) + val profiledEnergy = ProfiledEnergyGaugeWidget(this, tile?.energy, energyWidget) init { val container = tile?.container ?: SimpleContainer(5) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/matter/MatterScannerMenu.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/matter/MatterScannerMenu.kt index ea94cf99a..f07f1d3e3 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/matter/MatterScannerMenu.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/matter/MatterScannerMenu.kt @@ -13,6 +13,7 @@ import ru.dbotthepony.mc.otm.menu.MatteryPoweredMenu import ru.dbotthepony.mc.otm.menu.MatterySlot import ru.dbotthepony.mc.otm.menu.input.EnergyConfigPlayerInput import ru.dbotthepony.mc.otm.menu.input.ItemConfigPlayerInput +import ru.dbotthepony.mc.otm.menu.widget.ProfiledEnergyGaugeWidget import ru.dbotthepony.mc.otm.registry.MMenus class MatterScannerMenu @JvmOverloads constructor( @@ -25,6 +26,7 @@ class MatterScannerMenu @JvmOverloads constructor( val patterns = LevelGaugeWidget(this) val itemConfig = ItemConfigPlayerInput(this, tile?.itemConfig) val energyConfig = EnergyConfigPlayerInput(this, tile?.energyConfig) + val profiledEnergy = ProfiledEnergyGaugeWidget(this, tile?.energy, energyWidget) init { val container = tile?.container ?: SimpleContainer(1) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/tech/AndroidStationMenu.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/tech/AndroidStationMenu.kt index 36fc131b0..a96447a9b 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/tech/AndroidStationMenu.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/tech/AndroidStationMenu.kt @@ -13,6 +13,7 @@ import ru.dbotthepony.mc.otm.capability.matteryPlayer import ru.dbotthepony.mc.otm.menu.MatteryPoweredMenu import ru.dbotthepony.mc.otm.menu.MatterySlot import ru.dbotthepony.mc.otm.menu.input.EnergyConfigPlayerInput +import ru.dbotthepony.mc.otm.menu.widget.ProfiledEnergyGaugeWidget import ru.dbotthepony.mc.otm.registry.MMenus import kotlin.reflect.KMutableProperty0 @@ -51,7 +52,7 @@ class AndroidStationMenu @JvmOverloads constructor( } override fun removeItem(p_18942_: Int, p_18943_: Int): ItemStack { - if (p_18942_ != 0 || powerWidget.level < AndroidStationBlockEntity.ENERGY_PER_OPERATION || item.isEmpty) + if (p_18942_ != 0 || energyWidget.level < AndroidStationBlockEntity.ENERGY_PER_OPERATION || item.isEmpty) return ItemStack.EMPTY (tile as AndroidStationBlockEntity).energy.extractEnergy(AndroidStationBlockEntity.ENERGY_PER_OPERATION, false) @@ -94,7 +95,7 @@ class AndroidStationMenu @JvmOverloads constructor( return super.mayPickup(player) && tile.energy.batteryLevel >= AndroidStationBlockEntity.ENERGY_PER_OPERATION } - return super.mayPickup(player) && powerWidget.level >= AndroidStationBlockEntity.ENERGY_PER_OPERATION + return super.mayPickup(player) && energyWidget.level >= AndroidStationBlockEntity.ENERGY_PER_OPERATION } override fun mayPlace(itemStack: ItemStack): Boolean { @@ -102,7 +103,7 @@ class AndroidStationMenu @JvmOverloads constructor( return tile.energy.batteryLevel >= AndroidStationBlockEntity.ENERGY_PER_OPERATION && condition.invoke(itemStack) } - return powerWidget.level >= AndroidStationBlockEntity.ENERGY_PER_OPERATION && condition.invoke(itemStack) + return energyWidget.level >= AndroidStationBlockEntity.ENERGY_PER_OPERATION && condition.invoke(itemStack) } } @@ -112,6 +113,7 @@ class AndroidStationMenu @JvmOverloads constructor( val equipment = makeEquipmentSlots() val energyConfig = EnergyConfigPlayerInput(this, tile?.energyConfig) + val profiledEnergy = ProfiledEnergyGaugeWidget(this, tile?.energy, energyWidget) init { addInventorySlots() diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/tech/BatteryBankMenu.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/tech/BatteryBankMenu.kt index 3b7ae1ab8..4483e591d 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/tech/BatteryBankMenu.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/tech/BatteryBankMenu.kt @@ -16,6 +16,7 @@ import ru.dbotthepony.mc.otm.menu.MatterySlot import ru.dbotthepony.mc.otm.menu.input.EnergyConfigPlayerInput import ru.dbotthepony.mc.otm.menu.input.EnumInputWithFeedback import ru.dbotthepony.mc.otm.menu.input.ItemConfigPlayerInput +import ru.dbotthepony.mc.otm.menu.widget.ProfiledEnergyGaugeWidget import ru.dbotthepony.mc.otm.registry.MMenus class BatteryBankMenu @JvmOverloads constructor( @@ -23,7 +24,7 @@ class BatteryBankMenu @JvmOverloads constructor( inventory: Inventory, tile: BatteryBankBlockEntity? = null, ) : MatteryMenu(MMenus.BATTERY_BANK, p_38852_, inventory, tile) { - val powerLevel: LevelGaugeWidget + val powerLevel = ProfiledEnergyGaugeWidget(this, tile?.energyConfig?.capability) val storageSlots: List val redstone = EnumInputWithFeedback(this, RedstoneSetting::class.java) val energyConfig = EnergyConfigPlayerInput(this, allowPull = false, allowPush = true) @@ -37,7 +38,6 @@ class BatteryBankMenu @JvmOverloads constructor( } val container: Container = tile?.container ?: SimpleContainer(BatteryBankBlockEntity.CAPACITY) - powerLevel = LevelGaugeWidget(this, tile?.getCapability(MatteryCapability.ENERGY)?.orNull()) storageSlots = immutableList(BatteryBankBlockEntity.CAPACITY) { addStorageSlot(BatterySlot(container, it)) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/tech/EnergyServoMenu.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/tech/EnergyServoMenu.kt index 902116b03..cb8ce6b39 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/tech/EnergyServoMenu.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/tech/EnergyServoMenu.kt @@ -12,6 +12,7 @@ import ru.dbotthepony.mc.otm.menu.input.EnergyConfigPlayerInput import ru.dbotthepony.mc.otm.menu.input.EnumInputWithFeedback import ru.dbotthepony.mc.otm.menu.input.ItemConfigPlayerInput import ru.dbotthepony.mc.otm.menu.widget.LevelGaugeWidget +import ru.dbotthepony.mc.otm.menu.widget.ProfiledEnergyGaugeWidget import ru.dbotthepony.mc.otm.registry.MMenus class EnergyServoMenu @JvmOverloads constructor( @@ -33,7 +34,7 @@ class EnergyServoMenu @JvmOverloads constructor( val equipment = makeEquipmentSlots(mapMoveToExternal = true) - val powerGauge = LevelGaugeWidget(this, tile?.energy) + val powerGauge = ProfiledEnergyGaugeWidget(this, tile?.energy) val itemConfig = ItemConfigPlayerInput(this, tile?.itemConfig) val energyConfig = EnergyConfigPlayerInput(this, tile?.energyConfig, allowPull = true, allowPush = true) val redstoneConfig = EnumInputWithFeedback(this) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/tech/PlatePressMenu.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/tech/PlatePressMenu.kt index eecbe1063..63bdd4b0f 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/tech/PlatePressMenu.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/tech/PlatePressMenu.kt @@ -9,6 +9,7 @@ import ru.dbotthepony.mc.otm.menu.MatteryPoweredMenu import ru.dbotthepony.mc.otm.menu.MatterySlot import ru.dbotthepony.mc.otm.menu.input.EnergyConfigPlayerInput import ru.dbotthepony.mc.otm.menu.input.ItemConfigPlayerInput +import ru.dbotthepony.mc.otm.menu.widget.ProfiledEnergyGaugeWidget import ru.dbotthepony.mc.otm.menu.widget.ProgressGaugeWidget import ru.dbotthepony.mc.otm.registry.MMenus @@ -23,6 +24,7 @@ class PlatePressMenu @JvmOverloads constructor( val progressGauge = ProgressGaugeWidget(this, tile) val itemConfig = ItemConfigPlayerInput(this, tile?.itemConfig, allowPush = true) val energyConfig = EnergyConfigPlayerInput(this, tile?.energyConfig, allowPull = true) + val profiledEnergy = ProfiledEnergyGaugeWidget(this, tile?.energy, energyWidget) init { addStorageSlot(inputSlot) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/widget/ProfiledEnergyGaugeWidget.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/widget/ProfiledEnergyGaugeWidget.kt index 9bcae5438..1a63d3dd7 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/widget/ProfiledEnergyGaugeWidget.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/widget/ProfiledEnergyGaugeWidget.kt @@ -33,8 +33,8 @@ class ProfiledEnergyGaugeWidget(synchronizer: FieldSynchronizer, val gauge: Leve constructor(menu: MatteryMenu, storage: ProfiledEnergyStorage<*>?, gauge: LevelGaugeWidget = LevelGaugeWidget(menu)) : this(menu.mSynchronizer, storage, gauge = gauge) constructor(menu: MatteryMenu, gauge: LevelGaugeWidget = LevelGaugeWidget(menu)) : this(menu.mSynchronizer, gauge = gauge) - constructor(menu: MatteryPoweredMenu, storage: ProfiledEnergyStorage<*>?) : this(menu.mSynchronizer, storage, menu.powerWidget) - constructor(menu: MatteryPoweredMenu) : this(menu.mSynchronizer, menu.powerWidget) + constructor(menu: MatteryPoweredMenu, storage: ProfiledEnergyStorage<*>?) : this(menu.mSynchronizer, storage, menu.energyWidget) + constructor(menu: MatteryPoweredMenu) : this(menu.mSynchronizer, menu.energyWidget) fun with(storage: ProfiledEnergyStorage<*>): ProfiledEnergyGaugeWidget { gauge.with(storage)