2019-05-14 23:54:32 +02:00
|
|
|
From ea30d1b969577bd6f08afb4541f442ec4732e353 Mon Sep 17 00:00:00 2001
|
2018-09-09 18:58:47 +02:00
|
|
|
From: Aikar <aikar@aikar.co>
|
|
|
|
Date: Sun, 9 Sep 2018 13:30:00 -0400
|
|
|
|
Subject: [PATCH] Mob Pathfinding API
|
|
|
|
|
|
|
|
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
|
2019-05-14 23:54:32 +02:00
|
|
|
index 0000000000..f68a07cb96
|
2018-09-09 18:58:47 +02:00
|
|
|
--- /dev/null
|
|
|
|
+++ b/src/main/java/com/destroystokyo/paper/entity/PaperPathfinder.java
|
2019-05-06 09:20:16 +02:00
|
|
|
@@ -0,0 +1,111 @@
|
2018-09-09 18:58:47 +02:00
|
|
|
+package com.destroystokyo.paper.entity;
|
|
|
|
+
|
|
|
|
+import net.minecraft.server.EntityInsentient;
|
|
|
|
+import net.minecraft.server.PathEntity;
|
|
|
|
+import net.minecraft.server.PathPoint;
|
|
|
|
+import org.apache.commons.lang.Validate;
|
|
|
|
+import org.bukkit.Location;
|
|
|
|
+import org.bukkit.craftbukkit.entity.CraftLivingEntity;
|
|
|
|
+import org.bukkit.entity.LivingEntity;
|
|
|
|
+import org.bukkit.entity.Mob;
|
|
|
|
+
|
|
|
|
+import javax.annotation.Nonnull;
|
|
|
|
+import javax.annotation.Nullable;
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.List;
|
|
|
|
+
|
|
|
|
+public class PaperPathfinder implements com.destroystokyo.paper.entity.Pathfinder {
|
|
|
|
+
|
|
|
|
+ private final EntityInsentient entity;
|
|
|
|
+
|
|
|
|
+ public PaperPathfinder(EntityInsentient entity) {
|
|
|
|
+ this.entity = entity;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Mob getEntity() {
|
|
|
|
+ return entity.getBukkitMob();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void stopPathfinding() {
|
|
|
|
+ entity.getNavigation().stopPathfinding();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
2018-09-10 03:45:54 +02:00
|
|
|
+ public boolean hasPath() {
|
2018-09-09 18:58:47 +02:00
|
|
|
+ return entity.getNavigation().getPathEntity() != null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Nullable
|
|
|
|
+ @Override
|
2018-09-10 03:45:54 +02:00
|
|
|
+ public PathResult getCurrentPath() {
|
2018-09-09 18:58:47 +02:00
|
|
|
+ PathEntity path = entity.getNavigation().getPathEntity();
|
|
|
|
+ return path != null ? new PaperPathResult(path) : null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Nullable
|
|
|
|
+ @Override
|
2018-09-10 03:45:54 +02:00
|
|
|
+ public PathResult findPath(Location loc) {
|
2018-09-09 18:58:47 +02:00
|
|
|
+ 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;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Nullable
|
|
|
|
+ @Override
|
2018-09-10 03:45:54 +02:00
|
|
|
+ public PathResult findPath(LivingEntity target) {
|
2018-09-09 18:58:47 +02:00
|
|
|
+ Validate.notNull(target, "Target can not be null");
|
|
|
|
+ PathEntity path = entity.getNavigation().calculateDestination(((CraftLivingEntity) target).getHandle());
|
|
|
|
+ return path != null ? new PaperPathResult(path) : null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
2018-09-10 03:45:54 +02:00
|
|
|
+ public boolean moveTo(@Nonnull PathResult path, double speed) {
|
2018-09-09 18:58:47 +02:00
|
|
|
+ Validate.notNull(path, "PathResult can not be null");
|
|
|
|
+ PathEntity pathEntity = ((PaperPathResult) path).path;
|
2018-09-10 03:45:54 +02:00
|
|
|
+ return entity.getNavigation().setDestination(pathEntity, speed);
|
2018-09-09 18:58:47 +02:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public class PaperPathResult implements com.destroystokyo.paper.entity.PaperPathfinder.PathResult {
|
|
|
|
+
|
|
|
|
+ private final PathEntity path;
|
|
|
|
+ PaperPathResult(PathEntity path) {
|
|
|
|
+ this.path = path;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Nullable
|
|
|
|
+ @Override
|
2018-09-10 03:45:54 +02:00
|
|
|
+ public Location getFinalPoint() {
|
2018-09-09 18:58:47 +02:00
|
|
|
+ PathPoint point = path.getFinalPoint();
|
|
|
|
+ return point != null ? toLoc(point) : null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public List<Location> getPoints() {
|
|
|
|
+ List<Location> points = new ArrayList<>();
|
2019-05-06 09:20:16 +02:00
|
|
|
+ for (PathPoint point : path.getPoints()) {
|
|
|
|
+ points.add(toLoc(point));
|
2018-09-09 18:58:47 +02:00
|
|
|
+ }
|
|
|
|
+ return points;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
2018-09-09 20:36:51 +02:00
|
|
|
+ public int getNextPointIndex() {
|
2018-09-09 18:58:47 +02:00
|
|
|
+ return path.getNextIndex();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Nullable
|
|
|
|
+ @Override
|
2018-09-10 03:45:54 +02:00
|
|
|
+ public Location getNextPoint() {
|
2018-09-09 18:58:47 +02:00
|
|
|
+ if (!path.hasNext()) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
2019-05-06 09:20:16 +02:00
|
|
|
+ return toLoc(path.getPoints().get(path.getNextIndex()));
|
2018-09-09 18:58:47 +02:00
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private Location toLoc(PathPoint point) {
|
|
|
|
+ return new Location(entity.world.getWorld(), point.getX(), point.getY(), point.getZ());
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/NavigationAbstract.java b/src/main/java/net/minecraft/server/NavigationAbstract.java
|
2019-05-14 23:54:32 +02:00
|
|
|
index 6cc1423837..1bf7ead714 100644
|
2018-09-09 18:58:47 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/NavigationAbstract.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/NavigationAbstract.java
|
2019-01-01 04:15:55 +01:00
|
|
|
@@ -69,7 +69,7 @@ public abstract class NavigationAbstract {
|
2018-09-09 18:58:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Nullable
|
|
|
|
- public final PathEntity a(double d0, double d1, double d2) {
|
|
|
|
+ public final PathEntity calculateDestination(double d0, double d1, double d2) { return a(d0, d1, d2); } @Nullable public final PathEntity a(double d0, double d1, double d2) { // Paper - OBFHELPER
|
|
|
|
return this.b(new BlockPosition(d0, d1, d2));
|
|
|
|
}
|
|
|
|
|
2019-05-13 03:39:06 +02:00
|
|
|
@@ -85,7 +85,7 @@ public abstract class NavigationAbstract {
|
2018-09-09 18:58:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Nullable
|
|
|
|
- public PathEntity a(Entity entity) {
|
|
|
|
+ public PathEntity calculateDestination(Entity entity) { return a(entity); } @Nullable public PathEntity a(Entity entity) { // Paper - OBFHELPER
|
2019-05-05 10:33:44 +02:00
|
|
|
BlockPosition blockposition = new BlockPosition(entity);
|
|
|
|
double d0 = entity.locX;
|
|
|
|
double d1 = entity.getBoundingBox().minY;
|
2019-05-14 04:20:58 +02:00
|
|
|
@@ -151,6 +151,7 @@ public abstract class NavigationAbstract {
|
2018-09-09 18:58:47 +02:00
|
|
|
private int pathfindFailures = 0;
|
|
|
|
// Paper end
|
|
|
|
|
|
|
|
+ public boolean setDestination(@Nullable PathEntity pathentity, double speed) { return a(pathentity, speed); } // Paper - OBFHELPER
|
|
|
|
public boolean a(@Nullable PathEntity pathentity, double d0) {
|
|
|
|
if (pathentity == null) {
|
|
|
|
this.c = null;
|
2019-05-14 04:20:58 +02:00
|
|
|
@@ -174,7 +175,7 @@ public abstract class NavigationAbstract {
|
2018-09-09 18:58:47 +02:00
|
|
|
}
|
|
|
|
}
|
2019-05-05 10:33:44 +02:00
|
|
|
|
2018-09-09 18:58:47 +02:00
|
|
|
- @Nullable
|
2019-05-05 10:33:44 +02:00
|
|
|
+ @Nullable public PathEntity getPathEntity() { return l(); } @Nullable // Paper - OBFHELPER
|
|
|
|
public PathEntity l() {
|
2018-09-09 18:58:47 +02:00
|
|
|
return this.c;
|
|
|
|
}
|
2019-05-14 04:20:58 +02:00
|
|
|
@@ -261,6 +262,7 @@ public abstract class NavigationAbstract {
|
2018-09-09 18:58:47 +02:00
|
|
|
return this.c == null || this.c.b();
|
|
|
|
}
|
|
|
|
|
2019-05-05 10:33:44 +02:00
|
|
|
+ public void stopPathfinding() { o(); } // Paper - OBFHELPER
|
|
|
|
public void o() {
|
2018-09-09 18:58:47 +02:00
|
|
|
this.pathfindFailures = 0; this.lastFailure = 0; // Paper - Pathfinding optimizations
|
|
|
|
this.c = null;
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/PathEntity.java b/src/main/java/net/minecraft/server/PathEntity.java
|
2019-05-14 23:54:32 +02:00
|
|
|
index f1d94420c8..5fdb601801 100644
|
2018-09-09 18:58:47 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/PathEntity.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/PathEntity.java
|
2019-05-06 09:20:16 +02:00
|
|
|
@@ -5,11 +5,12 @@ import javax.annotation.Nullable;
|
2018-09-09 18:58:47 +02:00
|
|
|
|
|
|
|
public class PathEntity {
|
2019-01-01 04:15:55 +01:00
|
|
|
|
2019-05-05 10:33:44 +02:00
|
|
|
- private final List<PathPoint> a;
|
|
|
|
+ private final List<PathPoint> a; public List<PathPoint> getPoints() { return a; } // Paper - OBFHELPER
|
2018-09-09 18:58:47 +02:00
|
|
|
private PathPoint[] b = new PathPoint[0];
|
|
|
|
private PathPoint[] c = new PathPoint[0];
|
|
|
|
private PathPoint d;
|
|
|
|
- private int e;
|
|
|
|
+ private int e; public int getNextIndex() { return e; } // Paper - OBFHELPER
|
2019-05-06 09:20:16 +02:00
|
|
|
+ public boolean hasNext() { return getNextIndex() < getPoints().size(); } // Paper
|
2018-09-09 18:58:47 +02:00
|
|
|
|
2019-05-05 10:33:44 +02:00
|
|
|
public PathEntity(List<PathPoint> list) {
|
|
|
|
this.a = list;
|
2019-05-06 09:20:16 +02:00
|
|
|
@@ -23,8 +24,7 @@ public class PathEntity {
|
2019-05-05 10:33:44 +02:00
|
|
|
return this.e >= this.a.size();
|
2018-09-09 18:58:47 +02:00
|
|
|
}
|
|
|
|
|
2019-05-05 10:33:44 +02:00
|
|
|
- @Nullable
|
2018-09-09 18:58:47 +02:00
|
|
|
- public PathPoint c() {
|
|
|
|
+ public PathPoint getFinalPoint() { return c(); } @Nullable public PathPoint c() { // Paper - OBFHELPER
|
2019-05-05 10:33:44 +02:00
|
|
|
return !this.a.isEmpty() ? (PathPoint) this.a.get(this.a.size() - 1) : null;
|
2018-09-09 18:58:47 +02:00
|
|
|
}
|
|
|
|
|
2019-05-06 09:20:16 +02:00
|
|
|
@@ -72,7 +72,7 @@ public class PathEntity {
|
2018-09-09 18:58:47 +02:00
|
|
|
return this.a(entity, this.e);
|
|
|
|
}
|
|
|
|
|
2019-05-05 10:33:44 +02:00
|
|
|
- public Vec3D g() {
|
|
|
|
+ public Vec3D getNext() { return g(); } public Vec3D g() { // Paper - OBFHELPER
|
|
|
|
PathPoint pathpoint = (PathPoint) this.a.get(this.e);
|
2019-01-01 04:15:55 +01:00
|
|
|
|
|
|
|
return new Vec3D((double) pathpoint.a, (double) pathpoint.b, (double) pathpoint.c);
|
2018-09-09 18:58:47 +02:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/PathPoint.java b/src/main/java/net/minecraft/server/PathPoint.java
|
2019-05-14 23:54:32 +02:00
|
|
|
index 955152ef4e..4e2cef8f67 100644
|
2018-09-09 18:58:47 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/PathPoint.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/PathPoint.java
|
2019-01-01 04:15:55 +01:00
|
|
|
@@ -2,9 +2,9 @@ package net.minecraft.server;
|
2018-09-09 18:58:47 +02:00
|
|
|
|
|
|
|
public class PathPoint {
|
2019-01-01 04:15:55 +01:00
|
|
|
|
2018-09-09 18:58:47 +02:00
|
|
|
- public final int a;
|
|
|
|
- public final int b;
|
|
|
|
- public final int c;
|
|
|
|
+ public final int a; public final int getX() { return a; } // Paper - OBFHELPER
|
|
|
|
+ public final int b; public final int getY() { return b; } // Paper - OBFHELPER
|
|
|
|
+ public final int c; public final int getZ() { return c; } // Paper - OBFHELPER
|
2019-05-14 04:20:58 +02:00
|
|
|
private final int m;
|
2018-09-09 18:58:47 +02:00
|
|
|
public int d = -1;
|
|
|
|
public float e;
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftMob.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftMob.java
|
2019-05-14 23:54:32 +02:00
|
|
|
index 5bf1cd06fa..53c2d154ed 100644
|
2018-09-09 18:58:47 +02:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftMob.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftMob.java
|
|
|
|
@@ -12,8 +12,11 @@ import org.bukkit.loot.LootTable;
|
|
|
|
public abstract class CraftMob extends CraftLivingEntity implements Mob {
|
|
|
|
public CraftMob(CraftServer server, EntityInsentient entity) {
|
|
|
|
super(server, entity);
|
|
|
|
+ paperPathfinder = new com.destroystokyo.paper.entity.PaperPathfinder(entity); // Paper
|
|
|
|
}
|
|
|
|
|
|
|
|
+ private final com.destroystokyo.paper.entity.PaperPathfinder paperPathfinder; // Paper
|
|
|
|
+ @Override public com.destroystokyo.paper.entity.Pathfinder getPathfinder() { return paperPathfinder; } // Paper
|
|
|
|
@Override
|
|
|
|
public void setTarget(LivingEntity target) {
|
|
|
|
EntityInsentient entity = getHandle();
|
|
|
|
--
|
2019-05-05 13:32:20 +02:00
|
|
|
2.21.0
|
2018-09-09 18:58:47 +02:00
|
|
|
|