Jump to content

[1.12.2] Draw TextBox over Container


mohkamfer

Recommended Posts

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

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

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:

 

 

 

Link to comment
Share on other sites

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)

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • OLXTOTO: Menikmati Sensasi Bermain Togel dan Slot dengan Aman dan Mengasyikkan   Dunia perjudian daring terus berkembang dengan cepat, dan salah satu situs yang telah menonjol dalam pasar adalah OLXTOTO. Sebagai platform resmi untuk permainan togel dan slot, OLXTOTO telah memenangkan kepercayaan banyak pemain dengan menyediakan pengalaman bermain yang aman, adil, dan mengasyikkan.   Keamanan Sebagai Prioritas Utama   Salah satu aspek utama yang membuat OLXTOTO begitu menonjol adalah komitmennya terhadap keamanan pemain. Dengan menggunakan teknologi enkripsi terkini, situs ini memastikan bahwa semua informasi pribadi dan keuangan para pemain tetap aman dan terlindungi dari akses yang tidak sah.   Beragam Permainan yang Menarik   Di OLXTOTO, pemain dapat menemukan beragam permainan yang menarik untuk dinikmati. Mulai dari permainan klasik seperti togel hingga slot modern dengan fitur-fitur inovatif, ada sesuatu untuk setiap selera dan preferensi. Grafik yang memukau dan efek suara yang mengagumkan menambah keseruan setiap putaran. Peluang Menang yang Tinggi   Salah satu hal yang paling menarik bagi para pemain adalah peluang menang yang tinggi yang ditawarkan oleh OLXTOTO. Dengan pembayaran yang adil dan peluang yang setara bagi semua pemain, setiap taruhan memberikan kesempatan nyata untuk memenangkan hadiah besar.   Layanan Pelanggan yang Responsif   Tim layanan pelanggan OLXTOTO siap membantu para pemain dengan setiap pertanyaan atau masalah yang mereka hadapi. Dengan layanan yang ramah dan responsif, pemain dapat yakin bahwa mereka akan mendapatkan bantuan yang mereka butuhkan dengan cepat dan efisien.   Kesimpulan   OLXTOTO telah membuktikan dirinya sebagai salah satu situs terbaik untuk penggemar togel dan slot online. Dengan fokus pada keamanan, beragam permainan yang menarik, peluang menang yang tinggi, dan layanan pelanggan yang luar biasa, tidak mengherankan bahwa situs ini telah menjadi pilihan utama bagi banyak pemain.   Jadi, jika Anda mencari pengalaman bermain yang aman, adil, dan mengasyikkan, jangan ragu untuk bergabung dengan OLXTOTO hari ini dan rasakan sensasi kemenangan!      
    • i notice a change if i add the min and max ram in the line like this for example:    # Xmx and Xms set the maximum and minimum RAM usage, respectively. # They can take any number, followed by an M or a G. # M means Megabyte, G means Gigabyte. # For example, to set the maximum to 3GB: -Xmx3G # To set the minimum to 2.5GB: -Xms2500M # A good default for a modded server is 4GB. # Uncomment the next line to set it. -Xmx10240M -Xms8192M    i need to make more experiments but for now this apparently works.
    • Selamat datang di OLXTOTO, situs slot gacor terpanas yang sedang booming di industri perjudian online. Jika Anda mencari pengalaman bermain yang luar biasa, maka OLXTOTO adalah tempat yang tepat untuk Anda. Dapatkan sensasi tidak biasa dengan variasi slot online terlengkap dan peluang memenangkan jackpot slot maxwin yang sering. Di sini, Anda akan merasakan keseruan yang luar biasa dalam bermain judi slot. DAFTAR OLXTOTO DISINI LOGIN OLXTOTO DISINI AKUN PRO OLXTOTO DISINI   Slot Gacor untuk Sensasi Bermain Maksimal Olahraga cepat dan seru dengan slot gacor di OLXTOTO. Rasakan sensasi bermain maksimal dengan mesin slot yang memberikan kemenangan beruntun. Temukan keberuntungan Anda di antara berbagai pilihan slot gacor yang tersedia dan rasakan kegembiraan bermain judi slot yang tak terlupakan. Situs Slot Terpercaya dengan Pilihan Terlengkap OLXTOTO adalah situs slot terpercaya yang menawarkan pilihan terlengkap dalam perjudian online. Nikmati berbagai genre dan tema slot online yang menarik, dari slot klasik hingga slot video yang inovatif. Dipercaya oleh jutaan pemain, OLXTOTO memberikan pengalaman bermain yang aman dan terjamin.   Jackpot Slot Maxwin Sering Untuk Peluang Besar Di OLXTOTO, kami tidak hanya memberikan hadiah slot biasa, tapi juga memberikan kesempatan kepada pemain untuk memenangkan jackpot slot maxwin yang sering. Dengan demikian, Anda dapat meraih keberuntungan besar dan memenangkan ribuan rupiah sebagai hadiah jackpot slot maxwin kami. Jackpot slot maxwin merupakan peluang besar bagi para pemain judi slot untuk meraih keuntungan yang lebih besar. Dalam permainan kami, Anda tidak harus terpaku pada kemenangan biasa saja. Kami hadir dengan jackpot slot maxwin yang sering, sehingga Anda memiliki peluang yang lebih besar untuk meraih kemenangan besar dengan hadiah yang menggiurkan. Dalam permainan judi slot, pengalaman bermain bukan hanya tentang keseruan dan hiburan semata. Kami memahami bahwa para pemain juga menginginkan kesempatan untuk meraih keberuntungan besar. Oleh karena itu, OLXTOTO hadir dengan jackpot slot maxwin yang sering untuk memberikan peluang besar kepada para pemain kami. Peluang Besar Menang Jackpot Slot Maxwin Peluang menang jackpot slot maxwin di OLXTOTO sangatlah besar. Anda tidak perlu khawatir tentang batasan atau pembatasan dalam meraih jackpot tersebut. Kami ingin memberikan kesempatan kepada semua pemain kami untuk merasakan sensasi menang dalam jumlah yang luar biasa. Jackpot slot maxwin kami dibuka untuk semua pemain judi slot di OLXTOTO. Anda memiliki peluang yang sama dengan pemain lainnya untuk memenangkan hadiah jackpot yang besar. Kami percaya bahwa semua orang memiliki kesempatan untuk meraih keberuntungan besar, dan itulah mengapa kami menyediakan jackpot slot maxwin yang sering untuk memenuhi harapan dan keinginan Anda.  
    • LOGIN DAN DAFTAR DISINI SEKARANG !!!! Blacktogel adalah situs judi slot online yang menjadi pilihan banyak penggemar judi slot gacor di Indonesia. Dengan platform yang sangat user-friendly dan berbagai macam permainan slot yang tersedia, Blacktogel menjadi tempat yang tepat untuk penggemar judi slot online. Dalam artikel ini, kami akan membahas tentang Blacktogel dan keunggulan situs slot gacor online yang disediakan.  
    • Situs bandar slot online Gacor dengan bonus terbesar saat ini sedang menjadi sorotan para pemain judi online. Dengan persaingan yang semakin ketat dalam industri perjudian online, pemain mencari situs yang tidak hanya menawarkan permainan slot yang gacor (sering memberikan kemenangan), tetapi juga bonus terbesar yang bisa meningkatkan peluang menang. Daftar disini : https://gesit.io/googlegopek
  • Topics

×
×
  • Create New...

Important Information

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