Energy counter "pull" mode

This commit is contained in:
DBotThePony 2025-03-26 18:52:26 +07:00
parent ddcfe11780
commit 4fc646a13a
Signed by: DBot
GPG Key ID: DCC23B5715498507
5 changed files with 30 additions and 4 deletions

View File

@ -631,6 +631,8 @@ private fun blocks(provider: MatteryLanguageProvider) {
add(MBlocks.ENERGY_COUNTER[null]!!, "switch", "Switch input facing")
add(MBlocks.ENERGY_COUNTER[null]!!, "limit", "I/O Limit. -1 means no limit")
add(MBlocks.ENERGY_COUNTER[null]!!, "display_this", "Display this information on block's screen")
add(MBlocks.ENERGY_COUNTER[null]!!, "do_pull", "Pull energy from input side and push to output")
add(MBlocks.ENERGY_COUNTER[null]!!, "dont_pull", "Don't pull energy")
addBlock(MBlocks.CHEMICAL_GENERATOR.values, "Chemical Generator")
addBlock(MBlocks.CHEMICAL_GENERATOR.values, "desc", "Generates power by burning solid fuels")

View File

@ -635,6 +635,8 @@ private fun blocks(provider: MatteryLanguageProvider) {
add(MBlocks.ENERGY_COUNTER[null]!!, "switch", "Сменить сторону входа")
add(MBlocks.ENERGY_COUNTER[null]!!, "limit", "Лимит ввода/вывода. -1 для отключения лимитов")
add(MBlocks.ENERGY_COUNTER[null]!!, "display_this", "Отображать эти данные на экране блока")
add(MBlocks.ENERGY_COUNTER[null]!!, "do_pull", "Забирать энергию на входе и выталкивать её на выходе")
add(MBlocks.ENERGY_COUNTER[null]!!, "dont_pull", "Не забирать энергию на входе")
addBlock(MBlocks.CHEMICAL_GENERATOR.values, "Химический генератор")
addBlock(MBlocks.CHEMICAL_GENERATOR.values, "desc", "Генерирует энергию сжигая твёрдое топливо")

View File

@ -31,6 +31,7 @@ import ru.dbotthepony.mc.otm.registry.game.MBlockEntities
class EnergyCounterBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : MatteryDeviceBlockEntity(MBlockEntities.ENERGY_COUNTER, p_155229_, p_155230_) {
var passed by syncher.decimal()
var pullEnergyFromInput by syncher.boolean()
override val blockRotation: BlockRotation by countingLazy(blockStateChangesCounter) {
BlockRotation.of(blockState[EnergyCounterBlock.INPUT_DIRECTION])
@ -86,10 +87,8 @@ class EnergyCounterBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : Mat
savetables.stateful(::history1h)
savetables.stateful(::history6h)
savetables.stateful(::history24h)
}
override fun saveLevel(nbt: CompoundTag, registry: HolderLookup.Provider) {
super.saveLevel(nbt, registry)
savetablesConfig.bool(::pullEnergyFromInput)
}
override fun loadAdditional(nbt: CompoundTag, registry: HolderLookup.Provider) {
@ -267,6 +266,14 @@ class EnergyCounterBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : Mat
override fun tick() {
super.tick()
if (pullEnergyFromInput) {
val input = inputCapability
val output = outputCapability
if (input != null && output != null)
thisTick += moveEnergy(source = input, destination = output, simulate = false)
}
lastTick = thisTick
charts.forEach { it.add(thisTick) }
thisTick = Decimal.ZERO

View File

@ -111,7 +111,19 @@ class EnergyCounterScreen(menu: EnergyCounterMenu, inventory: Inventory, title:
}
}
makeDeviceControls(this, frame, redstoneConfig = menu.redstone)
val controls = makeDeviceControls(this, frame, redstoneConfig = menu.redstone)
controls.addButton(
BooleanButtonPanel.square18(
this,
controls,
menu.pullEnergyFromInput,
iconActive = Widgets18.LEFT_CONTROLS.push,
iconInactive = Widgets18.LEFT_CONTROLS.output,
tooltipActive = TranslatableComponent("block.overdrive_that_matters.energy_counter.do_pull"),
tooltipInactive = TranslatableComponent("block.overdrive_that_matters.energy_counter.dont_pull")
)
)
return frame
}

View File

@ -12,6 +12,7 @@ import ru.dbotthepony.mc.otm.core.chart.DecimalHistoryChart
import ru.dbotthepony.mc.otm.core.math.Decimal
import ru.dbotthepony.mc.otm.core.math.toDecimal
import ru.dbotthepony.mc.otm.menu.MatteryMenu
import ru.dbotthepony.mc.otm.menu.input.BooleanInputWithFeedback
import ru.dbotthepony.mc.otm.menu.input.EnumInputWithFeedback
import ru.dbotthepony.mc.otm.menu.input.IntInputWithFeedback
import ru.dbotthepony.mc.otm.registry.game.MMenus
@ -34,6 +35,8 @@ class EnergyCounterMenu(
val history6h = tile?.history6h ?: DecimalHistoryChart(720 * 6, 100)
val history24h = tile?.history24h ?: DecimalHistoryChart(720 * 24, 100)
val pullEnergyFromInput = BooleanInputWithFeedback(this, tile?.let { it::pullEnergyFromInput })
init {
mSynchronizer.add(history5s)
mSynchronizer.add(history15s)