Complicated Packets (Not Really xD)

Discussion in 'Plugin Development' started by Cloaking_Ocean, Apr 2, 2014.

Thread Status:
Not open for further replies.
  1. Offline


    So I've been trying to figure out what packets are and how to use them. I've noticed package usage in plugins such as "disguise craft" and "Werewolf" were they send the player a packet make the player see another player with a different skin. Upon googling I found this link, but I'm still a bit confused. First off,
    In his code
    CraftPlayer p = (CraftPlayer) player;
    PacketPlayOutNamedEntitySpawn npc = new PacketPlayOutNamedEntitySpawn(p.getHandle());
    //the a field used to be public, we'll need to use reflection to access:
    try {
        Field field = npc.getClass().getDeclaredField("a");
        field.setAccessable(true);// allows us to access the field
        field.setInt(npc, 123);// sets the field to an integer
        field.setAccessable(!field.isAccessable());//we want to stop accessing this now
    } catch(Exception x) {
    //now comes the sending
    What does the "PacketPlayOutNamedEntitySpawn" mean? Does it mean it's spawning a named entity and is the entity maybe a villager because the name of the variable is npc? And then with the fields. So setting the field a to (npc, 123) does what? and after wards is it just sending the player a message? Or sending the player a packet and if so, what is on the packet?

    Sorry I've been look around for a couple of hours on more detailed examples of packet usage but I just haven't found any.

    I've seen threads that have an idea like a player having a piece of red wool set as his hat, and then a packet is sent to another player and to that player the first player is wearing a blue piece of wool. This seems like it's a pretty simple concept, I just would like to know how to use packets, send packets, and edit packets.

    Any Help is appreciated GREATLY! Thanks in advance.
  2. Offline


    I'm going to try to take a shot at this. Go ahead and open up this resource:

    The first part of PacketPlayOutNamedEntitySpawn is Packet, denoting that this class is, in fact, a packet.

    Next, we have Play. According to the resource, there are four types of packets: Handshaking (initial connection), Play (something happens), Status (pinging), and Login.

    Next up is Out. This tells us that the packet is outbound. It's headed for the client.

    Finally, we have NamedEntitySpawn. That appears to correspond with this:

    Hope that helped. Again, this is speculation based on that website I got from the Packets Explained resource.
  3. Offline


    I watched your latest Bukkit Coding video on Youtube.... trolled so hard...
    PogoStick29 and Wolfey like this.
  4. Offline


    amhokies I was suspicious in the beginning, but I decided to give it a try anyways.

    As soon as I saw the AprilFoolsException, I was like "I KNEW IT".
    PogoStick29 likes this.
  5. Offline

    CaptainBern Retired Staff

    Cloaking_Ocean If you're new to packets then I suggest you to stay away from this packet and first try come others. Packets aren't that hard but this one can be considered one of the hardest, mostly because of the DataWatcher (well that's my opinion). First play around with other packets, then spawn a fake entity and then start playing with this packet.

    If you do want to continue you can take a look at my NPC-Lib (do not use any of it's code since it's nowhere near finished and in it's current state breaks servers :) )

    In my lib I created a util to easily create a spawn-packet, you can see it here
  6. Offline


    CaptainBern Okay thanks. Umm so if that kind is too hard to understand for now what do you suggest I do first? What did you learn first?
  7. Offline


  8. Offline


    Packets are used to send information to client and server, communication.
  9. Offline


    PacketPlayOutNamedEntitySpawn is for "named entities", which only consists of players. (
    PacketPlayOutSpawnEntityLiving is for living entities. (
    PacketPlayOutSpawnEntity is for (most) other entities. (
    PacketPlayOutSpawnEntityWeather is for lightning. (
    PacketPlayOutSpawnEntityPainting is for paintings. (
    PacketPlayOutSpawnEntityExperienceOrb is for XP orbs. (

    Just went to watch it, that was great.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: Jun 7, 2016
Thread Status:
Not open for further replies.

Share This Page