mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-24 03:25:13 +01:00
Implement new helper methods
This commit is contained in:
parent
0a155a7d10
commit
4bff8784d3
@ -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();
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user