[NMS] Entity move packets!

Discussion in 'Plugin Development' started by xXBeLkAXx, Aug 25, 2014.

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

    xXBeLkAXx

    Guys, I'm making a disguises. My mob spawns, but moves not good. Here is my code -
    Code:java
    1. public static void walk( String playerName, Location old, Location newLoc )
    2. {
    3. if( ids.containsKey( playerName ) )
    4. {
    5. PacketPlayOutRelEntityMoveLook packet = new PacketPlayOutRelEntityMoveLook(
    6. ids.get( playerName ),
    7. (byte) ((newLoc.getBlockX() - old.getBlockX()) * 32), // Fixed Point Format
    8. (byte) ((newLoc.getBlockY() - old.getBlockY()) * 32), // Fixed Point Format
    9. (byte) ((newLoc.getBlockZ() - old.getBlockZ()) * 32), // Fixed Point Format
    10. (byte) ((newLoc.getYaw() + 180) / 360), // Site says "fraction of 360", might need tweaking
    11. (byte) ((newLoc.getPitch() + 180) / 360)); // Site says "fraction of 360", might need tweaking
    12. PacketPlayOutEntityHeadRotation packett = new PacketPlayOutEntityHeadRotation();
    13. PacketPlayOutEntityLook packettt = new PacketPlayOutEntityLook(ids.get(playerName),(byte) ((newLoc.getYaw() + 180) / 360), (byte) ((newLoc.getPitch() + 180) / 360));
    14. PacketPlayOutEntityVelocity packetttt = new PacketPlayOutEntityVelocity(ids.get(playerName), Bukkit.getPlayer(playerName).getVelocity().getX(), Bukkit.getPlayer(playerName).getVelocity().getY(), Bukkit.getPlayer(playerName).getVelocity().getZ());
    15. PacketPlayOutRelEntityMove pack = new PacketPlayOutRelEntityMove(ids.get(playerName),
    16. (byte) ((newLoc.getBlockX() - old.getBlockX()) * 32), // Fixed Point Format
    17. (byte) ((newLoc.getBlockY() - old.getBlockY()) * 32), // Fixed Point Format
    18. (byte) ((newLoc.getBlockZ() - old.getBlockZ()) * 32));
    19. try {
    20. Field f = packett.getClass().getDeclaredField("a");
    21. f.setAccessible(true);
    22. f.set(packett, ids.get(playerName));
    23. f.setAccessible(false);
    24.  
    25. Field ff = packett.getClass().getDeclaredField("b");
    26. ff.setAccessible(true);
    27. ff.set(packett, (byte) ((newLoc.getYaw() * 256.0F) / 360.0F));
    28. ff.setAccessible(false);
    29. } catch (Exception ex) {
    30. ex.printStackTrace();
    31. }
    32.  
    33. for( Player p : Bukkit.getServer().getOnlinePlayers() )
    34. {
    35. ((CraftPlayer)p).getHandle().playerConnection.sendPacket(packet);
    36. ((CraftPlayer)p).getHandle().playerConnection.sendPacket(packett);
    37. ((CraftPlayer)p).getHandle().playerConnection.sendPacket(packettt);
    38. ((CraftPlayer)p).getHandle().playerConnection.sendPacket(packetttt);
    39. ((CraftPlayer)p).getHandle().playerConnection.sendPacket(pack);
    40. }
    41.  
    42. }
    43. }

    What I should do, what packets I should add, or remove? Or what arguments in the packets I should change?
     
  2. Just curious, why do you want to create a disguise plugin? Why not just use libs disguises?
     
  3. Offline

    xXBeLkAXx

    Bram0101
    I want to learn NMS. It has a lot of interesting interfaces.
     
Thread Status:
Not open for further replies.

Share This Page