Jump to content

Error opening GUI with a key [1.16.5]


Grookey

Recommended Posts

    @SubscribeEvent
    public static void gauntletGUI(final TickEvent.PlayerTickEvent event) {
        PlayerEntity player = event.player;
        ItemStack stack = event.player.getMainHandItem();

        if (keyOpenGauntlet.isDown() && keyOpenGauntlet.consumeClick() && stack.getItem().equals(ItemInit.INFINITY_GAUNTLET.get())) {
            Main.NETWORK.sendToServer(new InputMessage(stack));
        }
    }

This is the event

 

    public static void handle(InputMessage message, Supplier<NetworkEvent.Context> contextSupplier) {
        NetworkEvent.Context context = contextSupplier.get();
        context.enqueueWork( () ->
                {
                    ServerPlayerEntity player = context.getSender();
                    INamedContainerProvider ncp = new InfinityGauntlet.InfinityGauntletContainerProvider(player.getMainHandItem().getItem(), message.stack);
                    NetworkHooks.openGui(player, ncp);
                }
                );
        context.setPacketHandled(true);

    }

This opens the GUI.

 

So the problem is that when I press the key in this case is B the GUI opens and instantly closes.

https://github.com/Manueh333/Marvel-MOD

Link to comment
Share on other sites

Ok, so I have put this code and it doesn't work, I have to forms of opening the GUI one is on the useOn  void of the item and this  form work but the other form is to press 'B' but when the GUI opens it closes. If I put "return true;" in stillValid the GUI didn't close so it's obvious that the problem is there but I dont understand why 

    @Override
    public boolean stillValid(PlayerEntity player) {
        return (player.getMainHandItem().equals(heldItem));

    }

 

Link to comment
Share on other sites

stillValid() runs on the server, where are you storing "heldItem" when you press B?

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Link to comment
Share on other sites

ItemStack does not override equals, this means the == operator is used,
you need to use IForgeItemStack#equals (requires an ItemStack and a boolean)

or you check the Item of the ItemStack, therefore you can use a instanceof check, equals or the == operator depends on your purpose

Link to comment
Share on other sites

4 minutes ago, Grookey said:
16 minutes ago, Luis_ST said:

ItemStack does not override equals, this means the == operator is used,
you need to use IForgeItemStack#equals (requires an ItemStack and a boolean)

or you check the Item of the ItemStack, therefore you can use a instanceof check, equals or the == operator depends on your purpose

this is the issue

5 minutes ago, Grookey said:

This don't work

is the code called, use debugger to check

Link to comment
Share on other sites

8 minutes ago, Luis_ST said:

ItemStack does not override equals, this means the == operator is used,
you need to use IForgeItemStack#equals (requires an ItemStack and a boolean)

or you check the Item of the ItemStack, therefore you can use a instanceof check, equals or the == operator depends on your purpose

I dont understand what you mean, can you make an example pls

 

12 minutes ago, Luis_ST said:

is the code called, use debugger to check

yeah the code is called

Link to comment
Share on other sites

33 minutes ago, Grookey said:

I dont understand what you mean, can you make an example pls

when exactly should the player be able to open the container?
please be as detailed as possible

33 minutes ago, Grookey said:

yeah the code is called

is the Packet received on server and how did you test if it works?

Edited by Luis_ST
Link to comment
Share on other sites

8 minutes ago, Luis_ST said:

is the Packet received on server and how did you test if it works?

6urtiuV.png

I tested it with a breakpoint and pressing B at the game

 

8 minutes ago, Luis_ST said:

when exactly should the player be able to open the container?
please be as detailed as possible

You said I have to use a IForgeItemStack#equals with a ItemStack and a boolean so how?

Edited by Grookey
Link to comment
Share on other sites

 

You want to retrieve the held item on the server.

Instead you are retrieving it on the client which will not be the same item stack as the held item on the server. It will be a copy. So == will be false.

 

But I think you actually just need the following

        return (player.getMainHandItem().sameItem(heldItem));

to check the items are the same type. You are not interested in the stack count or tags?

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Link to comment
Share on other sites

3 minutes ago, warjort said:

You are not interested in the stack count or tags?

Actually, yes the Item is a container that contains items so its important that

 

But I tried and It worked

Also it would be good to make the item cant be moved in the inventory when my GUI is opened is there any form to do this?

Edited by Grookey
Link to comment
Share on other sites

Then use one of the ItemStack.matches() or the equals(ItemStack, boolean) defined by the IForgeItemStack interface.

I am not sure of your requirements so you will have to figure out which one yourself 🙂

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Link to comment
Share on other sites

24 minutes ago, warjort said:
 return (player.getMainHandItem().sameItem(heldItem));

