1. Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!

Dismiss Notice
This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

MundoSK Packets

Discussion in 'Tutorials' started by Tlatoani, Feb 2, 2017.

  1. Tlatoani

    Addon Developer

    Joined:
    Jan 24, 2017
    Messages:
    151
    Likes Received:
    89
    Medals:
    This is a tutorial that will teach you how to use packets.

    What are packets?

    Packets are what Minecraft uses to send information between a server and client. Each packet has a packettype. Packettypes describe what kind of information a packet holds and for what purpose that information should be used. There are two main kinds of packettypes: server and client. Server packettypes describe packets that are sent to a client from the server, and client packettypes describe packets that are received by the server from the client. Every packettype has a name that looks kinda like this: play_server_player_info. Here, play is that packettypes's group (Another classification of packets that you don't need to worry about) server means that that packettype is a server packettype, and player_info is the rest of its name.

    How do we get a packet?

    There are two ways you can get an actual packet: intercepting one by using a packet event, or creating one yourself. Packet events are called when a packet is either sent or received. They look like this:

    Code (Skript):
    1. on packet event %packettypes%:
    2.     #do stuff
    This event has the following event-values:

    Code (Skript):
    1. event-packet #(The packet being sent/received)
    2. event-packettype #(The packettype of the packet)
    3. event-player #(The player sending/receiving)
    And can also be cancelled.

    Packet creation is done using this simple expression:

    Code (Skript):
    1. new %packettype% packet
    What information is stored in a packet, and how do we access and modify it?

    Now that you have access to a packet, you can modify its information. Here's a list of all the different syntaxes for packet information:

    Code (Skript):
    1. %type% pinfo %number% of %packet%
    2. %type% array pinfo %number% of %packet%
    3. %string% pinfo %number% of %packet%
    4. %world% pentity %number% of %packet%
    5. byte pnum %number% of %packet%
    6. short pnum %number% of %packet%
    7. int pnum %number% of %packet%
    8. long pnum %number% of %packet%
    9. float pnum %number% of %packet%
    10. double pnum %number% of %packet%
    11. byte array pnum %number% of %packet%
    12. int array pnum %number% of %packet%
    13. %string% pjson %number% of %packet%
    14. %string% array pjson %number% of %packet%
    15. %string% penum %number% of %packet%
    Here, %number% is the index (starting from 0) and %packet% is the packet you are getting information from.
    • The first two allow you to put in a type, like 'string', to get all the strings. Keep in mind this doesn't work for all types.
    • The third one allows you to specify the method name for getting infos of a specific type in special cases.
    • The fourth allows you to get all the entities of the packet provided you specify the world (Either player's world or the world of the player who you will send to)
    • 5 through 12 allow you to get infos of different number types.
    • The next two are for getting infos of types that aren't in Skript yet, only one of which is supported - "ChatComponent" for the first one (Not the second one). Doing things with JsonObjects should be pretty easy if you look at skUnity. If not, feel free to ask questions on the MundoSK skUnity thread.
    • The last one is for modifying enum values of packets, where %string% is the name of the enum, like "WorldBorderAction".

    All these infos are setttable, which is very important, as it allows you to modify the information in the packet.

    How do we send and simulate receiving packets?

    To send a packet that you have created, use this effect:

    Code (Skript):
    1. send %players% packet[s] %packets%
    You can simulate the server receiving a packet from a player using this effect:

    Code (Skript):
    1. receive packet[s] %packets% from %players%
    Helpful Resources

    wiki.vg provides a list of packets, their fields, and what their fields represent. It can be useful for knowing what each pinfo of a packet means, however most of the packet names are different from their MundoSK names (which are based on their ProtocolLib names), and the fields aren't always 100% the same.

    PacketWrapper created by one of ProtocolLib's developers is a library of wrappers for all the packets, It has methods that tell you exactly what each pinfo represents and sometimes also has int values telling you what an int pnum's different values mean. It was made for 1.11, but if you go through its history you will be able to see older versions of the wrappers for previous versions.

    The PacketType class from ProtocolLib has a 100% up-to-date list of all of the packettypes available.

    The EnumWrappers class from ProtocolLib has a list of all the enums/values that can be used in the penum expression.

    Questions? Comments? Suggestions or improvements? Comment below!
     
    #1 Tlatoani, Feb 2, 2017
    Last edited: Sep 16, 2017
    • Like Like x 5
  2. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,052
    Likes Received:
    144
    How can i use the play_client_look packet. What do i need to change to make the player rotate or look in a specified direction?
     
  3. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,052
    Likes Received:
    144
    In the play_client_look packet, the float 0 is the yaw and the float 1 is the pitch. Keep in mind that this is a client packet, so you will have to make the server receive the packet from whoever you are rotating (unless you are modifying an intercepted packet)
     
  4. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,052
    Likes Received:
    144
    Thanks
    --- Double Post Merged, Mar 3, 2017, Original Post Date: Mar 3, 2017 ---
    command /rotate:
    trigger:
    set {_} to new play_client_look packet
    set float pnum 1 of {_} to 90
    receive packet {_} from player

    I did this and typed /rotate but i wont get rotated?
     
  5. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,052
    Likes Received:
    144
    You mean you didn't get rotated yourself, or that other players didn't see you get rotated?
     
  6. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,052
    Likes Received:
    144
    I did not get rotated
     
  7. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,052
    Likes Received:
    144
    That is what you would expect to happen by usig his packet. If you want to get rotated yourself, it is better to use the normal expression for yaw and pitch,
    Code (Skript):
    1. set %player%'s pitch to 90
    The only thing is that this will require RandomSK (or another addon that has it).

    If you only want to rotate yourself without other players seeing it, then you have to use the
    Code (Skript):
    1. play_server_position
    packet, which I do not know exactly how to use, but I can find out if that it what you want to do.
     
  8. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,052
    Likes Received:
    144
    My goal was to rotate the player further than normaly posible this is done in de CraftVenture server in 1.11 in 1.8 you can do that by opening the chat or a Inventory. So i am trying to do the same in 1.11 but using packets
    --- Double Post Merged, Mar 4, 2017, Original Post Date: Mar 4, 2017 ---
    So if you could help me with the packets maybe it works, it would be awesome :emoji_slight_smile:
    --- Double Post Merged, Mar 4, 2017 ---
    I have tried it and i think it works, One problem though, when i send the player the packet al blocks will be invisible and you will have to reload the chunks to make them visible again :/
     
  9. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,052
    Likes Received:
    144
    Good to see that you got it to work, for the chunks thing if reloading the chunks fixes it then that is the best you can do probably. I am trying to see if the expression for pitch from RandomSK works, but it does not seem to be doing anything at all.
     
  10. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,052
    Likes Received:
    144
    Okay thanks for the help! i hope you can figure a way out to make the chunks not unload themselfs :emoji_slight_smile:
     
  11. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,052
    Likes Received:
    144
  12. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,052
    Likes Received:
    144
    Hey, great tutorial, I'm a huge noob when it comes to packets and I'm trying to modify the player list shown when a player hovers over the player count while in the server browser

    This is what I'm talking about:
    http://i.imgur.com/T8FfgPZ.png

    Some servers modify it to have a fancy Motd in them as shown in that picture but I personally don't want to do that, I just want it to hide the list/show nothing simply because I don't want players to know who is online without joining the server, after some searching around I read on a few different forum posts that it was possible to modify that player list through packets, like I said I'm a huge noob when it comes to packets so I kinda just want to know if I'm on the right track or not, I believe this is the packet event I should be working with?:
    http://wiki.vg/Protocol#Request

    which I'm not sure if that is the packet event I should be listening for but if it is I tried:
    on packet event status_serverbound_request:

    and a few other variations of that but I haven't had any luck getting it right, so I was hoping you can lead me in the right direction, I probably have the wrong packet or doing something obvious wrong so I rather ask for some help here
     
  13. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,052
    Likes Received:
    144
    Hello, and thanks!

    The first thing you will want to know is that the packet names used in MundoSK are different from the ones you will find in wiki.vg as they are based on the names used by ProtocolLib, you can find a list of the packettypes from ProtocolLib here. Instead of writing clientbound or serverbound, you just write server, or client - server and client actually signify where they are coming from, so server in ProtocolLib packets = clientbound from wiki.vg and client = serverbound. In addition to this mix-up, they also may have completely different names in ProtocolLib and wiki.vg, like in this case there does not appear to be any packet named status_client_request.

    In this case however, we want to focus on a server packet (clientbound) as that will be sent to the client containing the player list, which is what we want to modify. In this case this would appear to be the packet status_server_server_info, so that's the packet you will want to use.
     
  14. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,052
    Likes Received:
    144
    Ah I see, thank you very much, this information is super helpful
     
    • Like Like x 1
  15. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,052
    Likes Received:
    144
    How to use PLAY_CLIENT_BLOCK_CHANGE packet?

    http://imgur.com/cmV5fzL

    Type is position, how i can modify this packet?
    (Sorry for bad my english)
     
  16. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,052
    Likes Received:
    144
    Position fields are modified using the location pinfo, syntax:
    Code (Skript):
    1. location pinfo %number% of %packet%
     
  17. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,052
    Likes Received:
    144
    Code (Skript):
    1. command /test:
    2.  trigger:
    3.   set {_player} to player
    4.   set {_loc} to location of targeted block
    5.   set {_packet} to new PLAY_SERVER_BLOCK_CHANGE packet
    6.   set location pinfo 0 of {_packet} to {_loc}
    7.   set int pnum 0 of {_packet} to 56
    8.   send {_player} packet {_packet}
    This is my code.
    I am not get error but is not working.
    I don't see the block change.

    Where is error?
     
  18. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,052
    Likes Received:
    144
    The play_server_block_change packet doesn't have an int pnum, but it does need a different pinfo known as "blockdata". I added a converter for this pinfo in the BETA.7.148 version (download: Download), so you can use it like this:
    Code (Skript):
    1. blockdata pinfo %number% of %packet%
    For example:
    Code (Skript):
    1. set blockdata pinfo 0 of {_packet} to emerald block
     
  19. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,052
    Likes Received:
    144
    My code:
    Code (Skript):
    1. command /test:
    2.     trigger:
    3.         set {_packet} to new PLAY_CLIENT_LOOK packet
    4.         wait a second
    5.         set float pnum 0 of {_packet} to 90
    6.         send player packet {_packet}
    I get error: https://pastebin.com/KrbES6Xc
     
  20. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,052
    Likes Received:
    144
    You can't send client packets to the player, you have to use the packet receive effect for make the player receive that packet. But do you know what that packet does? What are you trying to achieve with this?
     
Loading...