package de.craften.plugins.managedentities.util.nms;

import net.minecraft.server.v1_8_R3.Entity;
import net.minecraft.server.v1_8_R3.NBTTagCompound;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity;
import org.bukkit.entity.LivingEntity;

/**
 * NMS utility methods for entities.
 */
public class NmsEntityUtil {
    /**
     * Disables the AI for the given entity.
     *
     * @param entity entity
     */
    public static void disableAi(LivingEntity entity) {
        Entity nmsEntity = ((CraftEntity) entity).getHandle();
        NBTTagCompound tag = nmsEntity.getNBTTag();
        if (tag == null) {
            tag = new NBTTagCompound();
        }
        nmsEntity.c(tag);
        tag.setInt("NoAI", 1);
        nmsEntity.f(tag);
    }

    /**
     * Sets whether the entity is invulnerable. This only blocks players in survival or adventure mode from hurting
     * the entity.
     *
     * @param entity       entity
     * @param invulnerable whether the entity should be invulnerable
     */
    public static void setInvulnerable(LivingEntity entity, boolean invulnerable) {
        Entity nmsEntity = ((CraftEntity) entity).getHandle();
        NBTTagCompound tag = nmsEntity.getNBTTag();
        if (tag == null) {
            tag = new NBTTagCompound();
        }
        nmsEntity.c(tag);
        tag.setInt("Invulnerable", invulnerable ? 1 : 0);
        nmsEntity.f(tag);
    }
}

@@ -87,24 +87,74 @@
 _R3.Entity;%0A
+import net.minecraft.server.v1_8_R3.EntityLiving;%0A
 import net.m
@@ -247,24 +247,88 @@
 raftEntity;%0A
+import org.bukkit.craftbukkit.v1_8_R3.entity.CraftLivingEntity;%0A
 import org.b
@@ -1515,11 +1515,457 @@
 );%0A    %7D
+%0A%0A    public static void setHeadRotation(LivingEntity entity, float yaw, float pitch) %7B%0A        EntityLiving nmsEntity = ((CraftLivingEntity) entity).getHandle();%0A        nmsEntity.f(clampYaw(yaw));%0A        nmsEntity.g(pitch);%0A    %7D%0A%0A    private static float clampYaw(float yaw) %7B%0A        while (yaw %3C -180.0F) %7B%0A            yaw += 360.0F;%0A        %7D%0A%0A        while (yaw %3E= 180.0F) %7B%0A            yaw -= 360.0F;%0A        %7D%0A%0A        return yaw;%0A    %7D
 %0A%7D%0A

Add a utility method to set the head rotation of a living entity.