Skip to content

Commit

Permalink
Looking at locations permits (relative) locations without worlds. (Sk…
Browse files Browse the repository at this point in the history
…riptLang#6590)

Replace location with relative if no world set.
  • Loading branch information
Moderocky authored Apr 19, 2024
1 parent 7140f82 commit 7f6be1a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/main/java/ch/njol/skript/bukkitutil/PaperEntityUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ private static void mobLookAt(Object target, @Nullable Float headRotationSpeed,
Bukkit.getMobGoals().getRunningGoals(mob, GoalType.LOOK).forEach(goal -> Bukkit.getMobGoals().removeGoal(mob, goal));
float speed = headRotationSpeed != null ? headRotationSpeed : mob.getHeadRotationSpeed();
float maxPitch = maxHeadPitch != null ? maxHeadPitch : mob.getMaxHeadPitch();
if (target instanceof Location && !((Location) target).isWorldLoaded()) {
Location location = (Location) target;
target = new Location(mob.getWorld(), location.getX(), location.getY(), location.getZ());
}
Bukkit.getMobGoals().addGoal(mob, 0, new LookGoal(target, mob, speed, maxPitch));
}

Expand Down Expand Up @@ -102,6 +106,10 @@ public static void lookAt(LookAnchor entityAnchor, Object target, @Nullable Floa
if (target == null || !LOOK_AT || !LOOK_ANCHORS)
return;
for (LivingEntity entity : entities) {
if (target instanceof Location && !((Location) target).isWorldLoaded()) {
Location location = (Location) target;
target = new Location(entity.getWorld(), location.getX(), location.getY(), location.getZ());
}
if (entity instanceof Player) {
Player player = (Player) entity;
if (target instanceof Vector) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/ch/njol/skript/effects/EffLook.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ protected void execute(Event event) {
Float maxPitch = this.maxPitch == null ? null : this.maxPitch.getSingle(event).floatValue();
if (LOOK_ANCHORS) {
PaperEntityUtils.lookAt(anchor, object, speed, maxPitch, entities.getArray(event));
return;
} else {
PaperEntityUtils.lookAt(object, speed, maxPitch, entities.getArray(event));
}
PaperEntityUtils.lookAt(object, speed, maxPitch, entities.getArray(event));
}

@Override
Expand Down

0 comments on commit 7f6be1a

Please sign in to comment.