2020-05-06 11:48:49 +02:00
|
|
|
From 0000000000000000000000000000000000000000 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
|
2020-05-16 15:15:11 +02:00
|
|
|
index 0000000000000000000000000000000000000000..af1bac9680028130e99c5e7130f258c196b33275
|
2018-09-09 18:58:47 +02:00
|
|
|
--- /dev/null
|
|
|
|
+++ b/src/main/java/com/destroystokyo/paper/entity/PaperPathfinder.java
|
2020-05-16 15:15:11 +02:00
|
|
|
@@ -0,0 +1,141 @@
|
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
|
|
|
+ }
|
|
|
|
+
|
2020-05-16 15:15:11 +02:00
|
|
|
+ @Override
|
|
|
|
+ public boolean canOpenDoors() {
|
|
|
|
+ return entity.getNavigation().getPathfinder().getPathfinder().shouldOpenDoors();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void setCanOpenDoors(boolean canOpenDoors) {
|
|
|
|
+ entity.getNavigation().getPathfinder().getPathfinder().setShouldOpenDoors(canOpenDoors);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public boolean canPassDoors() {
|
|
|
|
+ return entity.getNavigation().getPathfinder().getPathfinder().shouldPassDoors();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void setCanPassDoors(boolean canPassDoors) {
|
|
|
|
+ entity.getNavigation().getPathfinder().getPathfinder().setShouldPassDoors(canPassDoors);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public boolean canFloat() {
|
|
|
|
+ return entity.getNavigation().getPathfinder().getPathfinder().shouldFloat();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void setCanFloat(boolean canFloat) {
|
|
|
|
+ entity.getNavigation().getPathfinder().getPathfinder().setShouldFloat(canFloat);
|
|
|
|
+ }
|
|
|
|
+
|
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());
|
|
|
|
+ }
|
|
|
|
+}
|
2021-03-16 08:19:45 +01:00
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/ai/navigation/NavigationAbstract.java b/src/main/java/net/minecraft/world/entity/ai/navigation/NavigationAbstract.java
|
|
|
|
index 1664d47a61f1c502ece7f32aecdce759172c9f85..ab469f1698b4f0e36c0d077472f1adea36f95ce9 100644
|
|
|
|
--- a/src/main/java/net/minecraft/world/entity/ai/navigation/NavigationAbstract.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/entity/ai/navigation/NavigationAbstract.java
|
|
|
|
@@ -99,7 +99,7 @@ public abstract class NavigationAbstract {
|
2018-09-09 18:58:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Nullable
|
2019-07-20 06:01:24 +02:00
|
|
|
- public final PathEntity a(double d0, double d1, double d2, int i) {
|
|
|
|
+ public final PathEntity calculateDestination(double d0, double d1, double d2) { return a(d0, d1, d2, 0); } public final PathEntity a(double d0, double d1, double d2, int i) { // Paper - OBFHELPER
|
|
|
|
return this.a(new BlockPosition(d0, d1, d2), i);
|
2018-09-09 18:58:47 +02:00
|
|
|
}
|
|
|
|
|
2021-03-16 08:19:45 +01:00
|
|
|
@@ -124,7 +124,7 @@ public abstract class NavigationAbstract {
|
2018-09-09 18:58:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Nullable
|
2019-07-20 06:01:24 +02:00
|
|
|
- public PathEntity a(Entity entity, int i) {
|
|
|
|
+ public final PathEntity calculateDestination(Entity entity) { return a(entity, 0); } public PathEntity a(Entity entity, int i) {
|
2020-06-25 16:09:55 +02:00
|
|
|
return this.a(ImmutableSet.of(entity.getChunkCoordinates()), entity, 16, true, i); // Paper
|
2019-07-20 06:01:24 +02:00
|
|
|
}
|
|
|
|
|
2021-03-16 08:19:45 +01:00
|
|
|
@@ -189,6 +189,7 @@ public abstract class NavigationAbstract {
|
2019-06-25 21:18:50 +02:00
|
|
|
return pathentity != null && this.a(pathentity, d0);
|
|
|
|
}
|
2018-09-09 18:58:47 +02:00
|
|
|
|
|
|
|
+ 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;
|
2021-03-16 08:19:45 +01:00
|
|
|
@@ -216,7 +217,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-12-13 02:18:18 +01:00
|
|
|
+ @Nullable public PathEntity getPathEntity() { return k(); } @Nullable // Paper - OBFHELPER
|
2019-12-12 17:20:43 +01:00
|
|
|
public PathEntity k() {
|
2018-09-09 18:58:47 +02:00
|
|
|
return this.c;
|
|
|
|
}
|
2021-03-16 08:19:45 +01:00
|
|
|
@@ -340,6 +341,7 @@ public abstract class NavigationAbstract {
|
2019-12-12 17:20:43 +01:00
|
|
|
return !this.m();
|
2018-09-09 18:58:47 +02:00
|
|
|
}
|
|
|
|
|
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.c = null;
|
2019-06-25 21:18:50 +02:00
|
|
|
}
|
2021-03-16 08:19:45 +01:00
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/pathfinder/PathEntity.java b/src/main/java/net/minecraft/world/level/pathfinder/PathEntity.java
|
|
|
|
index 606027de777750f6d2ab0d7f1ef387ed4f0c6092..81c3cb9da3f901d2bcf384f7113bdc5c60f9962f 100644
|
|
|
|
--- a/src/main/java/net/minecraft/world/level/pathfinder/PathEntity.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/pathfinder/PathEntity.java
|
|
|
|
@@ -8,13 +8,14 @@ import net.minecraft.world.phys.Vec3D;
|
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 int e;
|
2019-07-20 06:01:24 +02:00
|
|
|
+ private int e; public int getNextIndex() { return this.e; } // Paper - OBFHELPER
|
|
|
|
private final BlockPosition f;
|
|
|
|
private final float g;
|
|
|
|
private final boolean h;
|
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-07-20 06:01:24 +02:00
|
|
|
public PathEntity(List<PathPoint> list, BlockPosition blockposition, boolean flag) {
|
2019-05-05 10:33:44 +02:00
|
|
|
this.a = list;
|
2021-03-16 08:19:45 +01:00
|
|
|
@@ -36,7 +37,7 @@ public class PathEntity {
|
2018-09-09 18:58:47 +02:00
|
|
|
}
|
|
|
|
|
2020-08-25 04:22:08 +02:00
|
|
|
@Nullable
|
|
|
|
- public PathPoint d() {
|
|
|
|
+ public PathPoint getFinalPoint() { return d(); } @Nullable public PathPoint d() { // 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
|
|
|
}
|
|
|
|
|
2021-03-16 08:19:45 +01:00
|
|
|
@@ -84,7 +85,7 @@ public class PathEntity {
|
2018-09-09 18:58:47 +02:00
|
|
|
return this.a(entity, this.e);
|
|
|
|
}
|
|
|
|
|
2020-08-25 04:22:08 +02:00
|
|
|
- public BlockPosition g() {
|
|
|
|
+ public BlockPosition getNext() { return g(); } public BlockPosition g() { // Paper - OBFHELPER
|
|
|
|
return ((PathPoint) this.a.get(this.e)).a();
|
|
|
|
}
|
2019-01-01 04:15:55 +01:00
|
|
|
|
2021-03-16 08:19:45 +01:00
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/pathfinder/PathPoint.java b/src/main/java/net/minecraft/world/level/pathfinder/PathPoint.java
|
|
|
|
index 43cc9430972a18cbf03a590d576ed200e3836017..c260b0ca70cb18811158761c574aee9c3166da28 100644
|
|
|
|
--- a/src/main/java/net/minecraft/world/level/pathfinder/PathPoint.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/pathfinder/PathPoint.java
|
|
|
|
@@ -5,9 +5,9 @@ import net.minecraft.util.MathHelper;
|
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;
|
2021-03-16 08:19:45 +01:00
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/pathfinder/PathfinderAbstract.java b/src/main/java/net/minecraft/world/level/pathfinder/PathfinderAbstract.java
|
|
|
|
index f2080bd50db04af6eabec4b4b757d6dadfb1a2f5..88be03bd77656235322522c3782b9f9a878b86b1 100644
|
|
|
|
--- a/src/main/java/net/minecraft/world/level/pathfinder/PathfinderAbstract.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/pathfinder/PathfinderAbstract.java
|
|
|
|
@@ -16,9 +16,9 @@ public abstract class PathfinderAbstract {
|
2020-05-16 15:15:11 +02:00
|
|
|
protected int d;
|
|
|
|
protected int e;
|
|
|
|
protected int f;
|
|
|
|
- protected boolean g;
|
|
|
|
- protected boolean h;
|
|
|
|
- protected boolean i;
|
|
|
|
+ protected boolean g; public boolean shouldPassDoors() { return g; } public void setShouldPassDoors(boolean b) { g = b; } // Paper - obfhelper
|
|
|
|
+ protected boolean h; public boolean shouldOpenDoors() { return h; } public void setShouldOpenDoors(boolean b) { h = b; } // Paper - obfhelper
|
|
|
|
+ protected boolean i; public boolean shouldFloat() { return i; } public void setShouldFloat(boolean b) { i = b; } // Paper - obfhelper
|
|
|
|
|
|
|
|
public PathfinderAbstract() {}
|
|
|
|
|
2018-09-09 18:58:47 +02:00
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftMob.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftMob.java
|
2021-03-16 08:19:45 +01:00
|
|
|
index eb275ac45def34d5bb1ed696b4f6a4d53d282ab3..28a4e90130f51fd2fda7003fde5b4d0a410e1aef 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();
|