I thought that I need the tags but not because the item contain items if you add or remove some of the item it closes the GUI and the content of the container is not updated so I finally used this code

Any of the codes worked for me because when i change a Item of the inside of the container it closes and not updates, and like after the problem is only when I use the key B to open the GUI

    @SubscribeEvent
    public static void gauntletGUI(TickEvent.PlayerTickEvent event) {
        PlayerEntity player = event.player;
        ItemStack stack = event.player.getItemBySlot(EquipmentSlotType.MAINHAND);

        if (keyOpenGauntlet.isDown() && keyOpenGauntlet.consumeClick() && stack.getItem().equals(ItemInit.INFINITY_GAUNTLET.get())) {
            Main.NETWORK.sendToServer(new InputMessage(stack));
        }
    }

 

Edited by Grookey
Link to comment
Share on other sites

KeyBindings are client side only, you need to use TickEvent.ClientTickEvent instead

why did you call KeyBinding#consumeClick, you should only check KeyBinding#isDown?

last but not least i would recommend you to check the Item also on server side (in the handle method of the Message), since you should never trust the client

Link to comment
Share on other sites

43 minutes ago, Luis_ST said:

TickEvent.ClientTickEvent instead

In ClickTickEvent i dont know how to get the player

 

43 minutes ago, Luis_ST said:

i would recommend you to check the Item also on server side (in the handle method of the Message)

    public static void handle(InputMessage message, Supplier<NetworkEvent.Context> contextSupplier) {
        NetworkEvent.Context context = contextSupplier.get();
        ServerPlayerEntity player = context.getSender();
        ItemStack gauntlet = player.getMainHandItem();
        if(gauntlet.getItem() instanceof InfinityGauntlet) {
            INamedContainerProvider ncp = new InfinityGauntlet.InfinityGauntletContainerProvider((InfinityGauntlet) gauntlet.getItem(), gauntlet);
            NetworkHooks.openGui(player, ncp);
            context.setPacketHandled(false);
        }


    }

You were right I check the item on the server and this code works 
Thanks

Link to comment
Share on other sites

5 minutes ago, Luis_ST said:

Minecraft.getInstance()

    @SubscribeEvent
    public static void gauntletGUI(final TickEvent.ClientTickEvent event) {
        PlayerEntity player = Minecraft.getInstance().player;
        if(player != null)  {
            ItemStack stack = player.getMainHandItem();

            if (keyOpenGauntlet.isDown() && stack.getItem().equals(ItemInit.INFINITY_GAUNTLET.get())) {
                Main.NETWORK.sendToServer(new InputMessage(stack));
            }
        }

    }

