Jump to content

Recommended Posts

Posted (edited)

Hello, I'm trying to draw a GuiScreen over a normal container like a chest for example, but seems like the textbox is only being shown for one frame, and the rest of the frames the cursor is hidden and the textbox is invisible.

How can I achieve such a combination? Just like how JEI shows the items list on the right, and a textbox underneath.

 

As for my code, it's really simple and basic, that I don't think might be introducing a problem, and I believe my problem is something missing not something existing.

Edited by mohkamfer
Add version tag
Posted
1 hour ago, diesieben07 said:

Show your code.

@Mod(modid = ExampleMod.MODID, name = ExampleMod.NAME, version = ExampleMod.VERSION)
public class ExampleMod {
    class ContainerOpenEventHandler {
        @SubscribeEvent
        public void containerOpen(PlayerContainerEvent.Open containerEvent) {
            Minecraft.getMinecraft().displayGuiScreen(new InputScreen());
        }
    }

    class InputScreen extends GuiScreen {

        private GuiTextField textField;
        private int textFieldId;

        @Override
        public void initGui() {
            super.initGui();

            textFieldId = 0;
            textField = new GuiTextField(textFieldId, fontRenderer, 0, 0, 100, 10);
            Keyboard.enableRepeatEvents(true);
        }

        @Override
        protected void keyTyped(char typedChar, int keyCode) throws IOException {
            super.keyTyped(typedChar, keyCode);
            textField.textboxKeyTyped(typedChar, keyCode);
        }

        @Override
        public void updateScreen() {
            super.updateScreen();
            textField.updateCursorCounter();
        }

        @Override
        public void drawScreen(int mouseX, int mouseY, float partialTicks) {
            super.drawScreen(mouseX, mouseY, partialTicks);
            textField.drawTextBox(); // I shuffled this before and after super, didn't help.
        }

        @Override
        protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
            super.mouseClicked(mouseX, mouseY, mouseButton);
            textField.mouseClicked(mouseX, mouseY, mouseButton);
        }

        @Override
        protected void actionPerformed(GuiButton button) throws IOException {
            super.actionPerformed(button);
        }

        @Override
        public boolean doesGuiPauseGame() {
            return false;
        }
    }

    public static final String MODID = "example";
    public static final String NAME = "Example";
    public static final String VERSION = "1.0";

    private static Logger logger;

    @EventHandler
    public void preInit(FMLPreInitializationEvent event)
    {
        logger = event.getModLog();
    }

    @EventHandler
    public void init(FMLInitializationEvent event)
    {
        MinecraftForge.EVENT_BUS.register(new ContainerOpenEventHandler());
    }
}

 

Also I tried showing the screen after closing the container, just to confirm... And it showed perfectly... So this makes me believe that the container GUI is overriding my screen GUI, how can I force draw the textbox over the container?

Posted
18 minutes ago, mohkamfer said:

public void containerOpen(PlayerContainerEvent.Open containerEvent) { Minecraft.getMinecraft().displayGuiScreen(new InputScreen()); }

You can't do any of this. First of all that event fires on the server, so you can't access client-sided classes in it or you will crash the server.

You are also reaching across logical sides which creates a lot of issues in general and many more issues with things that need access to render-thread state(rendering, mouse checks, etc)

Lastly you can't just open your GUI over the original GuiContainer instance. You are screwing up internal game logic since the client doesn't have an associated container anymore, the GUI id is different and the sync packets from the server now reach an incompatible class. Minecraft's GUI isn't modular, there is only ever one GUI at a time.

 

In your case either listen to a GUI screen init event and add your text field to it there or render it separately in some kind of GUI render event. Note that in both cases you will need your own handlers for the mouse and keyboard actions.

Posted
22 minutes ago, V0idWa1k3r said:

In your case either listen to a GUI screen init event and add your text field to it there or render it separately in some kind of GUI render event. Note that in both cases you will need your own handlers for the mouse and keyboard actions.

 

Well, being introduced to the forge documentation (which seems to not help in any way at all) for the first time today explains why I messed up so bad...

So which event exactly should I listen to? GuiScreenEvent from net.minecraftforge.client.event?

 

Also once I get its instance, do I attach the the text field only? Or I make a complete GuiScreen for it?

In both cases how do I dynamically attach a view to that instance?

 

I tried looking up JEI's repository, but they already have a sophisticated architecture with many middlewares between what I want to look at, so it's quite hard to learn anything from it.

If there's a simpler plugin that I could look at its source code, I'd be much appreciated so I don't annoy you with questions.

Posted
22 minutes ago, mohkamfer said:

So which event exactly should I listen to? GuiScreenEvent from net.minecraftforge.client.event?

 

IIRC that is a base class for more specific events.

 

23 minutes ago, mohkamfer said:

do I attach the the text field only? Or I make a complete GuiScreen for it?

Think yourself - would you rather just dynamically add a text field to the GUI's text field list or create a new implementation of GuiScrren for EVERY SINGLE GUI class in the game and give up on mod compatibility? Even if you choose to do the second variant with a wrapper you will still mess up every instanceof check. So the answer is painfully obvious.

 

 

Posted
6 hours ago, V0idWa1k3r said:

Think yourself - would you rather just dynamically add a text field to the GUI's text field list or create a new implementation of GuiScrren for EVERY SINGLE GUI class in the game and give up on mod compatibility? Even if you choose to do the second variant with a wrapper you will still mess up every instanceof check. So the answer is painfully obvious.

Yeah I was successfully able to draw it on top of the current GuiScreen using events.

 

The only problem facing me now is that tooltips appear behind my component.. Is there any way to only redraw the tooltips of the container? Or maybe draw my component just before tooltips are drawn?

6 hours ago, V0idWa1k3r said:

 

 

 

Posted

Post your code, you’re rendering too far forward on the z axis

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

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.