Update energy counter menu code
This commit is contained in:
parent
4fc646a13a
commit
85dde24e59
@ -17,15 +17,16 @@ import ru.dbotthepony.mc.otm.menu.input.EnumInputWithFeedback
|
||||
import ru.dbotthepony.mc.otm.menu.input.IntInputWithFeedback
|
||||
import ru.dbotthepony.mc.otm.registry.game.MMenus
|
||||
import java.math.BigDecimal
|
||||
import java.util.function.Supplier
|
||||
|
||||
class EnergyCounterMenu(
|
||||
p_38852_: Int,
|
||||
inventory: Inventory,
|
||||
tile: EnergyCounterBlockEntity? = null
|
||||
) : MatteryMenu(MMenus.ENERGY_COUNTER, p_38852_, inventory, tile) {
|
||||
var passed by mSynchronizer.decimal()
|
||||
var lastTick by mSynchronizer.decimal()
|
||||
var maxIO by mSynchronizer.decimal()
|
||||
var passed by mSynchronizer.computedDecimal { tile?.passed ?: Decimal.ZERO }
|
||||
var lastTick by mSynchronizer.computedDecimal { tile?.lastTick ?: Decimal.ZERO }
|
||||
var maxIO by mSynchronizer.computedDecimal { tile?.ioLimit ?: Decimal.ZERO }
|
||||
|
||||
val history5s = tile?.history5s ?: DecimalHistoryChart(1, 100)
|
||||
val history15s = tile?.history15s ?: DecimalHistoryChart(3, 100)
|
||||
@ -62,7 +63,7 @@ class EnergyCounterMenu(
|
||||
}
|
||||
}
|
||||
|
||||
var inputDirection: Direction by mSynchronizer.enum(Direction.UP)
|
||||
val inputDirection: Direction by mSynchronizer.computedEnum { tile?.blockState?.getValue(EnergyCounterBlock.INPUT_DIRECTION) ?: Direction.UP}
|
||||
|
||||
val maxIOInput = decimalInput {
|
||||
if (tile is EnergyCounterBlockEntity) {
|
||||
@ -73,20 +74,4 @@ class EnergyCounterMenu(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun beforeBroadcast() {
|
||||
super.beforeBroadcast()
|
||||
|
||||
if (tile is EnergyCounterBlockEntity) {
|
||||
passed = tile.passed
|
||||
lastTick = tile.lastTick
|
||||
inputDirection = tile.blockState.getValue(EnergyCounterBlock.INPUT_DIRECTION)
|
||||
|
||||
maxIO = tile.ioLimit?.toDecimal() ?: -Decimal.ONE
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val MINUS_ONE = -BigDecimal.ONE
|
||||
}
|
||||
}
|
||||
|
@ -270,6 +270,10 @@ class SynchableGroup : Observer, ISynchable, Iterable<ISynchable> {
|
||||
return add(ListenableDelegate.maskSmart(value, getter, setter), MatteryStreamCodec.Enum(value::class.java))
|
||||
}
|
||||
|
||||
inline fun <reified E : Enum<E>> computedEnum(value: Supplier<E>): SynchableDelegate<E> {
|
||||
return computed(value, MatteryStreamCodec.Enum(E::class.java))
|
||||
}
|
||||
|
||||
fun decimal(value: Decimal = Decimal.ZERO, setter: DelegateSetter<Decimal> = DelegateSetter.passthrough(), getter: DelegateGetter<Decimal> = DelegateGetter.passthrough()): SynchableDelegate<Decimal> {
|
||||
return add(ListenableDelegate.maskSmart(value, getter, setter), StreamCodecs.DECIMAL)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user