a menu for combustion generator, but sprites dont work.
Don't quest the test sprites.
This commit is contained in:
@@ -31,6 +31,7 @@ object NeoComputers {
|
|||||||
BlockEntities.BLOCKENTITIES.register()
|
BlockEntities.BLOCKENTITIES.register()
|
||||||
BlockEntities.registerPowerBlocks()
|
BlockEntities.registerPowerBlocks()
|
||||||
Menus.MENUS.register()
|
Menus.MENUS.register()
|
||||||
|
Menus.registerScreens()
|
||||||
Tabs.TABS.register()
|
Tabs.TABS.register()
|
||||||
|
|
||||||
ClientLifecycleEvent.CLIENT_SETUP.register {
|
ClientLifecycleEvent.CLIENT_SETUP.register {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package org.neoflock.neocomputers.block
|
package org.neoflock.neocomputers.block
|
||||||
|
|
||||||
|
import dev.architectury.registry.menu.MenuRegistry
|
||||||
import net.minecraft.core.BlockPos
|
import net.minecraft.core.BlockPos
|
||||||
import net.minecraft.network.chat.ChatType
|
import net.minecraft.network.chat.ChatType
|
||||||
import net.minecraft.network.chat.OutgoingChatMessage
|
import net.minecraft.network.chat.OutgoingChatMessage
|
||||||
@@ -33,13 +34,8 @@ class CombustionGeneratorBlock : NodeBlock(), EntityBlock {
|
|||||||
): InteractionResult {
|
): InteractionResult {
|
||||||
if(!level.isClientSide()) {
|
if(!level.isClientSide()) {
|
||||||
val sp = player as ServerPlayer
|
val sp = player as ServerPlayer
|
||||||
val ent = level.getBlockEntity(blockPos, BlockEntities.COMBUSTGEN_ENTITY.get())
|
val ent = level.getBlockEntity(blockPos, BlockEntities.COMBUSTGEN_ENTITY.get()).get()
|
||||||
if(ent.isPresent) {
|
MenuRegistry.openMenu(sp, ent)
|
||||||
val bust = ent.get()
|
|
||||||
val fuel = bust.stacks[0]
|
|
||||||
val msg = PlayerChatMessage.system("${fuel.displayName.string} x ${fuel.count} (${bust.node.getEnergy()} / ${bust.node.getEnergyCapacity()} J)")
|
|
||||||
sp.sendChatMessage(OutgoingChatMessage.create(msg), false, ChatType.bind(ChatType.CHAT, player))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return InteractionResult.SUCCESS
|
return InteractionResult.SUCCESS
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ object BlockEntities {
|
|||||||
|
|
||||||
fun registerPowerBlocks() {
|
fun registerPowerBlocks() {
|
||||||
PowerManager.registerPowerBlockEntity(CAPACITOR_ENTITY.get())
|
PowerManager.registerPowerBlockEntity(CAPACITOR_ENTITY.get())
|
||||||
|
PowerManager.registerPowerBlockEntity(SOLARGEN_ENTITY.get())
|
||||||
PowerManager.registerPowerBlockEntity(COMBUSTGEN_ENTITY.get())
|
PowerManager.registerPowerBlockEntity(COMBUSTGEN_ENTITY.get())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,17 +2,22 @@ package org.neoflock.neocomputers.entity
|
|||||||
|
|
||||||
import net.minecraft.core.BlockPos
|
import net.minecraft.core.BlockPos
|
||||||
import net.minecraft.core.NonNullList
|
import net.minecraft.core.NonNullList
|
||||||
|
import net.minecraft.network.chat.Component
|
||||||
|
import net.minecraft.world.MenuProvider
|
||||||
|
import net.minecraft.world.entity.player.Inventory
|
||||||
import net.minecraft.world.entity.player.Player
|
import net.minecraft.world.entity.player.Player
|
||||||
|
import net.minecraft.world.inventory.AbstractContainerMenu
|
||||||
import net.minecraft.world.item.ItemStack
|
import net.minecraft.world.item.ItemStack
|
||||||
import net.minecraft.world.level.block.state.BlockState
|
import net.minecraft.world.level.block.state.BlockState
|
||||||
import org.neoflock.neocomputers.block.NodeBlockEntity
|
import org.neoflock.neocomputers.block.NodeBlockEntity
|
||||||
|
import org.neoflock.neocomputers.gui.menu.CombustionGeneratorMenu
|
||||||
import org.neoflock.neocomputers.network.Networking
|
import org.neoflock.neocomputers.network.Networking
|
||||||
import org.neoflock.neocomputers.network.PowerRole
|
import org.neoflock.neocomputers.network.PowerRole
|
||||||
import org.neoflock.neocomputers.utils.GenericContainer
|
import org.neoflock.neocomputers.utils.GenericContainer
|
||||||
import org.neoflock.neocomputers.utils.ContainerUtils
|
import org.neoflock.neocomputers.utils.ContainerUtils
|
||||||
import kotlin.math.min
|
import kotlin.math.min
|
||||||
|
|
||||||
class CombustionGeneratorBlockEntity(blockPos: BlockPos, blockState: BlockState) : NodeBlockEntity(BlockEntities.COMBUSTGEN_ENTITY.get(), blockPos, blockState), GenericContainer {
|
class CombustionGeneratorBlockEntity(blockPos: BlockPos, blockState: BlockState) : NodeBlockEntity(BlockEntities.COMBUSTGEN_ENTITY.get(), blockPos, blockState), GenericContainer, MenuProvider {
|
||||||
val energyPerTick: Long = 50
|
val energyPerTick: Long = 50
|
||||||
|
|
||||||
var energy: Long = 0
|
var energy: Long = 0
|
||||||
@@ -70,4 +75,8 @@ class CombustionGeneratorBlockEntity(blockPos: BlockPos, blockState: BlockState)
|
|||||||
burningTimeRemaining = ContainerUtils.getBurningTime(fuel) ?: 0
|
burningTimeRemaining = ContainerUtils.getBurningTime(fuel) ?: 0
|
||||||
fuel.count--
|
fuel.count--
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun getDisplayName(): Component? = Component.translatable("block.neocomputers.combustgen")
|
||||||
|
|
||||||
|
override fun createMenu(i: Int, inventory: Inventory, player: Player) = CombustionGeneratorMenu(i, inventory, this)
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
package org.neoflock.neocomputers.gui.menu
|
||||||
|
|
||||||
|
import net.minecraft.world.Container
|
||||||
|
import net.minecraft.world.SimpleContainer
|
||||||
|
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.Slot
|
||||||
|
import net.minecraft.world.item.ItemStack
|
||||||
|
|
||||||
|
class CombustionGeneratorMenu: AbstractContainerMenu {
|
||||||
|
var container: Container
|
||||||
|
|
||||||
|
// 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
|
||||||
|
|
||||||
|
container.startOpen(inventory.player)
|
||||||
|
|
||||||
|
this.addSlot(Slot(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)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,13 +3,22 @@ package org.neoflock.neocomputers.gui.menu;
|
|||||||
import dev.architectury.registry.menu.MenuRegistry
|
import dev.architectury.registry.menu.MenuRegistry
|
||||||
import dev.architectury.registry.registries.DeferredRegister
|
import dev.architectury.registry.registries.DeferredRegister
|
||||||
import dev.architectury.registry.registries.RegistrySupplier
|
import dev.architectury.registry.registries.RegistrySupplier
|
||||||
|
import net.minecraft.client.gui.screens.MenuScreens
|
||||||
import net.minecraft.core.registries.Registries
|
import net.minecraft.core.registries.Registries
|
||||||
|
import net.minecraft.world.flag.FeatureFlagSet
|
||||||
|
import net.minecraft.world.flag.FeatureFlags
|
||||||
import net.minecraft.world.inventory.MenuType
|
import net.minecraft.world.inventory.MenuType
|
||||||
import org.neoflock.neocomputers.NeoComputers
|
import org.neoflock.neocomputers.NeoComputers
|
||||||
import org.neoflock.neocomputers.gui.menu.ScreenMenu
|
import org.neoflock.neocomputers.gui.menu.ScreenMenu
|
||||||
|
import org.neoflock.neocomputers.gui.screen.CombustionGeneratorScreen
|
||||||
|
|
||||||
object Menus {
|
object Menus {
|
||||||
val MENUS: DeferredRegister<MenuType<*>> = DeferredRegister.create(NeoComputers.MODID, Registries.MENU)
|
val MENUS: DeferredRegister<MenuType<*>> = DeferredRegister.create(NeoComputers.MODID, Registries.MENU)
|
||||||
|
|
||||||
val SCREEN_MENU: RegistrySupplier<MenuType<ScreenMenu>> = MENUS.register("screen_menu") { MenuRegistry.of(::ScreenMenu)} // "deprecated" my ass
|
val SCREEN_MENU: RegistrySupplier<MenuType<ScreenMenu>> = MENUS.register("screen_menu") { MenuType(::ScreenMenu, FeatureFlagSet.of()) }
|
||||||
|
val COMBUSTGEN_MENU: RegistrySupplier<MenuType<CombustionGeneratorMenu>> = MENUS.register("combustgen_menu") { MenuType(::CombustionGeneratorMenu, FeatureFlagSet.of() ) }
|
||||||
|
|
||||||
|
fun registerScreens() {
|
||||||
|
MenuScreens.register(Menus.COMBUSTGEN_MENU.get(), {m: CombustionGeneratorMenu, u, comp -> CombustionGeneratorScreen(m, u, comp)})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +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
|
||||||
|
|
||||||
|
class CombustionGeneratorScreen(abstractContainerMenu: CombustionGeneratorMenu, inventory: Inventory, component: Component) : AbstractContainerScreen<CombustionGeneratorMenu>(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)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun render(graphics: GuiGraphics, mouseX: Int, mouseY: Int, something: Float) {
|
||||||
|
super.render(graphics, mouseX, mouseY, something)
|
||||||
|
super.renderTooltip(graphics, mouseX, mouseY)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package org.neoflock.neocomputers.utils
|
package org.neoflock.neocomputers.utils
|
||||||
|
|
||||||
import dev.architectury.registry.fuel.FuelRegistry
|
import dev.architectury.registry.fuel.FuelRegistry
|
||||||
|
import net.minecraft.world.inventory.AbstractContainerMenu
|
||||||
import net.minecraft.world.item.ItemStack
|
import net.minecraft.world.item.ItemStack
|
||||||
|
|
||||||
// mewhenthe, aka e, will have me publicly executed for this code
|
// mewhenthe, aka e, will have me publicly executed for this code
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
{
|
{
|
||||||
"neocomputers.confirm": "Confirm",
|
"neocomputers.confirm": "Confirm",
|
||||||
"neocomputers.cancel": "Cancel"
|
"neocomputers.cancel": "Cancel",
|
||||||
|
"block.neocomputers.combustgen": "Combustion Generator"
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"pack": {
|
"pack": {
|
||||||
"description": "${name}",
|
"description": "${name}",
|
||||||
"pack_format": 15
|
"pack_format": 48
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user