From 0f0e14fad527e71ed6f3f5cc4d860ce2daf75371 Mon Sep 17 00:00:00 2001 From: TwoLeggedCat <80929284+TwoLeggedCat@users.noreply.github.com> Date: Sat, 29 May 2021 14:33:18 -0500 Subject: [PATCH] Add more line of sight methods --- .../src/main/java/org/bukkit/RegionAccessor.java | 8 ++++++++ .../main/java/org/bukkit/entity/LivingEntity.java | 13 +++++++++++++ 2 files changed, 21 insertions(+) diff --git a/paper-api/src/main/java/org/bukkit/RegionAccessor.java b/paper-api/src/main/java/org/bukkit/RegionAccessor.java index d8b1fa79dc..b68367f123 100644 --- a/paper-api/src/main/java/org/bukkit/RegionAccessor.java +++ b/paper-api/src/main/java/org/bukkit/RegionAccessor.java @@ -461,5 +461,13 @@ public interface RegionAccessor extends Keyed { // Paper @NotNull @Override NamespacedKey getKey(); + + /** + * Tell whether a line of sight exists between the given locations + * @param from Location to start at + * @param to target Location + * @return whether a line of sight exists between {@code from} and {@code to} + */ + public boolean lineOfSightExists(@NotNull Location from, @NotNull Location to); // Paper end } diff --git a/paper-api/src/main/java/org/bukkit/entity/LivingEntity.java b/paper-api/src/main/java/org/bukkit/entity/LivingEntity.java index a50b0b8370..5db673a057 100644 --- a/paper-api/src/main/java/org/bukkit/entity/LivingEntity.java +++ b/paper-api/src/main/java/org/bukkit/entity/LivingEntity.java @@ -622,6 +622,19 @@ public interface LivingEntity extends Attributable, Damageable, ProjectileSource */ public boolean hasLineOfSight(@NotNull Entity other); + // Paper start + /** + * Checks whether the living entity has block line of sight to the given block. + *

+ * This uses the same algorithm that hostile mobs use to find the closest + * player. + * + * @param location the location to determine line of sight to + * @return true if there is a line of sight, false if not + */ + public boolean hasLineOfSight(@NotNull Location location); + // Paper end + /** * Returns if the living entity despawns when away from players or not. *