Add profiled energy storage to most of machines

This commit is contained in:
DBotThePony 2023-04-15 14:09:24 +07:00
parent 8afa21ae16
commit ba326b9fb8
Signed by: DBot
GPG Key ID: DCC23B5715498507
43 changed files with 227 additions and 127 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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<MatteryWorkerBlockEntity.ItemJob>(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 {

View File

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

View File

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

View File

@ -78,7 +78,6 @@ class ChemicalGeneratorBlockEntity(pos: BlockPos, state: BlockState) : MatteryDe
override fun tick() {
super.tick()
energy.tick()
if (workTicks > 0) {
workTicks--

View File

@ -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<IMatteryEnergyStorage> = 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(

View File

@ -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<MatteryWorkerBlockEntity.ItemJob>(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)

View File

@ -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<E : IMatteryEnergyStorage>(val parent: E) : IMatteryEnergyStorage, ITickable, INBTSerializable<CompoundTag?> {
class ProfiledEnergyStorage<E : IMatteryEnergyStorage>(val parent: E) : IMatteryEnergyStorage, INBTSerializable<CompoundTag?> {
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<E : IMatteryEnergyStorage>(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<Decimal>()
private val historyTransferInternal = ArrayList<Decimal>()
private val historyReceiveInternal = ArrayList<Decimal>(HISTORY_SIZE)
private val historyTransferInternal = ArrayList<Decimal>(HISTORY_SIZE)
val historyReceive: List<Decimal> = Collections.unmodifiableList(historyReceiveInternal)
val historyTransfer: List<Decimal> = 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<E : IMatteryEnergyStorage>(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<E : IMatteryEnergyStorage>(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<CompoundTag?> = object : INBTSerializable<CompoundTag?> {
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<CompoundTag?>).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<CompoundTag?>).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<E : IMatteryEnergyStorage>(val parent: E) : IMattery
}
}
override fun serializeNBT(): CompoundTag {
val tag: CompoundTag
if (parent is INBTSerializable<*>) {
tag = (parent as INBTSerializable<CompoundTag?>).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<CompoundTag?>).deserializeNBT(nbt)
}
savedata.deserializeNBT(nbt)
}
companion object {
const val HISTORY_SIZE = 20
private val storages = ArrayList<WeakReference<ProfiledEnergyStorage<*>>>()
// после раздумий, наиболее корректное место для обновления состояния профилированных
// хранилищ энергии будет после всех остальных хуков на тики после тика сервера
// разумеется, такое решение может несколько снизить производительность сервера,
// но ничего страшного произойти не должно
internal fun onServerPostTick() {
storages.forValidRefs { it.tick() }
}
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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<MatterScannerMenu>(p_97741_, p_97742_, p_97743_) {
override fun makeMainFrame(): FramePanel<out MatteryScreen<*>> {
override fun makeMainFrame(): FramePanel<MatteryScreen<*>> {
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)

View File

@ -15,7 +15,7 @@ class DriveRackScreen(menu: DriveRackMenu, inventory: Inventory, title: Componen
override fun makeMainFrame(): FramePanel<MatteryScreen<*>> {
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)

View File

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

View File

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

View File

@ -18,7 +18,7 @@ class StorageBusScreen(menu: StorageBusMenu, inventory: Inventory, title: Compon
override fun makeMainFrame(): FramePanel<out MatteryScreen<*>> {
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) {

View File

@ -18,7 +18,7 @@ class StorageExporterScreen(menu: StorageExporterMenu, inventory: Inventory, tit
override fun makeMainFrame(): FramePanel<out MatteryScreen<*>> {
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) {

View File

@ -18,7 +18,7 @@ class StorageImporterScreen(menu: StorageImporterMenu, inventory: Inventory, tit
override fun makeMainFrame(): FramePanel<out MatteryScreen<*>> {
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) {

View File

@ -18,7 +18,7 @@ class StoragePowerSupplierScreen(menu: StoragePowerSupplierMenu, inventory: Inve
override fun makeMainFrame(): FramePanel<MatteryScreen<*>> {
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
}

View File

@ -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<Component>().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
}

View File

@ -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<BatteryBankMenu>(menu, p_97742_, p_97743_) {
@ -15,7 +15,7 @@ class BatteryBankScreen(menu: BatteryBankMenu, p_97742_: Inventory, p_97743_: Co
override fun makeMainFrame(): FramePanel<MatteryScreen<*>> {
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)

View File

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

View File

@ -16,7 +16,7 @@ class PlatePressScreen(menu: PlatePressMenu, inventory: Inventory, title: Compon
override fun makeMainFrame(): FramePanel<MatteryScreen<*>> {
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)

View File

@ -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<out S : Screen>(
screen: S,
@ -19,27 +44,7 @@ open class HorizontalPowerGaugePanel<out S : Screen>(
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<out S : Screen>(
/**
* Shortcut to [HorizontalPowerGaugePanel] with doubled height
*/
@Suppress("FunctionName")
fun <S : Screen> TallHorizontalPowerGaugePanel(
screen: S,
parent: EditablePanel<*>? = null,
@ -63,3 +69,33 @@ fun <S : Screen> 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<out S : Screen>(
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<S>(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 <S : Screen> 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)

View File

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

View File

@ -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<MatterySlot>
val profiledEnergy = ProfiledEnergyGaugeWidget(this, tile?.energy, energyWidget)
init {
val container = tile?.container ?: SimpleContainer(6)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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