Rename some methods per discussion in channel

This commit is contained in:
Aikar 2018-09-09 21:45:54 -04:00
parent 55afdc44c9
commit b3a9fc3bf9
No known key found for this signature in database
GPG key ID: 401ADFC9891FAAFE
2 changed files with 37 additions and 39 deletions

View file

@ -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> From: Aikar <aikar@aikar.co>
Date: Sun, 9 Sep 2018 12:39:06 -0400 Date: Sun, 9 Sep 2018 12:39:06 -0400
Subject: [PATCH] Mob Pathfinding API 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 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 new file mode 100644
index 000000000..78230bd28 index 000000000..d6953b390
--- /dev/null --- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/entity/Pathfinder.java +++ b/src/main/java/com/destroystokyo/paper/entity/Pathfinder.java
@@ -0,0 +1,168 @@ @@ -0,0 +1,167 @@
+package com.destroystokyo.paper.entity; +package com.destroystokyo.paper.entity;
+ +
+import org.apache.commons.lang.Validate;
+import org.bukkit.Location; +import org.bukkit.Location;
+import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.LivingEntity;
+import org.bukkit.entity.Mob; +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 + * 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 + * @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 + * @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 + * 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 + * @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 + * @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, + * 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 + * @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 + * @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 + * 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 + * @param loc Location to navigate to
+ * @return If the pathfinding was successfully started + * @return If the pathfinding was successfully started
+ */ + */
+ default boolean setDestination(@Nonnull Location loc) { + default boolean moveTo(@Nonnull Location loc) {
+ return setDestination(loc, 1); + return moveTo(loc, 1);
+ } + }
+ +
+ /** + /**
@ -95,9 +94,9 @@ index 000000000..78230bd28
+ * @param speed Speed multiplier to navigate at, where 1 is 'normal' + * @param speed Speed multiplier to navigate at, where 1 is 'normal'
+ * @return If the pathfinding was successfully started + * @return If the pathfinding was successfully started
+ */ + */
+ default boolean setDestination(@Nonnull Location loc, double speed) { + default boolean moveTo(@Nonnull Location loc, double speed) {
+ PathResult path = calculateDestination(loc); + PathResult path = findPath(loc);
+ return path != null && setDestination(path, speed); + return path != null && moveTo(path, speed);
+ } + }
+ +
+ /** + /**
@ -112,8 +111,8 @@ index 000000000..78230bd28
+ * @param target the Entity to navigate to + * @param target the Entity to navigate to
+ * @return If the pathfinding was successfully started + * @return If the pathfinding was successfully started
+ */ + */
+ default boolean setDestination(@Nonnull LivingEntity target) { + default boolean moveTo(@Nonnull LivingEntity target) {
+ return setDestination(target, 1); + return moveTo(target, 1);
+ } + }
+ +
+ /** + /**
@ -129,9 +128,9 @@ index 000000000..78230bd28
+ * @param speed Speed multiplier to navigate at, where 1 is 'normal' + * @param speed Speed multiplier to navigate at, where 1 is 'normal'
+ * @return If the pathfinding was successfully started + * @return If the pathfinding was successfully started
+ */ + */
+ default boolean setDestination(@Nonnull LivingEntity target, double speed) { + default boolean moveTo(@Nonnull LivingEntity target, double speed) {
+ PathResult path = calculateDestination(target); + PathResult path = findPath(target);
+ return path != null && setDestination(path, speed); + return path != null && moveTo(path, speed);
+ } + }
+ +
+ /** + /**
@ -141,8 +140,8 @@ index 000000000..78230bd28
+ * @param path The Path to start following + * @param path The Path to start following
+ * @return If the pathfinding was successfully started + * @return If the pathfinding was successfully started
+ */ + */
+ default boolean setDestination(@Nonnull PathResult path) { + default boolean moveTo(@Nonnull PathResult path) {
+ return setDestination(path, 1); + return moveTo(path, 1);
+ } + }
+ +
+ /** + /**
@ -153,7 +152,7 @@ index 000000000..78230bd28
+ * @param speed Speed multiplier to navigate at, where 1 is 'normal' + * @param speed Speed multiplier to navigate at, where 1 is 'normal'
+ * @return If the pathfinding was successfully started + * @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 + * Represents the result of a pathfinding calculation
@ -161,11 +160,6 @@ index 000000000..78230bd28
+ interface PathResult { + 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 + * 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()} + * 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 + * @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 diff --git a/src/main/java/org/bukkit/entity/Mob.java b/src/main/java/org/bukkit/entity/Mob.java

View file

@ -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> From: Aikar <aikar@aikar.co>
Date: Sun, 9 Sep 2018 13:30:00 -0400 Date: Sun, 9 Sep 2018 13:30:00 -0400
Subject: [PATCH] Mob Pathfinding API 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 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 new file mode 100644
index 0000000000..d166bcdd28 index 0000000000..ed3d86ddd3
--- /dev/null --- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/entity/PaperPathfinder.java +++ b/src/main/java/com/destroystokyo/paper/entity/PaperPathfinder.java
@@ -0,0 +1,114 @@ @@ -0,0 +1,113 @@
+package com.destroystokyo.paper.entity; +package com.destroystokyo.paper.entity;
+ +
+import net.minecraft.server.EntityInsentient; +import net.minecraft.server.EntityInsentient;
@ -46,20 +46,20 @@ index 0000000000..d166bcdd28
+ } + }
+ +
+ @Override + @Override
+ public boolean hasDestination() { + public boolean hasPath() {
+ return entity.getNavigation().getPathEntity() != null; + return entity.getNavigation().getPathEntity() != null;
+ } + }
+ +
+ @Nullable + @Nullable
+ @Override + @Override
+ public PathResult getCurrentDestination() { + public PathResult getCurrentPath() {
+ PathEntity path = entity.getNavigation().getPathEntity(); + PathEntity path = entity.getNavigation().getPathEntity();
+ return path != null ? new PaperPathResult(path) : null; + return path != null ? new PaperPathResult(path) : null;
+ } + }
+ +
+ @Nullable + @Nullable
+ @Override + @Override
+ public PathResult calculateDestination(Location loc) { + public PathResult findPath(Location loc) {
+ Validate.notNull(loc, "Location can not be null"); + Validate.notNull(loc, "Location can not be null");
+ PathEntity path = entity.getNavigation().calculateDestination(loc.getX(), loc.getY(), loc.getZ()); + PathEntity path = entity.getNavigation().calculateDestination(loc.getX(), loc.getY(), loc.getZ());
+ return path != null ? new PaperPathResult(path) : null; + return path != null ? new PaperPathResult(path) : null;
@ -67,18 +67,17 @@ index 0000000000..d166bcdd28
+ +
+ @Nullable + @Nullable
+ @Override + @Override
+ public PathResult calculateDestination(LivingEntity target) { + public PathResult findPath(LivingEntity target) {
+ Validate.notNull(target, "Target can not be null"); + Validate.notNull(target, "Target can not be null");
+ PathEntity path = entity.getNavigation().calculateDestination(((CraftLivingEntity) target).getHandle()); + PathEntity path = entity.getNavigation().calculateDestination(((CraftLivingEntity) target).getHandle());
+ return path != null ? new PaperPathResult(path) : null; + return path != null ? new PaperPathResult(path) : null;
+ } + }
+ +
+ @Override + @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"); + Validate.notNull(path, "PathResult can not be null");
+ PathEntity pathEntity = ((PaperPathResult) path).path; + PathEntity pathEntity = ((PaperPathResult) path).path;
+ entity.getNavigation().setDestination(pathEntity, speed); + return entity.getNavigation().setDestination(pathEntity, speed);
+ return false;
+ } + }
+ +
+ public class PaperPathResult implements com.destroystokyo.paper.entity.PaperPathfinder.PathResult { + public class PaperPathResult implements com.destroystokyo.paper.entity.PaperPathfinder.PathResult {
@ -90,7 +89,7 @@ index 0000000000..d166bcdd28
+ +
+ @Nullable + @Nullable
+ @Override + @Override
+ public Location getLocation() { + public Location getFinalPoint() {
+ PathPoint point = path.getFinalPoint(); + PathPoint point = path.getFinalPoint();
+ return point != null ? toLoc(point) : null; + return point != null ? toLoc(point) : null;
+ } + }
@ -113,7 +112,7 @@ index 0000000000..d166bcdd28
+ +
+ @Nullable + @Nullable
+ @Override + @Override
+ public Location getNextPointLocation() { + public Location getNextPoint() {
+ if (!path.hasNext()) { + if (!path.hasNext()) {
+ return null; + return null;
+ } + }