From 4fc646a13a23ea025d61ce217f9ab26fe2c5cfae Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Wed, 26 Mar 2025 18:52:26 +0700 Subject: [PATCH] Energy counter "pull" mode --- .../ru/dbotthepony/mc/otm/datagen/lang/English.kt | 2 ++ .../ru/dbotthepony/mc/otm/datagen/lang/Russian.kt | 2 ++ .../block/entity/tech/EnergyCounterBlockEntity.kt | 13 ++++++++++--- .../otm/client/screen/tech/EnergyCounterScreen.kt | 14 +++++++++++++- .../mc/otm/menu/tech/EnergyCounterMenu.kt | 3 +++ 5 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/lang/English.kt b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/lang/English.kt index 67ead1708..33c067834 100644 --- a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/lang/English.kt +++ b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/lang/English.kt @@ -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") diff --git a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/lang/Russian.kt b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/lang/Russian.kt index cc3b3a7d4..a79597b28 100644 --- a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/lang/Russian.kt +++ b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/lang/Russian.kt @@ -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", "Генерирует энергию сжигая твёрдое топливо") diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/EnergyCounterBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/EnergyCounterBlockEntity.kt index 80b12d46f..790067c07 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/EnergyCounterBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/tech/EnergyCounterBlockEntity.kt @@ -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 diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/tech/EnergyCounterScreen.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/tech/EnergyCounterScreen.kt index b552b93a1..8ddd297a5 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/tech/EnergyCounterScreen.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/tech/EnergyCounterScreen.kt @@ -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 } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/tech/EnergyCounterMenu.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/tech/EnergyCounterMenu.kt index 0f917784e..5849e82e4 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/tech/EnergyCounterMenu.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/tech/EnergyCounterMenu.kt @@ -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)