Solved Changing an EntityPlayer's head rotation.

Discussion in 'Spigot Plugin Development' started by Martoph, Oct 17, 2016.

  1. I need to change the head position of an EntityPlayer, currently I'm doing this through packets (of course). My code wont change the head position, I've tried a lot of things. The head position is based on the yaw of the armorstand.
    Code (Text):

        public NPCEntity(MinecraftServer minecraftserver, WorldServer worldserver, GameProfile gameprofile, PlayerInteractManager playerinteractmanager) {
            super(minecraftserver, worldserver, gameprofile, playerinteractmanager);
    Code (Text):
    public static void spawnEntity(ArmorStand armorStand, GameProfile profile) {

            Location location = armorStand.getLocation();
            World world = location.getWorld();
            MinecraftServer nmsServer = ((CraftServer) Bukkit.getServer()).getServer();
            WorldServer nmsWorldServer = ((CraftWorld) world).getHandle();
            final NPCEntity npc = new NPCEntity(nmsServer, nmsWorldServer, profile, new PlayerInteractManager(nmsWorldServer));
            npc.teleportTo(location, false);
            npc.setPosition(location.getX(), location.getY(), location.getZ());
            npc.setYawPitch(location.getYaw(), location.getPitch());

            for(Player player : Bukkit.getOnlinePlayers()) {
                ClientConnectionUtil.sendPacket(player, new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, npc));
                ClientConnectionUtil.sendPacket(player, new PacketPlayOutNamedEntitySpawn(npc));
  2. It's either pitch or yaw, can't remember which. You can just do
    Code (Text):
    Code (Text):
  3. Choco


    Yaw is along the x and z axis. Pitch is along the y axis
    • Informative Informative x 2
  4. I'm sorry, but you must not have read any of my code.

    This is an EntityPlayer, which is sent by packets. You can't change the head position like that because it's not part of Spigot's API, it's NMS programming. Also, the variable "p" isn't even in my code. So for future reference, I suggest you use the variables that the OP provides.
  5. We aren't going to spoonfeed you. You can change the head rotation in this way, I've done it 1000 times. Finally, just case EntityPlayer to Player and call it p
  6. Kinda in a forum where spoonfeeding is prominent.

    I'll try that when I get the chance.
  7. Yes, spoonfeeding is prominent here however most of us do not like it.
    • Agree Agree x 1
  8. We all have different styles of programming, saying "heres the answer: 'p.getLocation'" when no steps on how to get there frustrates the OP. I have never used that variable in the original post, and I didn't have a clue to what you were referring to.

    Also, for the record, you can't cast EntityPlayer to Player. Throws errors.
  9. You can, you just have to cast to CraftPlayer first and do #getHandle():
    Code (Text):
    EntityPlayer ep = ((CraftPlayer) p).getHandle();
  11. What?
    EDIT: Oh, I didn't literally mean do
    Code (Text):
    EntityPlayer ep = (EntityPlayer) p;
    I meant do the proper thing. I don't want to spoonfeed him
  12. You're casting entityPlayer to entityplayer....

    You want to cast EntityPlayer to Player. Which you can't do.

    If you're not going to help, I would appreciate it if you don't.
  13. I recommend you look through the MCP mappings and their should be something there with yaw and pitch, then simply use that field.
  14. Hmm, thanks for the suggestion. Will take a look at it.
  15. We've given you the answer, we're not going to spoonfeed you on how to implement it now.
  16. No you haven't..... -_-
  17. PacketPlayOutEntityHeadRotation
    • Winner Winner x 2
  18. But EntityPlayer#asBukkitEntity or so is a thing
  19. it still works
    • Like Like x 1
  20. Thanks. Didn't know this was a thing!

    Problem Solved.