Jump to content

Recommended Posts

Posted

Hi. I need your help. I want to send a packet to the server which makes mi click item in the chosen slot. I already have gui, Container and Slot but don't know how to send packets. I created channel and Network but there are no tutorials how to send packet to do something in gui. Can somebody help me or send a tutorial where someone tells how to perform actions in gui. Like putting or taking items.

Posted

you can get the current AbstractContainerMenu from the player it's a public field,
make sure before you interacte with the Menu your are on Server and ServerPlayer#containerCounter match with the
containerId of the Menu. Then you can get the Slot via AbstractContainerMenu#getSlot

Posted

But I don't think you understand what I mean. I already have gui and a Slot. I need to create mod only for client because I want to use it not on my server. And I want to take an item or click the chosen Slot in the gui. I just need to make server register this action.

Posted (edited)

This will not work client only, it also sounds like cheating...
If this is your server, why did you not create a Mod for both server and client

Edited by Luis_ST
spelling mistake
Posted
4 minutes ago, Luis_ST said:

This will not work client only, it also sounds like cheating...
If this is your server, why did you not create a Mob for both server and client

???. I said it isn't my server and what do you mean by creating a Mob? I don't need any mobs.

Posted (edited)
4 minutes ago, Skw972 said:

I said it isn't my server and what do you mean by creating a Mob?

it was a spelling mistake😅, i already fixed it
What exactly did you try to achieve?

Edited by Luis_ST
Posted (edited)
On 3/28/2022 at 9:13 PM, Luis_ST said:

it was a spelling mistake😅, i already fixed it
What exactly did you try to achieve?

I'm trying to click in the chosen slot when player opens a gui. I already made a event which checks if gui is correct and I already have chosen slot. Now I only need to click this slot from client side but I have to make it register on the server. So if I click item in chest it makes it click on the server too. Just like the player normally clicked it. I could create a list of coordinates for every slot and then move it to chosen coords and make mouse click in program but I know that there has to be a better way to do it.

Edited by Skw972
Posted
52 minutes ago, Skw972 said:

I'm trying to click in the chosen slot when player opens a gui. I already made a event which checks if gui is correct and I already have chosen slot. Now I only need to click this slot from client side but I have to make it register on the server. So if I click item in chest it makes it click on the server too. Just like the player normally clicked it.

this is not the reason for why you do this from client

53 minutes ago, Skw972 said:

I know that there has to be a better way to do it.

yeah do it from server

  • 1 year later...
Posted
On 2/10/2024 at 11:35 PM, LZDQ said:

Bro I wrote a python script to sort my slots. I send http request from java to python and sort my slots within 1s.

Hi there. Today I figured out how to send a packet of swapping two items in inventory by hovering on one and press the hotbar button of another. Clicking one is similar.

First I intercept all the outgoing packets and found one called `net.minecraft.network.protocol.game.ServerboundContainerClickPacket` which does the exactly thing you wished for.

Then search the source code (I get it in intellij idea's cache) and use grep to find all occurences (or you can use intellij or other IDE to grab all references but my IDEs all failed to do that) and read the code. Finally the wrapper for doing modification client-side and sending packet is `Minecraft.getInstance().gameMode.handleInventoryMouseClick`.

My code here:
 

    private static void swapSlot(int slot_from, int slot_to){
        // slot_from is the inventory id (for hotbar, it is [36, 45) )
        // slot_to is the hotbar id [0, 9)
        Minecraft mc = Minecraft.getInstance();
        //mc.player.sendOpenInventory();   We don't even need to open the inventory. Actually there is not a packet telling server to open inventory, only a packet of telling server to close it but we don't need it either.
        //Inventory inventory = mc.player.getInventory();
        InventoryMenu inv_menu = mc.player.inventoryMenu;
        mc.gameMode.handleInventoryMouseClick(
                inv_menu.containerId,
                slot_from,
                slot_to,
                ClickType.SWAP,
                mc.player
        );
    }

 

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.