|
5 | 5 | import org.bukkit.entity.LivingEntity; |
6 | 6 | import org.bukkit.entity.Entity; |
7 | 7 | import org.bukkit.entity.Mob; |
| 8 | +import org.checkerframework.checker.index.qual.NonNegative; |
8 | 9 | import org.jspecify.annotations.NullMarked; |
9 | 10 | import org.jspecify.annotations.Nullable; |
10 | 11 |
|
@@ -43,7 +44,20 @@ public interface Pathfinder { |
43 | 44 | * @param loc Location to navigate to |
44 | 45 | * @return The closest Location the Entity can get to for this navigation, or null if no path could be calculated |
45 | 46 | */ |
46 | | - @Nullable PathResult findPath(Location loc); |
| 47 | + default @Nullable PathResult findPath(Location loc) { |
| 48 | + return this.findPath(loc, 0); |
| 49 | + } |
| 50 | + |
| 51 | + /** |
| 52 | + * Calculates a destination for the Entity to navigate to, but does not set it |
| 53 | + * as the current target. Useful for calculating what would happen before setting it. |
| 54 | + * |
| 55 | + * @param loc Location to navigate to |
| 56 | + * @param reachRange The <a href="https://cp-algorithms.com/geometry/manhattan-distance.html">Manhattan-distance</a> threshold |
| 57 | + * from the target position at which the path is considered reached, where {@code 0} requires the exact target position |
| 58 | + * @return The closest Location the Entity can get to for this navigation, or null if no path could be calculated |
| 59 | + */ |
| 60 | + @Nullable PathResult findPath(final Location loc, final @NonNegative int reachRange); |
47 | 61 |
|
48 | 62 | /** |
49 | 63 | * Calculates a destination for the Entity to navigate to reach the target entity, |
@@ -76,7 +90,26 @@ default PathResult findPath(LivingEntity target) { |
76 | 90 | * @param target the Entity to navigate to |
77 | 91 | * @return The closest Location the Entity can get to for this navigation, or null if no path could be calculated |
78 | 92 | */ |
79 | | - @Nullable PathResult findPath(Entity target); |
| 93 | + default @Nullable PathResult findPath(Entity target) { |
| 94 | + return this.findPath(target, 0); |
| 95 | + } |
| 96 | + |
| 97 | + /** |
| 98 | + * Calculates a destination for the Entity to navigate to to reach the target entity, |
| 99 | + * but does not set it as the current target. |
| 100 | + * Useful for calculating what would happen before setting it. |
| 101 | + * <p> |
| 102 | + * The behavior of this PathResult is subject to the games pathfinding rules, and may |
| 103 | + * result in the pathfinding automatically updating to follow the target Entity. |
| 104 | + * <p> |
| 105 | + * However, this behavior is not guaranteed, and is subject to the games behavior. |
| 106 | + * |
| 107 | + * @param target the Entity to navigate to |
| 108 | + * @param reachRange The <a href="https://cp-algorithms.com/geometry/manhattan-distance.html">Manhattan-distance</a> threshold |
| 109 | + * from the target position at which the path is considered reached, where {@code 0} requires the exact target position |
| 110 | + * @return The closest Location the Entity can get to for this navigation, or null if no path could be calculated |
| 111 | + */ |
| 112 | + @Nullable PathResult findPath(final Entity target, final @NonNegative int reachRange); |
80 | 113 |
|
81 | 114 | /** |
82 | 115 | * Calculates a destination for the Entity to navigate to, and sets it with default speed |
|
0 commit comments