CraftPlayer head rotation

Discussion in 'Plugin Development' started by CheesyFreezy, Jun 16, 2016.

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

    CheesyFreezy

    Hey guys,

    I am back at it again with a new problem. So I am trying to learn on how to create NPC's. So I did make one, but the head rotation isn't like how I want it. How do I make the head rotation to be set the same as the player's head rotation at the moment when the player executes a command to place the NPC?

    Current problem: https://gyazo.com/ceaca097924cab0b4460c2029c80709b
    Current code:

    Code:
    MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
    WorldServer world = ((CraftWorld) player.getWorld()).getHandle();
                      
    EntityPlayer npc = new EntityPlayer(server, world, new GameProfile(Bukkit.getServer().getPlayer("ItsJasonn").getUniqueId(), ChatColor.GOLD + "" + ChatColor.BOLD + "Dungeons"), new PlayerInteractManager(world));
    npc.teleportTo(player.getLocation(), false);
    npc.pitch = player.getLocation().getPitch();
    npc.yaw = player.getLocation().getYaw();
                      
    for(Player players : Bukkit.getOnlinePlayers()) {
      PlayerConnection connection = ((CraftPlayer) players).getHandle().playerConnection;
      connection.sendPacket(new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.ADD_PLAYER, npc));
      connection.sendPacket(new PacketPlayOutNamedEntitySpawn(npc));
      connection.sendPacket(new PacketPlayOutEntityEquipment(npc.getId(), EnumItemSlot.HEAD, CraftItemStack.asNMSCopy(new ItemStack(Material.GOLD_HELMET))));
      connection.sendPacket(new PacketPlayOutEntityEquipment(npc.getId(), EnumItemSlot.CHEST, CraftItemStack.asNMSCopy(new ItemStack(Material.CHAINMAIL_CHESTPLATE))));
      connection.sendPacket(new PacketPlayOutEntityEquipment(npc.getId(), EnumItemSlot.LEGS, CraftItemStack.asNMSCopy(new ItemStack(Material.CHAINMAIL_LEGGINGS))));
      connection.sendPacket(new PacketPlayOutEntityEquipment(npc.getId(), EnumItemSlot.FEET, CraftItemStack.asNMSCopy(new ItemStack(Material.CHAINMAIL_BOOTS))));
      connection.sendPacket(new PacketPlayOutEntityEquipment(npc.getId(), EnumItemSlot.MAINHAND, CraftItemStack.asNMSCopy(new ItemStack(Material.WOOD_SWORD))));
      connection.sendPacket(new PacketPlayOutEntityEquipment(npc.getId(), EnumItemSlot.OFFHAND, CraftItemStack.asNMSCopy(new ItemStack(Material.BOW))));
    }
     
  2. Offline

    Zombie_Striker

Thread Status:
Not open for further replies.

Share This Page