From 462a6d1bdf5ca82b929fcabe66be51640570be47 Mon Sep 17 00:00:00 2001 From: IonutParau Date: Wed, 15 Apr 2026 20:57:59 +0200 Subject: [PATCH] block models and stuff --- .../org/neoflock/neocomputers/block/Blocks.kt | 1 + .../gui/menu/CombustionGeneratorMenu.kt | 58 +++--------- .../gui/screen/CombustionGeneratorScreen.kt | 32 +++---- .../neocomputers/utils/GenericContainer.kt | 93 +++++++++++++++++++ .../neocomputers/blockstates/combustgen.json | 7 ++ .../neocomputers/models/block/combustgen.json | 6 ++ .../neocomputers/models/item/combustgen.json | 3 + 7 files changed, 137 insertions(+), 63 deletions(-) create mode 100644 src/main/resources/assets/neocomputers/blockstates/combustgen.json create mode 100644 src/main/resources/assets/neocomputers/models/block/combustgen.json create mode 100644 src/main/resources/assets/neocomputers/models/item/combustgen.json diff --git a/src/main/kotlin/org/neoflock/neocomputers/block/Blocks.kt b/src/main/kotlin/org/neoflock/neocomputers/block/Blocks.kt index 36f559d..93e6d2b 100644 --- a/src/main/kotlin/org/neoflock/neocomputers/block/Blocks.kt +++ b/src/main/kotlin/org/neoflock/neocomputers/block/Blocks.kt @@ -32,6 +32,7 @@ object Blocks { fun registerBlockItems() { BLOCKS.forEach(Consumer { sup: RegistrySupplier -> + NeoComputers.LOGGER.info(sup.id.toString()) val id = ResourceKey.create(Registries.ITEM, sup.id) Items.ITEMS.register(sup.id.path) { BlockItem(sup.get()!!, Item.Properties().`arch$tab`(Tabs.TAB))} }) diff --git a/src/main/kotlin/org/neoflock/neocomputers/gui/menu/CombustionGeneratorMenu.kt b/src/main/kotlin/org/neoflock/neocomputers/gui/menu/CombustionGeneratorMenu.kt index 15e66a9..31d9318 100644 --- a/src/main/kotlin/org/neoflock/neocomputers/gui/menu/CombustionGeneratorMenu.kt +++ b/src/main/kotlin/org/neoflock/neocomputers/gui/menu/CombustionGeneratorMenu.kt @@ -7,61 +7,25 @@ import net.minecraft.world.entity.player.Player import net.minecraft.world.inventory.AbstractContainerMenu import net.minecraft.world.inventory.Slot import net.minecraft.world.item.ItemStack +import org.neoflock.neocomputers.utils.ContainerUtils +import org.neoflock.neocomputers.utils.GenericContainerMenu -class CombustionGeneratorMenu: AbstractContainerMenu { - var container: Container +class CombustionFuelSlot(container: Container, slot: Int, x: Int, y: Int): Slot(container, slot, x, y) { + override fun mayPlace(itemStack: ItemStack): Boolean { + return ContainerUtils.isBurningFuel(itemStack) + } +} +class CombustionGeneratorMenu: GenericContainerMenu { // Client-side constructor, idk forge tells me to do this constructor(id: Int, inventory: Inventory): this(id, inventory, SimpleContainer(1)) // Server-side constructor - constructor(id: Int, inventory: Inventory, container: Container): super(Menus.COMBUSTGEN_MENU.get(), id) { - this.container = container - + constructor(id: Int, inventory: Inventory, container: Container): super(Menus.COMBUSTGEN_MENU.get(), id, container) { container.startOpen(inventory.player) - this.addSlot(Slot(container, 0, 80, 35)) + this.addSlot(CombustionFuelSlot(container, 0, 80, 35)) - // Based off the code in ChestMenu - for (l in 0..2) { - for (m in 0..8) { - this.addSlot(Slot(inventory, m + l * 9 + 9, 8 + m * 18, 84 + l * 18)) - } - } - - for (l in 0..8) { - this.addSlot(Slot(inventory, l, 8 + l * 18, 84 + 3 * 18 + 4)) - } - } - - // taken from https://docs.fabricmc.net/develop/blocks/container-menus - override fun quickMoveStack(player: Player, i: Int): ItemStack? { - val slot = slots[i] - - if(!slot.hasItem()) return ItemStack.EMPTY - - val stack = slot.item - val copied = stack.copy() - val contSize = container.containerSize - - if(i < contSize) { - if(!this.moveItemStackTo(stack, contSize, slots.size, true)) { - return ItemStack.EMPTY - } - } else if(!this.moveItemStackTo(stack, 0, contSize, false)) { - return ItemStack.EMPTY - } - - if(stack.isEmpty) { - slot.setByPlayer(ItemStack.EMPTY) - } else { - slot.setChanged() - } - - return copied - } - - override fun stillValid(player: Player): Boolean { - return container.stillValid(player) + this.addInventorySlots(inventory, 8, 84) } } \ No newline at end of file diff --git a/src/main/kotlin/org/neoflock/neocomputers/gui/screen/CombustionGeneratorScreen.kt b/src/main/kotlin/org/neoflock/neocomputers/gui/screen/CombustionGeneratorScreen.kt index 07d372b..63c2dce 100644 --- a/src/main/kotlin/org/neoflock/neocomputers/gui/screen/CombustionGeneratorScreen.kt +++ b/src/main/kotlin/org/neoflock/neocomputers/gui/screen/CombustionGeneratorScreen.kt @@ -1,29 +1,29 @@ package org.neoflock.neocomputers.gui.screen + import net.minecraft.client.gui.GuiGraphics -import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen import net.minecraft.network.chat.Component import net.minecraft.resources.ResourceLocation import net.minecraft.world.entity.player.Inventory import org.neoflock.neocomputers.NeoComputers import org.neoflock.neocomputers.gui.menu.CombustionGeneratorMenu +import org.neoflock.neocomputers.utils.GenericContainerScreen -class CombustionGeneratorScreen(abstractContainerMenu: CombustionGeneratorMenu, inventory: Inventory, component: Component) : AbstractContainerScreen(abstractContainerMenu, inventory, component) { - override fun init() { - super.init() - - this.titleLabelX = (this.imageWidth - this.font.width(this.title)) / 2 - } - - override fun renderBg(guiGraphics: GuiGraphics, f: Float, i: Int, j: Int) { - val cx = (width - imageWidth) / 2 - val cy = (height - imageHeight) / 2 - - val containerTexture: ResourceLocation = ResourceLocation.fromNamespaceAndPath(NeoComputers.MODID, "textures/gui/linux.png") - guiGraphics.blitSprite(containerTexture, cx, cy, imageWidth, imageHeight) - } +class CombustionGeneratorScreen(abstractContainerMenu: CombustionGeneratorMenu, inventory: Inventory, component: Component) : GenericContainerScreen(abstractContainerMenu, inventory, component) { + override fun findMenuTexture(): ResourceLocation = ResourceLocation.withDefaultNamespace("textures/gui/container/dispenser.png") override fun render(graphics: GuiGraphics, mouseX: Int, mouseY: Int, something: Float) { super.render(graphics, mouseX, mouseY, something) - super.renderTooltip(graphics, mouseX, mouseY) + + val lineBg = 0xFF002200.toInt() + val lineFg = 0xFF00FF00.toInt() + + val lineX = imageX + 8 + val lineY = imageY + 6 + val lineHeight = 60 + + val power = 0.2 + + graphics.fill(lineX, lineY, lineX + 2, lineY + lineHeight, lineFg) + graphics.fill(lineX, lineY, lineX + 2, lineY + (lineHeight * (1.0 - power)).toInt(), lineBg) } } \ No newline at end of file diff --git a/src/main/kotlin/org/neoflock/neocomputers/utils/GenericContainer.kt b/src/main/kotlin/org/neoflock/neocomputers/utils/GenericContainer.kt index 06ed98c..44998b7 100644 --- a/src/main/kotlin/org/neoflock/neocomputers/utils/GenericContainer.kt +++ b/src/main/kotlin/org/neoflock/neocomputers/utils/GenericContainer.kt @@ -1,9 +1,19 @@ package org.neoflock.neocomputers.utils // based off the ImplementedContainer of https://docs.fabricmc.net/develop/blocks/block-containers +import net.minecraft.client.gui.GuiGraphics +import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen import net.minecraft.world.Container; import net.minecraft.core.NonNullList; +import net.minecraft.network.chat.Component +import net.minecraft.resources.ResourceLocation +import net.minecraft.server.packs.resources.Resource import net.minecraft.world.ContainerHelper +import net.minecraft.world.entity.player.Inventory +import net.minecraft.world.entity.player.Player +import net.minecraft.world.inventory.AbstractContainerMenu +import net.minecraft.world.inventory.MenuType +import net.minecraft.world.inventory.Slot import net.minecraft.world.item.ItemStack // Common container interface, assumes the entire purpose is purely raw item storage @@ -45,4 +55,87 @@ interface GenericContainer : Container { override fun clearContent() { getItems().clear() } +} + +abstract class GenericContainerMenu(menuType: MenuType<*>, id: Int, var container: Container): AbstractContainerMenu(menuType, id) { + fun addInventorySlots(inventory: Inventory, x: Int, y: Int) { + // Based off the code in ChestMenu + for (i in 0..2) { + for (j in 0..8) { + this.addSlot(Slot(inventory, j + i * 9 + 9, 8 + j * 18, 84 + i * 18)) + } + } + + addInventoryHotbar(inventory, x, y + 3 * 18 + 4) + } + + fun addInventoryHotbar(inventory: Inventory, x: Int, y: Int) { + for (i in 0..8) { + this.addSlot(Slot(inventory, i, x + i * 18, y)) + } + } + + // taken from https://docs.fabricmc.net/develop/blocks/container-menus + override fun quickMoveStack(player: Player, i: Int): ItemStack? { + val slot = slots[i] + + if(!slot.hasItem()) return ItemStack.EMPTY + + val stack = slot.item + val copied = stack.copy() + val contSize = container.containerSize + + if(i < contSize) { + if(!this.moveItemStackTo(stack, contSize, slots.size, true)) { + return ItemStack.EMPTY + } + } else if(!this.moveItemStackTo(stack, 0, contSize, false)) { + return ItemStack.EMPTY + } + + if(stack.isEmpty) { + slot.setByPlayer(ItemStack.EMPTY) + } else { + slot.setChanged() + } + + return copied + } + + override fun stillValid(player: Player): Boolean { + return container.stillValid(player) + } +} + +abstract class GenericContainerScreen(menu: T, inventory: Inventory, component: Component): AbstractContainerScreen(menu, inventory, component) { + open fun shouldCenterTitle() = true + open fun shouldRenderTooltip() = true + open fun findMenuTexture(): ResourceLocation? = null + + val imageX: Int + get() = (width - imageWidth) / 2 + + val imageY: Int + get() = (height - imageHeight) / 2 + + override fun init() { + super.init() + + if(shouldCenterTitle()) this.titleLabelX = (this.imageWidth - this.font.width(this.title)) / 2 + } + + override fun renderBg(guiGraphics: GuiGraphics, f: Float, i: Int, j: Int) { + val menuTex = findMenuTexture() + if(menuTex != null) { + val cx = (width - imageWidth) / 2 + val cy = (height - imageHeight) / 2 + + guiGraphics.blit(menuTex, imageX, imageY, 0, 0, imageWidth, imageHeight) + } + } + + override fun render(graphics: GuiGraphics, mouseX: Int, mouseY: Int, something: Float) { + super.render(graphics, mouseX, mouseY, something) + if(shouldRenderTooltip()) super.renderTooltip(graphics, mouseX, mouseY) + } } \ No newline at end of file diff --git a/src/main/resources/assets/neocomputers/blockstates/combustgen.json b/src/main/resources/assets/neocomputers/blockstates/combustgen.json new file mode 100644 index 0000000..4d396b0 --- /dev/null +++ b/src/main/resources/assets/neocomputers/blockstates/combustgen.json @@ -0,0 +1,7 @@ +{ + "variants": { + "": { + "model": "neocomputers:block/combustgen" + } + } +} \ No newline at end of file diff --git a/src/main/resources/assets/neocomputers/models/block/combustgen.json b/src/main/resources/assets/neocomputers/models/block/combustgen.json new file mode 100644 index 0000000..0683a5c --- /dev/null +++ b/src/main/resources/assets/neocomputers/models/block/combustgen.json @@ -0,0 +1,6 @@ +{ + "parent": "minecraft:block/cube_all", + "textures": { + "all": "neocomputers:block/teto" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/neocomputers/models/item/combustgen.json b/src/main/resources/assets/neocomputers/models/item/combustgen.json new file mode 100644 index 0000000..684fd2f --- /dev/null +++ b/src/main/resources/assets/neocomputers/models/item/combustgen.json @@ -0,0 +1,3 @@ +{ + "parent": "neocomputers:block/combustgen" +} \ No newline at end of file