Skip to content

Commit

Permalink
Add immediate parameter to Util.faceLocation and fix a bug in it
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Dec 16, 2016
1 parent 1bd3b7e commit cf5beab
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 24 deletions.
4 changes: 2 additions & 2 deletions main/src/main/java/net/citizensnpcs/util/NMS.java
Expand Up @@ -156,8 +156,8 @@ public static void look(Entity entity, float yaw, float pitch) {
BRIDGE.look(entity, yaw, pitch);
}

public static void look(org.bukkit.entity.Entity entity, Location to, boolean headOnly) {
BRIDGE.look(entity, to, headOnly);
public static void look(org.bukkit.entity.Entity entity, Location to, boolean headOnly, boolean immediate) {
BRIDGE.look(entity, to, headOnly, immediate);
}

public static void look(org.bukkit.entity.Entity bhandle, org.bukkit.entity.Entity btarget) {
Expand Down
2 changes: 1 addition & 1 deletion main/src/main/java/net/citizensnpcs/util/NMSBridge.java
Expand Up @@ -82,7 +82,7 @@ public interface NMSBridge {

public void look(Entity entity, float yaw, float pitch);

public void look(Entity entity, Location to, boolean headOnly);
public void look(Entity entity, Location to, boolean headOnly, boolean immediate);

public void mount(Entity entity, Entity passenger);

Expand Down
6 changes: 5 additions & 1 deletion main/src/main/java/net/citizensnpcs/util/Util.java
Expand Up @@ -66,9 +66,13 @@ public static void faceLocation(Entity entity, Location to) {
}

public static void faceLocation(Entity entity, Location to, boolean headOnly) {
faceLocation(entity, to, headOnly, true);
}

public static void faceLocation(Entity entity, Location to, boolean headOnly, boolean immediate) {
if (to == null || entity.getWorld() != to.getWorld())
return;
NMS.look(entity, to, headOnly);
NMS.look(entity, to, headOnly, immediate);
}

public static Location getEyeLocation(Entity entity) {
Expand Down
Expand Up @@ -383,7 +383,7 @@ public void setTargetLook(Entity target, float yawOffset, float renderOffset) {
}

public void setTargetLook(Location target) {
controllerLook.a(target.getX(), target.getY(), target.getZ(), target.getYaw(), target.getPitch());
controllerLook.a(target.getX(), target.getY(), target.getZ(), 10, 40);
}

public void updateAI() {
Expand Down
Expand Up @@ -605,9 +605,9 @@ public void look(org.bukkit.entity.Entity entity, float yaw, float pitch) {
}

@Override
public void look(org.bukkit.entity.Entity entity, Location to, boolean headOnly) {
public void look(org.bukkit.entity.Entity entity, Location to, boolean headOnly, boolean immediate) {
Entity handle = NMSImpl.getHandle(entity);
if (headOnly || BAD_CONTROLLER_LOOK.contains(handle.getBukkitEntity().getType())
if (immediate || headOnly || BAD_CONTROLLER_LOOK.contains(handle.getBukkitEntity().getType())
|| (!(handle instanceof EntityInsentient) && !(handle instanceof EntityHumanNPC))) {
Location fromLocation = entity.getLocation(FROM_LOCATION);
double xDiff, yDiff, zDiff;
Expand Down Expand Up @@ -635,8 +635,8 @@ public void look(org.bukkit.entity.Entity entity, Location to, boolean headOnly)
return;
}
if (handle instanceof EntityInsentient) {
((EntityInsentient) handle).getControllerLook().a(to.getX(), to.getY(), to.getZ(), to.getYaw(),
to.getPitch());
((EntityInsentient) handle).getControllerLook().a(to.getX(), to.getY(), to.getZ(),
((EntityInsentient) handle).cJ(), ((EntityInsentient) handle).N());
while (((EntityInsentient) handle).aQ >= 180F) {
((EntityInsentient) handle).aQ -= 360F;
}
Expand All @@ -653,9 +653,9 @@ public void look(org.bukkit.entity.Entity from, org.bukkit.entity.Entity to) {
Entity handle = NMSImpl.getHandle(from), target = NMSImpl.getHandle(to);
if (BAD_CONTROLLER_LOOK.contains(handle.getBukkitEntity().getType())) {
if (to instanceof LivingEntity) {
look(from, ((LivingEntity) to).getEyeLocation(), false);
look(from, ((LivingEntity) to).getEyeLocation(), false, true);
} else {
look(from, to.getLocation(), false);
look(from, to.getLocation(), false, true);
}
} else if (handle instanceof EntityInsentient) {
((EntityInsentient) handle).getControllerLook().a(target, ((EntityInsentient) handle).cJ(),
Expand Down Expand Up @@ -1390,9 +1390,9 @@ public static void updateNavigation(NavigationAbstract navigation) {
navigation.l();
}

private static final Set<EntityType> BAD_CONTROLLER_LOOK = EnumSet.of(EntityType.SILVERFISH, EntityType.ENDERMITE,
EntityType.ENDER_DRAGON, EntityType.BAT, EntityType.SLIME, EntityType.MAGMA_CUBE, EntityType.HORSE,
EntityType.GHAST);
private static final Set<EntityType> BAD_CONTROLLER_LOOK = EnumSet.of(EntityType.POLAR_BEAR, EntityType.SILVERFISH,
EntityType.ENDERMITE, EntityType.ENDER_DRAGON, EntityType.BAT, EntityType.SLIME, EntityType.MAGMA_CUBE,
EntityType.HORSE, EntityType.GHAST);

private static final Field CRAFT_BOSSBAR_HANDLE_FIELD = NMS.getField(CraftBossBar.class, "handle");
private static final float DEFAULT_SPEED = 1F;
Expand Down
Expand Up @@ -394,7 +394,7 @@ public void setTargetLook(Entity target, float yawOffset, float renderOffset) {
}

public void setTargetLook(Location target) {
controllerLook.a(target.getX(), target.getY(), target.getZ(), target.getYaw(), target.getPitch());
controllerLook.a(target.getX(), target.getY(), target.getZ(), 10, 40);
}

public void updateAI() {
Expand Down
Expand Up @@ -637,9 +637,9 @@ public void look(org.bukkit.entity.Entity entity, float yaw, float pitch) {
}

@Override
public void look(org.bukkit.entity.Entity entity, Location to, boolean headOnly) {
public void look(org.bukkit.entity.Entity entity, Location to, boolean headOnly, boolean immediate) {
Entity handle = NMSImpl.getHandle(entity);
if (headOnly || BAD_CONTROLLER_LOOK.contains(handle.getBukkitEntity().getType())
if (immediate || headOnly || BAD_CONTROLLER_LOOK.contains(handle.getBukkitEntity().getType())
|| (!(handle instanceof EntityInsentient) && !(handle instanceof EntityHumanNPC))) {
Location fromLocation = entity.getLocation(FROM_LOCATION);
double xDiff, yDiff, zDiff;
Expand Down Expand Up @@ -667,8 +667,8 @@ public void look(org.bukkit.entity.Entity entity, Location to, boolean headOnly)
return;
}
if (handle instanceof EntityInsentient) {
((EntityInsentient) handle).getControllerLook().a(to.getX(), to.getY(), to.getZ(), to.getYaw(),
to.getPitch());
((EntityInsentient) handle).getControllerLook().a(to.getX(), to.getY(), to.getZ(),
((EntityInsentient) handle).cL(), ((EntityInsentient) handle).N());

while (((EntityLiving) handle).aP >= 180F) {
((EntityLiving) handle).aP -= 360F;
Expand All @@ -686,9 +686,9 @@ public void look(org.bukkit.entity.Entity from, org.bukkit.entity.Entity to) {
Entity handle = NMSImpl.getHandle(from), target = NMSImpl.getHandle(to);
if (BAD_CONTROLLER_LOOK.contains(handle.getBukkitEntity().getType())) {
if (to instanceof LivingEntity) {
look(from, ((LivingEntity) to).getEyeLocation(), false);
look(from, ((LivingEntity) to).getEyeLocation(), false, true);
} else {
look(from, to.getLocation(), false);
look(from, to.getLocation(), false, true);
}
} else if (handle instanceof EntityInsentient) {
((EntityInsentient) handle).getControllerLook().a(target, ((EntityInsentient) handle).cL(),
Expand Down Expand Up @@ -1434,9 +1434,9 @@ public static void updateNavigation(NavigationAbstract navigation) {
navigation.l();
}

private static final Set<EntityType> BAD_CONTROLLER_LOOK = EnumSet.of(EntityType.SILVERFISH, EntityType.ENDERMITE,
EntityType.ENDER_DRAGON, EntityType.BAT, EntityType.SLIME, EntityType.MAGMA_CUBE, EntityType.HORSE,
EntityType.GHAST);
private static final Set<EntityType> BAD_CONTROLLER_LOOK = EnumSet.of(EntityType.POLAR_BEAR, EntityType.SILVERFISH,
EntityType.ENDERMITE, EntityType.ENDER_DRAGON, EntityType.BAT, EntityType.SLIME, EntityType.MAGMA_CUBE,
EntityType.HORSE, EntityType.GHAST);
private static final Field CRAFT_BOSSBAR_HANDLE_FIELD = NMS.getField(CraftBossBar.class, "handle");
private static final float DEFAULT_SPEED = 1F;
private static final Field ENDERDRAGON_BATTLE_BAR_FIELD = NMS.getField(EnderDragonBattle.class, "c");
Expand Down

0 comments on commit cf5beab

Please sign in to comment.