It works. Thanks! :D

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: Platform Maxwin dan Gacor Terbesar Sepanjang Masa OLXTOTO telah menetapkan standar baru dalam dunia perjudian dengan menjadi platform terbesar untuk pengalaman gaming yang penuh kemenangan dan kegacoran, sepanjang masa. Dengan fokus yang kuat pada menyediakan permainan yang menghadirkan kesenangan tanpa batas dan peluang kemenangan besar, OLXTOTO telah menjadi pilihan utama bagi para pencinta judi berani di Indonesia. Maxwin: Mengejar Kemenangan Terbesar Maxwin bukan sekadar kata-kata kosong di OLXTOTO. Ini adalah konsep yang ditanamkan dalam setiap aspek permainan yang mereka tawarkan. Dari permainan slot yang menghadirkan jackpot besar hingga berbagai opsi permainan togel dengan hadiah fantastis, para pemain dapat memperoleh peluang nyata untuk mencapai kemenangan terbesar dalam setiap taruhan yang mereka lakukan. OLXTOTO tidak hanya menawarkan kesempatan untuk menang, tetapi juga menjadi wadah bagi para pemain untuk meraih impian mereka dalam perjudian yang berani. Gacor: Keberuntungan yang Tak Tertandingi Keberuntungan seringkali menjadi faktor penting dalam perjudian, dan OLXTOTO memahami betul akan hal ini. Dengan berbagai strategi dan analisis yang disediakan, pemain dapat menemukan peluang gacor yang tidak tertandingi dalam setiap taruhan. Dari hasil togel yang tepat hingga putaran slot yang menguntungkan, OLXTOTO memastikan bahwa setiap taruhan memiliki potensi untuk menjadi momen yang mengubah hidup. Inovasi dan Kualitas Tanpa Batas Tidak puas dengan prestasi masa lalu, OLXTOTO terus berinovasi untuk memberikan pengalaman gaming terbaik kepada para pengguna. Dengan menggabungkan teknologi terbaru dengan desain yang ramah pengguna, platform ini menyajikan antarmuka yang mudah digunakan tanpa mengorbankan kualitas. Setiap pembaruan dan peningkatan dilakukan dengan tujuan tunggal: memberikan pengalaman gaming yang tanpa kompromi kepada setiap pengguna. Komitmen Terhadap Kepuasan Pelanggan Di balik kesuksesan OLXTOTO adalah komitmen mereka terhadap kepuasan pelanggan. Tim dukungan pelanggan yang profesional siap membantu para pemain dalam setiap langkah perjalanan gaming mereka. Dari pertanyaan teknis hingga bantuan dengan transaksi keuangan, OLXTOTO selalu siap memberikan pelayanan terbaik kepada para pengguna mereka. Penutup: Mengukir Sejarah dalam Dunia Perjudian Daring OLXTOTO bukan sekadar platform perjudian berani biasa. Ini adalah ikon dalam dunia perjudian daring Indonesia, sebuah destinasi yang menyatukan kemenangan dan keberuntungan dalam satu tempat yang mengasyikkan. Dengan komitmen mereka terhadap kualitas, inovasi, dan kepuasan pelanggan, OLXTOTO terus mengukir sejarah dalam perjudian dunia berani, menjadi nama yang tak terpisahkan dari pengalaman gaming terbaik. Bersiaplah untuk mengalami sensasi kemenangan terbesar dan keberuntungan tak terduga di OLXTOTO - platform maxwin dan gacor terbesar sepanjang masa.
    • OLXTOTO - Bandar Togel Online Dan Slot Terbesar Di Indonesia OLXTOTO telah lama dikenal sebagai salah satu bandar online terkemuka di Indonesia, terutama dalam pasar togel dan slot. Dengan reputasi yang solid dan pengalaman bertahun-tahun, OLXTOTO menawarkan platform yang aman dan andal bagi para penggemar perjudian daring. DAFTAR OLXTOTO DISINI DAFTAR OLXTOTO DISINI DAFTAR OLXTOTO DISINI Beragam Permainan Togel Sebagai bandar online terbesar di Indonesia, OLXTOTO menawarkan berbagai macam permainan togel. Mulai dari togel Singapura, togel Hongkong, hingga togel Sidney, pemain memiliki banyak pilihan untuk mencoba keberuntungan mereka. Dengan sistem yang transparan dan hasil yang adil, OLXTOTO memastikan bahwa setiap taruhan diproses dengan cepat dan tanpa keadaan. Slot Online Berkualitas Selain togel, OLXTOTO juga menawarkan berbagai permainan slot online yang menarik. Dari slot klasik hingga slot video modern, pemain dapat menemukan berbagai opsi permainan yang sesuai dengan preferensi mereka. Dengan grafis yang memukau dan fitur bonus yang menggiurkan, pengalaman bermain slot di OLXTOTO tidak akan pernah membosankan. Keamanan dan Kepuasan Pelanggan Terjamin Keamanan dan kepuasan pelanggan merupakan prioritas utama di OLXTOTO. Mereka menggunakan teknologi enkripsi terbaru untuk melindungi data pribadi dan keuangan para pemain. Tim dukungan pelanggan yang ramah dan responsif siap membantu pemain dengan setiap pertanyaan atau masalah yang mereka hadapi. Promosi dan Bonus Menarik OLXTOTO sering menawarkan promosi dan bonus menarik kepada para pemainnya. Mulai dari bonus selamat datang hingga bonus deposit, pemain memiliki kesempatan untuk meningkatkan kemenangan mereka dengan memanfaatkan berbagai penawaran yang tersedia. Penutup Dengan reputasi yang solid, beragam permainan berkualitas, dan komitmen terhadap keamanan dan kepuasan pelanggan, OLXTOTO tetap menjadi salah satu pilihan utama bagi para pecinta judi online di Indonesia. Jika Anda mencari pengalaman berjudi yang menyenangkan dan terpercaya, OLXTOTO layak dipertimbangkan.
    • I have been having a problem with minecraft forge. Any version. Everytime I try to launch it it always comes back with error code 1. I have tried launching from curseforge, from the minecraft launcher. I have also tried resetting my computer to see if that would help. It works on my other computer but that one is too old to run it properly. I have tried with and without mods aswell. Fabric works, optifine works, and MultiMC works aswell but i want to use forge. If you can help with this issue please DM on discord my # is Haole_Dawg#6676
    • Add the latest.log (logs-folder) with sites like https://paste.ee/ and paste the link to it here  
    • I have no idea how a UI mod crashed a whole world but HUGE props to you man, just saved me +2 months of progress!  
  • Topics

×
×
  • Create New...

Important Information

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