Jump to content

How can I show an empty gui by key pressing


Klarks

Recommended Posts

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

Link to comment
Share on other sites

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).

  • Like 1
Link to comment
Share on other sites

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 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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);
}
Link to comment
Share on other sites

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);
}

forum.PNG

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.