mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-30 16:19:03 +01:00
69ee95fa42
PaperMC believes that 1.16.2 is now ready for general release as we fixed the main issue plagueing the 1.16.x release, the MapLike data conversion issues. Until now, it was not safe for a server to convert a world to 1.16.2 without data conversion issues around villages and potentially other things. If you did, those MapLike errors meant something went wrong. This is now resolved. Big thanks to all those that helped, notably @BillyGalbreath and @Proximyst who did large parts of the update process with me. Please as always, backup your worlds and test before updating to 1.16.2! If you update to 1.16.2, there is no going back to an older build than this. --------------------------------- Co-authored-by: William Blake Galbreath <Blake.Galbreath@GMail.com> Co-authored-by: Mariell Hoversholm <proximyst@proximyst.com> Co-authored-by: krolik-exe <69214078+krolik-exe@users.noreply.github.com> Co-authored-by: BillyGalbreath <BillyGalbreath@users.noreply.github.com> Co-authored-by: stonar96 <minecraft.stonar96@gmail.com> Co-authored-by: Shane Freeder <theboyetronic@gmail.com> Co-authored-by: Jason Penilla <11360596+jpenilla@users.noreply.github.com> Co-authored-by: Riley Park <rileysebastianpark@gmail.com> Co-authored-by: Aurora <21148213+aurorasmiles@users.noreply.github.com> Co-authored-by: Nassim Jahnke <nassim@njahnke.dev> Co-authored-by: commandblockguy <commandblockguy1@gmail.com> Co-authored-by: DigitalRegent <misterwener@gmail.com> Co-authored-by: ishland <ishlandmc@yeah.net>
290 lines
11 KiB
Diff
290 lines
11 KiB
Diff
From 0000000000000000000000000000000000000000 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
|
|
|
|
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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000
|
|
--- /dev/null
|
|
+++ b/src/main/java/com/destroystokyo/paper/entity/PaperPathfinder.java
|
|
@@ -0,0 +0,0 @@
|
|
+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
|
|
+ public boolean hasPath() {
|
|
+ return entity.getNavigation().getPathEntity() != null;
|
|
+ }
|
|
+
|
|
+ @Nullable
|
|
+ @Override
|
|
+ public PathResult getCurrentPath() {
|
|
+ PathEntity path = entity.getNavigation().getPathEntity();
|
|
+ return path != null ? new PaperPathResult(path) : null;
|
|
+ }
|
|
+
|
|
+ @Nullable
|
|
+ @Override
|
|
+ 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;
|
|
+ }
|
|
+
|
|
+ @Nullable
|
|
+ @Override
|
|
+ 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 moveTo(@Nonnull PathResult path, double speed) {
|
|
+ Validate.notNull(path, "PathResult can not be null");
|
|
+ PathEntity pathEntity = ((PaperPathResult) path).path;
|
|
+ return entity.getNavigation().setDestination(pathEntity, speed);
|
|
+ }
|
|
+
|
|
+ @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);
|
|
+ }
|
|
+
|
|
+ public class PaperPathResult implements com.destroystokyo.paper.entity.PaperPathfinder.PathResult {
|
|
+
|
|
+ private final PathEntity path;
|
|
+ PaperPathResult(PathEntity path) {
|
|
+ this.path = path;
|
|
+ }
|
|
+
|
|
+ @Nullable
|
|
+ @Override
|
|
+ public Location getFinalPoint() {
|
|
+ PathPoint point = path.getFinalPoint();
|
|
+ return point != null ? toLoc(point) : null;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public List<Location> getPoints() {
|
|
+ List<Location> points = new ArrayList<>();
|
|
+ for (PathPoint point : path.getPoints()) {
|
|
+ points.add(toLoc(point));
|
|
+ }
|
|
+ return points;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public int getNextPointIndex() {
|
|
+ return path.getNextIndex();
|
|
+ }
|
|
+
|
|
+ @Nullable
|
|
+ @Override
|
|
+ public Location getNextPoint() {
|
|
+ if (!path.hasNext()) {
|
|
+ return null;
|
|
+ }
|
|
+ return toLoc(path.getPoints().get(path.getNextIndex()));
|
|
+ }
|
|
+ }
|
|
+
|
|
+ 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
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/net/minecraft/server/NavigationAbstract.java
|
|
+++ b/src/main/java/net/minecraft/server/NavigationAbstract.java
|
|
@@ -0,0 +0,0 @@ public abstract class NavigationAbstract {
|
|
}
|
|
|
|
@Nullable
|
|
- 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);
|
|
}
|
|
|
|
@@ -0,0 +0,0 @@ public abstract class NavigationAbstract {
|
|
}
|
|
|
|
@Nullable
|
|
- public PathEntity a(Entity entity, int i) {
|
|
+ public final PathEntity calculateDestination(Entity entity) { return a(entity, 0); } public PathEntity a(Entity entity, int i) {
|
|
return this.a(ImmutableSet.of(entity.getChunkCoordinates()), entity, 16, true, i); // Paper
|
|
}
|
|
|
|
@@ -0,0 +0,0 @@ public abstract class NavigationAbstract {
|
|
return pathentity != null && this.a(pathentity, d0);
|
|
}
|
|
|
|
+ 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;
|
|
@@ -0,0 +0,0 @@ public abstract class NavigationAbstract {
|
|
}
|
|
}
|
|
|
|
- @Nullable
|
|
+ @Nullable public PathEntity getPathEntity() { return k(); } @Nullable // Paper - OBFHELPER
|
|
public PathEntity k() {
|
|
return this.c;
|
|
}
|
|
@@ -0,0 +0,0 @@ public abstract class NavigationAbstract {
|
|
return !this.m();
|
|
}
|
|
|
|
+ public void stopPathfinding() { o(); } // Paper - OBFHELPER
|
|
public void o() {
|
|
this.c = null;
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/server/PathEntity.java b/src/main/java/net/minecraft/server/PathEntity.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/net/minecraft/server/PathEntity.java
|
|
+++ b/src/main/java/net/minecraft/server/PathEntity.java
|
|
@@ -0,0 +0,0 @@ import javax.annotation.Nullable;
|
|
|
|
public class PathEntity {
|
|
|
|
- private final List<PathPoint> a;
|
|
+ private final List<PathPoint> a; public List<PathPoint> getPoints() { return a; } // Paper - OBFHELPER
|
|
private PathPoint[] b = new PathPoint[0];
|
|
private PathPoint[] c = new PathPoint[0];
|
|
- private int e;
|
|
+ private int e; public int getNextIndex() { return this.e; } // Paper - OBFHELPER
|
|
private final BlockPosition f;
|
|
private final float g;
|
|
private final boolean h;
|
|
+ public boolean hasNext() { return getNextIndex() < getPoints().size(); } // Paper
|
|
|
|
public PathEntity(List<PathPoint> list, BlockPosition blockposition, boolean flag) {
|
|
this.a = list;
|
|
@@ -0,0 +0,0 @@ public class PathEntity {
|
|
}
|
|
|
|
@Nullable
|
|
- public PathPoint d() {
|
|
+ public PathPoint getFinalPoint() { return d(); } @Nullable public PathPoint d() { // Paper - OBFHELPER
|
|
return !this.a.isEmpty() ? (PathPoint) this.a.get(this.a.size() - 1) : null;
|
|
}
|
|
|
|
@@ -0,0 +0,0 @@ public class PathEntity {
|
|
return this.a(entity, this.e);
|
|
}
|
|
|
|
- public BlockPosition g() {
|
|
+ public BlockPosition getNext() { return g(); } public BlockPosition g() { // Paper - OBFHELPER
|
|
return ((PathPoint) this.a.get(this.e)).a();
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/PathPoint.java b/src/main/java/net/minecraft/server/PathPoint.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/net/minecraft/server/PathPoint.java
|
|
+++ b/src/main/java/net/minecraft/server/PathPoint.java
|
|
@@ -0,0 +0,0 @@ package net.minecraft.server;
|
|
|
|
public class PathPoint {
|
|
|
|
- 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
|
|
private final int m;
|
|
public int d = -1;
|
|
public float e;
|
|
diff --git a/src/main/java/net/minecraft/server/PathfinderAbstract.java b/src/main/java/net/minecraft/server/PathfinderAbstract.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/net/minecraft/server/PathfinderAbstract.java
|
|
+++ b/src/main/java/net/minecraft/server/PathfinderAbstract.java
|
|
@@ -0,0 +0,0 @@ public abstract class PathfinderAbstract {
|
|
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() {}
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftMob.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftMob.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftMob.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftMob.java
|
|
@@ -0,0 +0,0 @@ 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();
|