Posted January 8, 20214 yr I'm just starting to learn minecraft modding and would like to understand how i can display an empty gui by pressing the key. I tried to figure it out myself from the vanilla minecraft code and tutorials, but I could not understand how it all works
January 8, 20214 yr What is an empty gui? If it does not store any information (e.g. inventories, sharing data) a simple screen will work using Minecraft#displayGuiScreen (this is client only). Otherwise you will need a registered container and screen, and open it with NetworkHooks#openGui (this should be done on server, in this case you send a packet when the key is pressed). There's a key input event that you can use, or use client tick event to proceed with keybindings (check Minecraft.java).
January 8, 20214 yr Author Thanks for the tip. How to make a gui as a standard player inventory for storing resources, but with 1 cell. What i should use? I saw tutorials and people uses tileentity, containers but which of this do I need and what function do they perform. I wanna start with simple things
January 8, 20214 yr Where will you be storing things at? Is it going to be saved per player, or itemstacks? Both of them can use capabilities. https://mcforge.readthedocs.io/en/latest/datastorage/capabilities/ Edited January 8, 20214 yr by poopoodice
January 8, 20214 yr Author So itemstack allow to create a bag? I want to make an extra slot for players. Do I need to use an entity for this?
January 8, 20214 yr Author How can i do it? I don't quite understand what capability is and how to attach it to the player
January 8, 20214 yr Author Thanks for the tips i made a single stack chest. But how i can fix the inventory title pos and how should i call the lang variable to change the chest name Edited January 8, 20214 yr by Klarks
January 8, 20214 yr Well, if you use this texture for the GUI there will never be space to write "Inventory" in a human-readable character size such as it fits that little gap 😆 To change how things are rendered/placed in your GUI you need to do that in the render method of your custom screen class Check out the port of the BetterEnd fabric mod (WIP): https://www.curseforge.com/minecraft/mc-mods/betterend-forge-port
January 8, 20214 yr Author That's not a problem it was just a placeholder. What i should change or add here i couldn't find anything similar in the vanilla code @Override public void render(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) { this.renderBackground(matrixStack); super.render(matrixStack, mouseX, mouseY, partialTicks); this.renderHoveredTooltip(matrixStack, mouseX, mouseY); }
January 8, 20214 yr Author I fixed by adding this.playerInventoryTitleY = 42; @Override public void render(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) { this.renderBackground(matrixStack); //this.playerInventoryTitleX = 10; this.playerInventoryTitleY = 42; super.render(matrixStack, mouseX, mouseY, partialTicks); this.renderHoveredTooltip(matrixStack, mouseX, mouseY); }
January 8, 20214 yr I just noticed that the titles are actually rendered in drawGuiContainerForegroundLayer() not render(). Also I believe you only need to set the value once in the constructor, or in init().
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.