diff --git a/src/main/java/net/citizensnpcs/npc/CitizensNPC.java b/src/main/java/net/citizensnpcs/npc/CitizensNPC.java index 796bbb957..5a747e4b1 100644 --- a/src/main/java/net/citizensnpcs/npc/CitizensNPC.java +++ b/src/main/java/net/citizensnpcs/npc/CitizensNPC.java @@ -76,6 +76,13 @@ public class CitizensNPC extends AbstractNPC { return true; } + @Override + public void faceLocation(Location location) { + if (!isSpawned()) + return; + Util.faceLocation(getBukkitEntity(), location); + } + @Override public LivingEntity getBukkitEntity() { return entityController == null ? null : entityController.getBukkitEntity(); diff --git a/src/main/java/net/citizensnpcs/util/Util.java b/src/main/java/net/citizensnpcs/util/Util.java index 2b1515e43..3a2ee9de8 100644 --- a/src/main/java/net/citizensnpcs/util/Util.java +++ b/src/main/java/net/citizensnpcs/util/Util.java @@ -42,12 +42,17 @@ public class Util { public static void faceEntity(LivingEntity from, LivingEntity at) { if (from.getWorld() != at.getWorld()) return; - Location atLocation = at.getLocation(AT_LOCATION); + faceLocation(from, at.getLocation(AT_LOCATION)); + } + + public static void faceLocation(LivingEntity from, Location to) { + if (from.getWorld() != to.getWorld()) + return; Location fromLocation = from.getLocation(FROM_LOCATION); double xDiff, yDiff, zDiff; - xDiff = atLocation.getX() - fromLocation.getX(); - yDiff = atLocation.getY() - fromLocation.getY(); - zDiff = atLocation.getZ() - fromLocation.getZ(); + xDiff = to.getX() - fromLocation.getX(); + yDiff = to.getY() - fromLocation.getY(); + zDiff = to.getZ() - fromLocation.getZ(); double distanceXZ = Math.sqrt(xDiff * xDiff + zDiff * zDiff); double distanceY = Math.sqrt(distanceXZ * distanceXZ + yDiff * yDiff);