Implement new helper methods

This commit is contained in:
fullwall 2013-07-28 22:13:51 +08:00
parent 82321b7d19
commit a84fbbbe53
2 changed files with 16 additions and 4 deletions

View File

@ -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();

View File

@ -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);