From 833c5d2780e8522ad9b9dace96525275e8c21f6d Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Sat, 14 May 2022 23:35:30 +0700 Subject: [PATCH] Storage power supplier menu --- .../entity/StoragePowerSupplierBlockEntity.kt | 5 +-- .../screen/StoragePowerSupplierScreen.kt | 34 ++++++++++++++++++ .../mc/otm/menu/StoragePowerSupplierMenu.kt | 35 +++++++++++++++++++ .../ru/dbotthepony/mc/otm/registry/MMenus.kt | 2 ++ 4 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/StoragePowerSupplierScreen.kt create mode 100644 src/main/kotlin/ru/dbotthepony/mc/otm/menu/StoragePowerSupplierMenu.kt diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/StoragePowerSupplierBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/StoragePowerSupplierBlockEntity.kt index 6e32fbd56..48992118b 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/StoragePowerSupplierBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/StoragePowerSupplierBlockEntity.kt @@ -20,6 +20,7 @@ import ru.dbotthepony.mc.otm.capability.transferInner import ru.dbotthepony.mc.otm.core.ImpreciseFraction import ru.dbotthepony.mc.otm.graph.storage.BasicStorageGraphNode import ru.dbotthepony.mc.otm.graph.storage.StorageNetworkGraph +import ru.dbotthepony.mc.otm.menu.StoragePowerSupplierMenu import ru.dbotthepony.mc.otm.registry.MBlockEntities import ru.dbotthepony.mc.otm.registry.MNames import ru.dbotthepony.mc.otm.set @@ -28,8 +29,8 @@ class StoragePowerSupplierBlockEntity(blockPos: BlockPos, blockState: BlockState override val defaultDisplayName: Component get() = MACHINE_NAME - override fun createMenu(containerID: Int, inventory: Inventory, ply: Player): AbstractContainerMenu? { - return null + override fun createMenu(containerID: Int, inventory: Inventory, ply: Player): AbstractContainerMenu { + return StoragePowerSupplierMenu(containerID, inventory, this) } val cell = BasicStorageGraphNode() diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/StoragePowerSupplierScreen.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/StoragePowerSupplierScreen.kt new file mode 100644 index 000000000..d863b9341 --- /dev/null +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/StoragePowerSupplierScreen.kt @@ -0,0 +1,34 @@ +package ru.dbotthepony.mc.otm.client.screen + +import net.minecraft.network.chat.Component +import net.minecraft.network.chat.TranslatableComponent +import net.minecraft.world.entity.player.Inventory +import ru.dbotthepony.mc.otm.client.screen.panels.* +import ru.dbotthepony.mc.otm.client.screen.widget.PowerGaugePanel +import ru.dbotthepony.mc.otm.menu.FormattingHelper + +import ru.dbotthepony.mc.otm.menu.StorageImporterMenu +import ru.dbotthepony.mc.otm.menu.StoragePowerSupplierMenu + +class StoragePowerSupplierScreen(menu: StoragePowerSupplierMenu, inventory: Inventory, title: Component) : + MatteryScreen(menu, inventory, title) { + override fun makeMainFrame(): FramePanel { + val frame = super.makeMainFrame()!! + + PowerGaugePanel(this, frame, menu.powerWidget, LEFT_MARGIN, GAUGE_TOP_WITH_SLOT) + SlotPanel(this, frame, menu.batterySlot, LEFT_MARGIN, SLOT_TOP_UNDER_GAUGE) + + object : Label(this@StoragePowerSupplierScreen, frame, 28f, 17f, width = 140f) { + override fun tick() { + super.tick() + + text = TranslatableComponent( + "otm.item.power.passed", + FormattingHelper.formatPower(menu.totalTransferred.value) + ) + } + } + + return frame + } +} diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/StoragePowerSupplierMenu.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/StoragePowerSupplierMenu.kt new file mode 100644 index 000000000..753ced438 --- /dev/null +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/StoragePowerSupplierMenu.kt @@ -0,0 +1,35 @@ +package ru.dbotthepony.mc.otm.menu + +import net.minecraft.world.entity.player.Inventory +import ru.dbotthepony.mc.otm.block.entity.StorageImporterBlockEntity +import ru.dbotthepony.mc.otm.block.entity.StoragePowerSupplierBlockEntity +import ru.dbotthepony.mc.otm.menu.data.ImpreciseFractionDataContainer +import ru.dbotthepony.mc.otm.menu.widget.BooleanPlayerInputWidget +import ru.dbotthepony.mc.otm.registry.MMenus + +class StoragePowerSupplierMenu @JvmOverloads constructor( + p_38852_: Int, + inventory: Inventory, + tile: StoragePowerSupplierBlockEntity? = null +) : MatteryPoweredMenu( + MMenus.STORAGE_POWER_SUPPLIER, p_38852_, inventory, tile +) { + val totalTransferred = ImpreciseFractionDataContainer() + + init { + addInventorySlots() + + addDataContainer(totalTransferred) + } + + override fun broadcastChanges() { + if (tile is StoragePowerSupplierBlockEntity) { + totalTransferred.value = tile.powerSupplied + } + + super.broadcastChanges() + } + + override fun getWorkingSlotStart() = 0 + override fun getWorkingSlotEnd() = 1 +} diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/registry/MMenus.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/registry/MMenus.kt index c0c926f20..335422e49 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/registry/MMenus.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/registry/MMenus.kt @@ -34,6 +34,7 @@ object MMenus { val STORAGE_BUS: MenuType<*> by registry.register(MNames.STORAGE_BUS) { MenuType(::StorageBusMenu) } val STORAGE_EXPORTER: MenuType<*> by registry.register(MNames.STORAGE_EXPORTER) { MenuType(::StorageExporterMenu) } val STORAGE_IMPORTER: MenuType<*> by registry.register(MNames.STORAGE_IMPORTER) { MenuType(::StorageImporterMenu) } + val STORAGE_POWER_SUPPLIER: MenuType<*> by registry.register(MNames.STORAGE_POWER_SUPPLIER) { MenuType(::StoragePowerSupplierMenu) } internal fun register() { registry.register(FMLJavaModLoadingContext.get().modEventBus) @@ -63,6 +64,7 @@ object MMenus { MenuScreens.register(STORAGE_BUS as MenuType, ::StorageBusScreen) MenuScreens.register(STORAGE_EXPORTER as MenuType, ::StorageExporterScreen) MenuScreens.register(STORAGE_IMPORTER as MenuType, ::StorageImporterScreen) + MenuScreens.register(STORAGE_POWER_SUPPLIER as MenuType, ::StoragePowerSupplierScreen) } } }