Rename some methods per discussion in channel
This commit is contained in:
parent
55afdc44c9
commit
b3a9fc3bf9
2 changed files with 37 additions and 39 deletions
|
@ -1,4 +1,4 @@
|
|||
From 68606cfdc559ec3b89b3704a24247fd6774e0cb3 Mon Sep 17 00:00:00 2001
|
||||
From 9ba0ba25fa41114b804a030a64748707f3747b76 Mon Sep 17 00:00:00 2001
|
||||
From: Aikar <aikar@aikar.co>
|
||||
Date: Sun, 9 Sep 2018 12:39:06 -0400
|
||||
Subject: [PATCH] Mob Pathfinding API
|
||||
|
@ -13,13 +13,12 @@ You can use EntityPathfindEvent to cancel new pathfinds from overriding your cur
|
|||
|
||||
diff --git a/src/main/java/com/destroystokyo/paper/entity/Pathfinder.java b/src/main/java/com/destroystokyo/paper/entity/Pathfinder.java
|
||||
new file mode 100644
|
||||
index 000000000..78230bd28
|
||||
index 000000000..d6953b390
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/com/destroystokyo/paper/entity/Pathfinder.java
|
||||
@@ -0,0 +1,168 @@
|
||||
@@ -0,0 +1,167 @@
|
||||
+package com.destroystokyo.paper.entity;
|
||||
+
|
||||
+import org.apache.commons.lang.Validate;
|
||||
+import org.bukkit.Location;
|
||||
+import org.bukkit.entity.LivingEntity;
|
||||
+import org.bukkit.entity.Mob;
|
||||
|
@ -48,12 +47,12 @@ index 000000000..78230bd28
|
|||
+ * If the entity is currently trying to navigate to a destination, this will return true
|
||||
+ * @return true if the entity is navigating to a destination
|
||||
+ */
|
||||
+ boolean hasDestination();
|
||||
+ boolean hasPath();
|
||||
+
|
||||
+ /**
|
||||
+ * @return The location the entity is trying to navigate to, or null if there is no destination
|
||||
+ */
|
||||
+ @Nullable PathResult getCurrentDestination();
|
||||
+ @Nullable PathResult getCurrentPath();
|
||||
+
|
||||
+ /**
|
||||
+ * Calculates a destination for the Entity to navigate to, but does not set it
|
||||
|
@ -61,7 +60,7 @@ index 000000000..78230bd28
|
|||
+ * @param loc Location to navigate to
|
||||
+ * @return The closest Location the Entity can get to for this navigation, or null if no path could be calculated
|
||||
+ */
|
||||
+ @Nullable PathResult calculateDestination(Location loc);
|
||||
+ @Nullable PathResult findPath(Location loc);
|
||||
+
|
||||
+ /**
|
||||
+ * Calculates a destination for the Entity to navigate to to reach the target entity,
|
||||
|
@ -76,7 +75,7 @@ index 000000000..78230bd28
|
|||
+ * @param target the Entity to navigate to
|
||||
+ * @return The closest Location the Entity can get to for this navigation, or null if no path could be calculated
|
||||
+ */
|
||||
+ @Nullable PathResult calculateDestination(LivingEntity target);
|
||||
+ @Nullable PathResult findPath(LivingEntity target);
|
||||
+
|
||||
+ /**
|
||||
+ * Calculates a destination for the Entity to navigate to, and sets it with default speed
|
||||
|
@ -84,8 +83,8 @@ index 000000000..78230bd28
|
|||
+ * @param loc Location to navigate to
|
||||
+ * @return If the pathfinding was successfully started
|
||||
+ */
|
||||
+ default boolean setDestination(@Nonnull Location loc) {
|
||||
+ return setDestination(loc, 1);
|
||||
+ default boolean moveTo(@Nonnull Location loc) {
|
||||
+ return moveTo(loc, 1);
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
|
@ -95,9 +94,9 @@ index 000000000..78230bd28
|
|||
+ * @param speed Speed multiplier to navigate at, where 1 is 'normal'
|
||||
+ * @return If the pathfinding was successfully started
|
||||
+ */
|
||||
+ default boolean setDestination(@Nonnull Location loc, double speed) {
|
||||
+ PathResult path = calculateDestination(loc);
|
||||
+ return path != null && setDestination(path, speed);
|
||||
+ default boolean moveTo(@Nonnull Location loc, double speed) {
|
||||
+ PathResult path = findPath(loc);
|
||||
+ return path != null && moveTo(path, speed);
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
|
@ -112,8 +111,8 @@ index 000000000..78230bd28
|
|||
+ * @param target the Entity to navigate to
|
||||
+ * @return If the pathfinding was successfully started
|
||||
+ */
|
||||
+ default boolean setDestination(@Nonnull LivingEntity target) {
|
||||
+ return setDestination(target, 1);
|
||||
+ default boolean moveTo(@Nonnull LivingEntity target) {
|
||||
+ return moveTo(target, 1);
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
|
@ -129,9 +128,9 @@ index 000000000..78230bd28
|
|||
+ * @param speed Speed multiplier to navigate at, where 1 is 'normal'
|
||||
+ * @return If the pathfinding was successfully started
|
||||
+ */
|
||||
+ default boolean setDestination(@Nonnull LivingEntity target, double speed) {
|
||||
+ PathResult path = calculateDestination(target);
|
||||
+ return path != null && setDestination(path, speed);
|
||||
+ default boolean moveTo(@Nonnull LivingEntity target, double speed) {
|
||||
+ PathResult path = findPath(target);
|
||||
+ return path != null && moveTo(path, speed);
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
|
@ -141,8 +140,8 @@ index 000000000..78230bd28
|
|||
+ * @param path The Path to start following
|
||||
+ * @return If the pathfinding was successfully started
|
||||
+ */
|
||||
+ default boolean setDestination(@Nonnull PathResult path) {
|
||||
+ return setDestination(path, 1);
|
||||
+ default boolean moveTo(@Nonnull PathResult path) {
|
||||
+ return moveTo(path, 1);
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
|
@ -153,7 +152,7 @@ index 000000000..78230bd28
|
|||
+ * @param speed Speed multiplier to navigate at, where 1 is 'normal'
|
||||
+ * @return If the pathfinding was successfully started
|
||||
+ */
|
||||
+ boolean setDestination(@Nonnull PathResult path, double speed);
|
||||
+ boolean moveTo(@Nonnull PathResult path, double speed);
|
||||
+
|
||||
+ /**
|
||||
+ * Represents the result of a pathfinding calculation
|
||||
|
@ -161,11 +160,6 @@ index 000000000..78230bd28
|
|||
+ interface PathResult {
|
||||
+
|
||||
+ /**
|
||||
+ * @return The closest point the path can get to the target location
|
||||
+ */
|
||||
+ @Nullable Location getLocation();
|
||||
+
|
||||
+ /**
|
||||
+ * All currently calculated points to follow along the path to reach the destination location
|
||||
+ *
|
||||
+ * Will return points the entity has already moved past, see {@link #getNextPointIndex()}
|
||||
|
@ -182,7 +176,12 @@ index 000000000..78230bd28
|
|||
+ /**
|
||||
+ * @return The next location in the path points the entity is trying to reach, or null if there is no next point
|
||||
+ */
|
||||
+ @Nullable Location getNextPointLocation();
|
||||
+ @Nullable Location getNextPoint();
|
||||
+
|
||||
+ /**
|
||||
+ * @return The closest point the path can get to the target location
|
||||
+ */
|
||||
+ @Nullable Location getFinalPoint();
|
||||
+ }
|
||||
+}
|
||||
diff --git a/src/main/java/org/bukkit/entity/Mob.java b/src/main/java/org/bukkit/entity/Mob.java
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
From 02345434a6ac0af81af23b6dc346d6e1efb0c2ee Mon Sep 17 00:00:00 2001
|
||||
From 3b72b5675437928e2fa39a540b2ea0644f173302 Mon Sep 17 00:00:00 2001
|
||||
From: Aikar <aikar@aikar.co>
|
||||
Date: Sun, 9 Sep 2018 13:30:00 -0400
|
||||
Subject: [PATCH] Mob Pathfinding API
|
||||
|
@ -7,10 +7,10 @@ Implements Pathfinding API for mobs
|
|||
|
||||
diff --git a/src/main/java/com/destroystokyo/paper/entity/PaperPathfinder.java b/src/main/java/com/destroystokyo/paper/entity/PaperPathfinder.java
|
||||
new file mode 100644
|
||||
index 0000000000..d166bcdd28
|
||||
index 0000000000..ed3d86ddd3
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/com/destroystokyo/paper/entity/PaperPathfinder.java
|
||||
@@ -0,0 +1,114 @@
|
||||
@@ -0,0 +1,113 @@
|
||||
+package com.destroystokyo.paper.entity;
|
||||
+
|
||||
+import net.minecraft.server.EntityInsentient;
|
||||
|
@ -46,20 +46,20 @@ index 0000000000..d166bcdd28
|
|||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public boolean hasDestination() {
|
||||
+ public boolean hasPath() {
|
||||
+ return entity.getNavigation().getPathEntity() != null;
|
||||
+ }
|
||||
+
|
||||
+ @Nullable
|
||||
+ @Override
|
||||
+ public PathResult getCurrentDestination() {
|
||||
+ public PathResult getCurrentPath() {
|
||||
+ PathEntity path = entity.getNavigation().getPathEntity();
|
||||
+ return path != null ? new PaperPathResult(path) : null;
|
||||
+ }
|
||||
+
|
||||
+ @Nullable
|
||||
+ @Override
|
||||
+ public PathResult calculateDestination(Location loc) {
|
||||
+ public PathResult findPath(Location loc) {
|
||||
+ Validate.notNull(loc, "Location can not be null");
|
||||
+ PathEntity path = entity.getNavigation().calculateDestination(loc.getX(), loc.getY(), loc.getZ());
|
||||
+ return path != null ? new PaperPathResult(path) : null;
|
||||
|
@ -67,18 +67,17 @@ index 0000000000..d166bcdd28
|
|||
+
|
||||
+ @Nullable
|
||||
+ @Override
|
||||
+ public PathResult calculateDestination(LivingEntity target) {
|
||||
+ public PathResult findPath(LivingEntity target) {
|
||||
+ Validate.notNull(target, "Target can not be null");
|
||||
+ PathEntity path = entity.getNavigation().calculateDestination(((CraftLivingEntity) target).getHandle());
|
||||
+ return path != null ? new PaperPathResult(path) : null;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public boolean setDestination(@Nonnull PathResult path, double speed) {
|
||||
+ public boolean moveTo(@Nonnull PathResult path, double speed) {
|
||||
+ Validate.notNull(path, "PathResult can not be null");
|
||||
+ PathEntity pathEntity = ((PaperPathResult) path).path;
|
||||
+ entity.getNavigation().setDestination(pathEntity, speed);
|
||||
+ return false;
|
||||
+ return entity.getNavigation().setDestination(pathEntity, speed);
|
||||
+ }
|
||||
+
|
||||
+ public class PaperPathResult implements com.destroystokyo.paper.entity.PaperPathfinder.PathResult {
|
||||
|
@ -90,7 +89,7 @@ index 0000000000..d166bcdd28
|
|||
+
|
||||
+ @Nullable
|
||||
+ @Override
|
||||
+ public Location getLocation() {
|
||||
+ public Location getFinalPoint() {
|
||||
+ PathPoint point = path.getFinalPoint();
|
||||
+ return point != null ? toLoc(point) : null;
|
||||
+ }
|
||||
|
@ -113,7 +112,7 @@ index 0000000000..d166bcdd28
|
|||
+
|
||||
+ @Nullable
|
||||
+ @Override
|
||||
+ public Location getNextPointLocation() {
|
||||
+ public Location getNextPoint() {
|
||||
+ if (!path.hasNext()) {
|
||||
+ return null;
|
||||
+ }
|
||||
|
|
Loading…
Reference in a new issue