Skip to content

Commit

Permalink
protect against an NPC facing straight up or straight down
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Feb 28, 2022
1 parent 5558c7e commit 4d8ecda
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/main/java/org/mcmonkey/sentinel/SentinelTrait.java
Expand Up @@ -1198,6 +1198,11 @@ public Vector fixForAcc(Vector input) {
*/
public void faceLocation(Location l) {
Location faceTowards = l.clone().subtract(0, getLivingEntity().getEyeHeight(), 0);
// Error protection: do not try to face straight up or straight down
Vector validator = l.toVector().subtract(getLivingEntity().getLocation().toVector());
if (validator.lengthSquared() < 0.1 || Math.abs(validator.getX()) + Math.abs(validator.getZ()) < 0.01) {
return;
}
npc.faceLocation(faceTowards);
if (npc.getNavigator().isNavigating()) {
Function<Navigator, Location> altLookFunction = n -> faceTowards;
Expand Down

0 comments on commit 4d8ecda

Please sign in to comment.