Jump to content

How to properly send a packet on a button click.


c-ab-o-o-s-e

Recommended Posts

All I am wanting to do is properly send a packet to the server and handle it properly when a user clicks a button in the Inventory. I have not messed with these before and looking at source code I have the packets setup and ready to go. I just don't know how to pass the button Id properly. Like wont I need the cordinates for where the TileEntity is? So in the gui when I send the packet I will need to send the TileEntity with it? I seen some people do the

modID.network.sendToServer()

and the

modID.network.getPacketFrom()

I don't know which one to use. My issue is that I got to see it finished to understand it. If I had a good source code that shows a process like that I would look at that. I tired looking at Mekanism, but seems like its all over the place. I'm pretty sure once I figure this one out afterwards it wont be too hard to understand. I got the Message class and all the needed classes for to send the packet I just don't know how to link it.

Link to comment
Share on other sites

ok so I would send the packet

ModID.network.sendToServer(new MessageGuiButton(button.id));

and then in the Handler class have the onMessage() take in the Id and get the player, container, and finally the TileEntity. And since we are getting the TileEntity that way it already knows what one we are talking about. Is that correct?

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.



×
×
  • Create New...

Important Information

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