Tutorial [INFO]Packets/NMS Explained

Discussion in 'Resources' started by xTrollxDudex, Sep 27, 2013.

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

    Paxination

    xTrollxDudex

    Sweet. I've been thinking about giving packets a chance lately. Been feeling more confident in my coding. I actually understood a lot of that.
     
    xTrollxDudex likes this.
  2. Offline

    xTrollxDudex

    Nice! Good luck, if it fails, keep trying, keep experimenting :)
     
    Garris0n likes this.
  3. Offline

    NoLiver92

    xTrollxDudex you have an excellent bit of code which creates a character based on you but how would you create an npc using packets that has a different name + stave skin (or another skin of my choosing)?
     
  4. Offline

    xTrollxDudex

    NoLiver92
    The skin on an NPC is client-sided. This means if you name the NPC a real, paid minecraft username, then the client renders that NPC with the skin of that user.

    So what does this mean? You're going to have to buy another minecraft account for a custom skin :D! Or just steal the skin of another player. You would have to modify the client in order to have free NPC skins.

    If you choose a character that is not a paid minecraft player, then the client renders the skin as a steve skin.
     
  5. Offline

    malandrix_bunny

    Too bad you cant force downloads on players like some steam games :/
     
  6. Offline

    SourceForums

    xTrollxDudex
    I don't really get how packets work. I can understand what they are, but I have no idea on how I should be using it. For example, how will I code so that only a certain client can see a certain particles effects?
     
  7. Offline

    NoLiver92

    SourceForums They will only see the effect if you send them the packet, so if you dont want players to see the effect you are creating with packets, dont send it to them.
     
  8. Offline

    xTrollxDudex

    SourceForums
    Construct your packet:
    PHP:
    String type //Type from https://gist.github.com/thinkofdeath/5110835
    float x Float.valueOf(/* X coordinate */);
    float y Float.valueOf(/* Y coordinate */);
    float z Float.valueOf(/* Z coordinate */);
    float randSeed 0F
    float data 0F;
    int amount 10

    PacketPlayOutWorldParticles particles = new PacketPlayOutWorldParticles(
        
    typexyzrandSeedrandSeedrandSeeddataamount);
    Now send it!
    PHP:
    CraftPlayer start = (CraftPlayerplayer//Replace player with your player.
    EntityPlayer target start.getHandle();
    PlayerConnection connect target.playerConnection;

    connect.sendPacket(particles);
    Done! Note, you will need to depend on CraftBukkit
     
    xepisolonxx likes this.
  9. Offline

    BungeeTheCookie

  10. Offline

    xTrollxDudex

    BungeeTheCookie
    Whaaaat. Also, in your sig, the universe is not infinite. It's just really big.
     
  11. Offline

    BungeeTheCookie

    At the end. It says, TO BE CONTINUED... why? Also, no one knows how big the universe is. Approximately it is 13.7 billion light years in diameter, that is all that the Hubble Space Telescope can see as of now, which is the most powerful telescope ever invented. I don't know if it can see farther into the universe through the Hubble Deep Field, but that is what I know. So 13.7 billion times seven trillion miles equals alot, so that is why Albert Einstein at the time considered the universe infinite, even though they probably thought the universe was 8 billion light years in diameter at the time of Einstein, I don't really know. Also, the universe is thought to expand at faster than the speed of light every second, which breaks the Laws of Physics. Well, who cares, that's the universes job, to break the Laws of Physics. Anyway, I had that in my signature to make a point. Even though the universe isn't technically "infinite", human stupidity is, so I was trying to make a point for the matter of the subject. If you didn't understand a word I said, I completely get it, my friends think I am insane when I talk like that. :p
     
  12. Offline

    Paxination

    Code:
    p.getHandle().playerConnection.sendPacket(npc);
    In your imaginary character example, do I have to keep sending that packet to keep the npc alive?
     
  13. Offline

    xTrollxDudex

    Paxination
    No you do not. The server handles this for you.
     
  14. Offline

    Paxination

    xTrollxDudex
    Thats what i thought. But he kept dissapearing, at random intervals might I add. I have to put that in a runTaskTimer to keep him alive. I have this as a /clone command atm. Should I be making that code its own class and call NEW thisclass(); on it in stead?

    Also, how do I go about renaming it to get different skins. I've tried using the methods in the player class, but that didnt work. And I looked at the NMS class that you have posted here and I saw this.b.getName(); But not sure how to set the name still as I believe 'b' in that class is the gamer profile which has the player ID, name location yaw pitch.... I tried using OfflinePlayer instead of Player and basically said cant cast to player or something like that.

    How would I make it a default steve skin as well?
     
  15. Offline

    xTrollxDudex

    Paxination
    Since packets aren't supported by bukkit, you're probably seeig a minecraft bug or some status update with the packet.

    If you name the player a non-paid username or a player that doesn't exist, you get a steve skin.
     
  16. Offline

    Paxination

    Yeah I know that, but how. I tried the methods in the craftplayer class and it didnt work.
     
  17. Offline

    xTrollxDudex

    Paxination
    You can't use any Player methods on a packet... Use reflection:
    PHP:
    PacketPlayOutNamedEntitySpawn packet /* Stuff... */;
    try {
        
    Field field packet.getClass().geDeclaredField("b");
        
    field.setAccessible(true);
        
    Object gameProfile field.get(packet);

        
    Field name gameProfile.getClass().getDeclaredField("name");
        
    name.setAccessible(true);
        
    name.set(gameProfile/* The player's name you want as a string */);
    } catch(
    Exception x) {
        
    x.printStackTrace();
    }
     
  18. Offline

    Paxination

    Yeah I just figured out gameProfile was the object I needed to look at.
     
  19. Offline

    Maurdekye

    xTrollxDudex I know this thread is old, but I need some help. I tried to send a Respawn packet to force the player to respawn, but it got all glitchy and I had to relog. I used this line;
    Code:java
    1. ((CraftPlayer) ply).getHandle().playerConnection.sendPacket(new PacketPlayOutRespawn(0, EnumDifficulty.NORMAL, WorldType.FLAT, EnumGamemode.SURVIVAL));

    I recognized the glitchy movement and inability to send chat messages, as it was similar to when you call .remove() on the player's entity. Is there another packet I have to send?
     
  20. Offline

    xTrollxDudex

    Maurdekye
    I believe you should use:
    PHP:
    ((CraftPlayerply).getHandle().playerConnection.a(new PacketPlayInClientCommand(EnumClientCommand.RESPAWN));
     
  21. Offline

    Maurdekye

    xTrollxDudex Instead of, or along with?
    Edit: It's EnumClientCommand.PERFORM_RESPAWN, by the way.
    Edit2: Thanks, it works great!
     
  22. Offline

    xTrollxDudex

  23. Offline

    qlimax5000

    xTrollxDudex

    I've been on this page like 20 times now but i still don't get it.
    I made a thread about my problem but got no takers so i'll just ask you directly.
    I have the PacketPlayOutNamedEntitySpawn that takes EntityHuman.
    How can i change the name value/field of the EntityHuman to do something like making him look like another player?
    Also, how can i use any other packets that this post didn't cover?

    Thanks
     
  24. Offline

    Garris0n

    https://github.com/Bukkit/CraftBukkit
    https://github.com/Bukkit/mc-dev/tree/master/net/minecraft/server
     
  25. Offline

    xTrollxDudex

    qlimax5000
    You can construct a new EntityHuman, or change the fields in the Packet after you are done constructing it.

    Packets are really self explanatory, find the one you want, look it up ok wiki.vg and find the constrructor args, anf build it, send to player.
     
  26. Offline

    Comphenix

    You might want to take a look at TagAPI.
     
    mbaxter likes this.
  27. Offline

    qlimax5000

    xTrollxDudex
    What is the field name for username in this packet? Or how would i make a new EntityHuman?
     
  28. Offline

    Comphenix

    The username is stored in the GameProfile field (getName()). To change it, create a new game profile with a different name and ID, and assign it to the field.

    Since you ignored TagAPI, I'm going to assume you're creating new player entities, and not merely renaming existing players. In that case, you might be better off with extending and adding a custom EntityPlayer/EntityHuman to the world. See if you can get this to work.
     
  29. Offline

    qlimax5000

    Comphenix

    Well... What i want (for now :p) is just a player typing /test and then sending a packet to everyone but him that he's now: 'Whatever name i put, no args just a test plugin for me to learn' and getting the skin, name and everything.
     
  30. Offline

    Freelix2000

    Awesome tutorial, but I have one question. In the example for spawning an imaginary player, how could you spawn a player with a different name, location, and armor/item in hand? I tried using an OfflinePlayer, but I soon found that a CraftPlayer cannot be cast from an OfflinePlayer object.
     
Thread Status:
Not open for further replies.

Share This Page