Jump to content

Sending Packets to server


Skw972

Recommended Posts

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

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

Link to comment
Share on other sites

  • 1 year later...
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
        );
    }

 

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

    • the mods are crashing and I'm not sure why so heres everything  crash log https://pastebin.com/RxLKbMNR  L2 Library (12library) has failed to load correctly java.lang.NoClassDefFoundError: org/antarcticgardens/newage/content/energiser/EnergiserBlock L2 Screen Tracker (12screentracker) has failed to load correctly java.lang.NoClassDefFoundError: Could not initialize class dev.xkmc.12library.base.L2Registrate Create: Interiors (interiors) has failed to load correctly java.lang.NoClassDefFoundError: Could not initialize class com.tterrag.registrate.AbstractRegistrate L2 Damage Tracker (12damagetracker) has failed to load correctly java.lang.NoClassDefFoundError: Could not initialize class dev.xkmc.l2library.base.L2Registrate Create Enchantment Industry (create_enchantment_industry) has failed to load correctly java.lang.NoClassDefFoundError: Could not initialize class com.simibubi.create.foundation.data.Createfiegistrate Create Crafts & Additions (createaddition) has failed to load correctly java.lang.NoClassDefFoundError: Could not initialize class com.simibubi.create.foundation.data.CreateRegistrate Create Slice & Dice (sliceanddice) has failed to load correctly java.lang.NoClassDefFoundError: Could not initialize class com.simibubi.create.foundation.data.CreateRegistrate L2 Tabs (12tabs) has failed to load correctly java.lang.NoClassDefFoundError: Could not initialize class dev.xkmc.l2library.base.L2Registrate Modular Golems (modulargolems) has failed to load correctly java.lang.NoClassDefFoundError: Could not initialize class dev.xkmc.l2library.base.L2Registrate Create: Steam 'n' FRails (railways) has failed to load correctly java.lang.NoClassDefFoundError : Could not initialize class com.simibubi.create.foundation.data.Createfregistrate Cuisine Delight (cuisinedelight) has failed to load correctly java.lang.NoClassDefFoundError: Could not initialize class dev.xkmc.12library.base.L2Registrate Create (create) has failed to load correctly java.lang.NoClassDefFoundError: Could not initialize class com.simibubi.create.Create Guardian Beam Defense (creategbd) has failed to load correctly java.lang.NoClassDefFoundError: Could not initialize class com.simibubi.create.foundation.data.CreateRegistrate L2 Item Selector (12itemselector) has failed to load correctly java.lang.NoClassDefFoundError: Could not initialize class dev.xkmc.l2library.base.L2Registrate
    • hey there, I have been using Forge for years without any problems, but for some time now I have been getting this error message when I click on “Installer” under the downloads. This happens on all versions. I have tried various things but have not gotten any results. If anyone has a solution, I would be very grateful!
    • I don't have mcreator installed.
    • the session has expired, what if the modified LAN Server displays the same screen after logging in as after logging in to the premium server from a non-premium account? Minecraft Forge 1.20.1 CurseForge. I also use Mod LAN World Plug n Play
    • Hello There! In today's video I will be showing you guys the Minecraft and Google Collaboration they are doing for the 15th anniversary for Minecraft! If you guys wanna try this out for yourself go to google and type in "Minecraft"!  
  • Topics

×
×
  • Create New...

Important Information

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