Fix ground pathfinding (#7683)

This commit is contained in:
Jake Potrebic 2022-09-20 14:06:11 -07:00 committed by GitHub
parent 8db45c4312
commit 9e614e6f9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 69 additions and 30 deletions

View File

@ -19,10 +19,41 @@ index 0b2e10a0f508448d9e7d003e6c822f0a56d4022f..27cd393e81f6ef9b5690c051624d8d2a
@Override @Override
diff --git a/src/main/java/net/minecraft/world/entity/ai/navigation/GroundPathNavigation.java b/src/main/java/net/minecraft/world/entity/ai/navigation/GroundPathNavigation.java diff --git a/src/main/java/net/minecraft/world/entity/ai/navigation/GroundPathNavigation.java b/src/main/java/net/minecraft/world/entity/ai/navigation/GroundPathNavigation.java
index 27b072943328aca4489a9565bda700e7e7dcbb6a..f610c06d7bb51ec2c63863dd46711712986a106a 100644 index 27b072943328aca4489a9565bda700e7e7dcbb6a..f0248d839255763005ba333b0bfcf691407fb69b 100644
--- a/src/main/java/net/minecraft/world/entity/ai/navigation/GroundPathNavigation.java --- a/src/main/java/net/minecraft/world/entity/ai/navigation/GroundPathNavigation.java
+++ b/src/main/java/net/minecraft/world/entity/ai/navigation/GroundPathNavigation.java +++ b/src/main/java/net/minecraft/world/entity/ai/navigation/GroundPathNavigation.java
@@ -69,7 +69,7 @@ public class GroundPathNavigation extends PathNavigation { @@ -39,14 +39,14 @@ public class GroundPathNavigation extends PathNavigation {
}
@Override
- public Path createPath(BlockPos target, int distance) {
+ public Path createPath(BlockPos target, @javax.annotation.Nullable Entity entity, int distance) { // Paper
if (this.level.getBlockState(target).isAir()) {
BlockPos blockPos;
for(blockPos = target.below(); blockPos.getY() > this.level.getMinBuildHeight() && this.level.getBlockState(blockPos).isAir(); blockPos = blockPos.below()) {
}
if (blockPos.getY() > this.level.getMinBuildHeight()) {
- return super.createPath(blockPos.above(), distance);
+ return super.createPath(blockPos.above(), entity, distance); // Paper
}
while(blockPos.getY() < this.level.getMaxBuildHeight() && this.level.getBlockState(blockPos).isAir()) {
@@ -57,19 +57,19 @@ public class GroundPathNavigation extends PathNavigation {
}
if (!this.level.getBlockState(target).getMaterial().isSolid()) {
- return super.createPath(target, distance);
+ return super.createPath(target, entity, distance); // Paper
} else {
BlockPos blockPos2;
for(blockPos2 = target.above(); blockPos2.getY() < this.level.getMaxBuildHeight() && this.level.getBlockState(blockPos2).getMaterial().isSolid(); blockPos2 = blockPos2.above()) {
}
- return super.createPath(blockPos2, distance);
+ return super.createPath(blockPos2, entity, distance); // Paper
}
}
@Override @Override
public Path createPath(Entity entity, int distance) { public Path createPath(Entity entity, int distance) {
@ -32,18 +63,10 @@ index 27b072943328aca4489a9565bda700e7e7dcbb6a..f610c06d7bb51ec2c63863dd46711712
private int getSurfaceY() { private int getSurfaceY() {
diff --git a/src/main/java/net/minecraft/world/entity/ai/navigation/PathNavigation.java b/src/main/java/net/minecraft/world/entity/ai/navigation/PathNavigation.java diff --git a/src/main/java/net/minecraft/world/entity/ai/navigation/PathNavigation.java b/src/main/java/net/minecraft/world/entity/ai/navigation/PathNavigation.java
index eaf1653b14e5fdacae38abe75260a64d0ffbfc1d..ff1e04e5e3b8099b0b71eda1c0de864c809c5029 100644 index eaf1653b14e5fdacae38abe75260a64d0ffbfc1d..30f58f1829d1b500ee49b543e3c15e5bfe63fade 100644
--- a/src/main/java/net/minecraft/world/entity/ai/navigation/PathNavigation.java --- a/src/main/java/net/minecraft/world/entity/ai/navigation/PathNavigation.java
+++ b/src/main/java/net/minecraft/world/entity/ai/navigation/PathNavigation.java +++ b/src/main/java/net/minecraft/world/entity/ai/navigation/PathNavigation.java
@@ -10,6 +10,7 @@ import net.minecraft.core.BlockPos; @@ -108,7 +108,13 @@ public abstract class PathNavigation {
import net.minecraft.core.Vec3i;
import net.minecraft.network.protocol.game.DebugPackets;
import net.minecraft.tags.BlockTags;
+import net.minecraft.server.MCUtil;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.Mob;
@@ -108,7 +109,13 @@ public abstract class PathNavigation {
@Nullable @Nullable
public Path createPath(BlockPos target, int distance) { public Path createPath(BlockPos target, int distance) {
@ -52,13 +75,13 @@ index eaf1653b14e5fdacae38abe75260a64d0ffbfc1d..ff1e04e5e3b8099b0b71eda1c0de864c
+ return this.createPath(target, null, distance); + return this.createPath(target, null, distance);
+ } + }
+ @Nullable + @Nullable
+ public Path createPath(BlockPos target, Entity entity, int distance) { + public Path createPath(BlockPos target, @Nullable Entity entity, int distance) {
+ return this.createPath(ImmutableSet.of(target), entity, 8, false, distance); + return this.createPath(ImmutableSet.of(target), entity, 8, false, distance);
+ // Paper end + // Paper end
} }
@Nullable @Nullable
@@ -118,7 +125,7 @@ public abstract class PathNavigation { @@ -118,7 +124,7 @@ public abstract class PathNavigation {
@Nullable @Nullable
public Path createPath(Entity entity, int distance) { public Path createPath(Entity entity, int distance) {
@ -67,24 +90,24 @@ index eaf1653b14e5fdacae38abe75260a64d0ffbfc1d..ff1e04e5e3b8099b0b71eda1c0de864c
} }
@Nullable @Nullable
@@ -128,6 +135,16 @@ public abstract class PathNavigation { @@ -128,6 +134,16 @@ public abstract class PathNavigation {
@Nullable @Nullable
protected Path createPath(Set<BlockPos> positions, int range, boolean useHeadPos, int distance, float followRange) { protected Path createPath(Set<BlockPos> positions, int range, boolean useHeadPos, int distance, float followRange) {
+ return this.createPath(positions, null, range, useHeadPos, distance, (float) this.mob.getAttributeValue(Attributes.FOLLOW_RANGE)); + return this.createPath(positions, null, range, useHeadPos, distance, followRange);
+ } + }
+ +
+ @Nullable + @Nullable
+ protected Path createPath(Set<BlockPos> positions, Entity target, int range, boolean useHeadPos, int distance) { + protected Path createPath(Set<BlockPos> positions, @Nullable Entity target, int range, boolean useHeadPos, int distance) {
+ return this.createPath(positions, target, range, useHeadPos, distance, (float) this.mob.getAttributeValue(Attributes.FOLLOW_RANGE)); + return this.createPath(positions, target, range, useHeadPos, distance, (float) this.mob.getAttributeValue(Attributes.FOLLOW_RANGE));
+ } + }
+ +
+ @Nullable protected Path createPath(Set<BlockPos> positions, Entity target, int range, boolean useHeadPos, int distance, float followRange) { + @Nullable protected Path createPath(Set<BlockPos> positions, @Nullable Entity target, int range, boolean useHeadPos, int distance, float followRange) {
+ // Paper end + // Paper end
if (positions.isEmpty()) { if (positions.isEmpty()) {
return null; return null;
} else if (this.mob.getY() < (double)this.level.getMinBuildHeight()) { } else if (this.mob.getY() < (double)this.level.getMinBuildHeight()) {
@@ -137,6 +154,23 @@ public abstract class PathNavigation { @@ -137,6 +153,23 @@ public abstract class PathNavigation {
} else if (this.path != null && !this.path.isDone() && positions.contains(this.targetPos)) { } else if (this.path != null && !this.path.isDone() && positions.contains(this.targetPos)) {
return this.path; return this.path;
} else { } else {
@ -92,7 +115,7 @@ index eaf1653b14e5fdacae38abe75260a64d0ffbfc1d..ff1e04e5e3b8099b0b71eda1c0de864c
+ boolean copiedSet = false; + boolean copiedSet = false;
+ for (BlockPos possibleTarget : positions) { + for (BlockPos possibleTarget : positions) {
+ if (!new com.destroystokyo.paper.event.entity.EntityPathfindEvent(this.mob.getBukkitEntity(), + if (!new com.destroystokyo.paper.event.entity.EntityPathfindEvent(this.mob.getBukkitEntity(),
+ MCUtil.toLocation(this.mob.level, possibleTarget), target == null ? null : target.getBukkitEntity()).callEvent()) { + net.minecraft.server.MCUtil.toLocation(this.mob.level, possibleTarget), target == null ? null : target.getBukkitEntity()).callEvent()) {
+ if (!copiedSet) { + if (!copiedSet) {
+ copiedSet = true; + copiedSet = true;
+ positions = new java.util.HashSet<>(positions); + positions = new java.util.HashSet<>(positions);
@ -108,3 +131,19 @@ index eaf1653b14e5fdacae38abe75260a64d0ffbfc1d..ff1e04e5e3b8099b0b71eda1c0de864c
this.level.getProfiler().push("pathfind"); this.level.getProfiler().push("pathfind");
BlockPos blockPos = useHeadPos ? this.mob.blockPosition().above() : this.mob.blockPosition(); BlockPos blockPos = useHeadPos ? this.mob.blockPosition().above() : this.mob.blockPosition();
int i = (int)(followRange + (float)range); int i = (int)(followRange + (float)range);
diff --git a/src/main/java/net/minecraft/world/entity/ai/navigation/WallClimberNavigation.java b/src/main/java/net/minecraft/world/entity/ai/navigation/WallClimberNavigation.java
index d11e9f4f7ae5f2666d67878309b4a1359ef90e39..de1f178fa18ae3ff3c73bc59b10eb39857800bf9 100644
--- a/src/main/java/net/minecraft/world/entity/ai/navigation/WallClimberNavigation.java
+++ b/src/main/java/net/minecraft/world/entity/ai/navigation/WallClimberNavigation.java
@@ -16,9 +16,9 @@ public class WallClimberNavigation extends GroundPathNavigation {
}
@Override
- public Path createPath(BlockPos target, int distance) {
+ public Path createPath(BlockPos target, @Nullable Entity entity, int distance) { // Paper
this.pathToPosition = target;
- return super.createPath(target, distance);
+ return super.createPath(target, entity, distance); // Paper
}
@Override

View File

@ -13,15 +13,15 @@ by adding code to all overrides in:
to return BLOCKED if it is outside the world border. to return BLOCKED if it is outside the world border.
diff --git a/src/main/java/net/minecraft/world/entity/ai/navigation/PathNavigation.java b/src/main/java/net/minecraft/world/entity/ai/navigation/PathNavigation.java diff --git a/src/main/java/net/minecraft/world/entity/ai/navigation/PathNavigation.java b/src/main/java/net/minecraft/world/entity/ai/navigation/PathNavigation.java
index ff1e04e5e3b8099b0b71eda1c0de864c809c5029..649c2fdba307d986d13916bf90e311c862ccefc1 100644 index 30f58f1829d1b500ee49b543e3c15e5bfe63fade..64cbff139ee8ccf5cdfe7c3d97fa69d8244becb2 100644
--- a/src/main/java/net/minecraft/world/entity/ai/navigation/PathNavigation.java --- a/src/main/java/net/minecraft/world/entity/ai/navigation/PathNavigation.java
+++ b/src/main/java/net/minecraft/world/entity/ai/navigation/PathNavigation.java +++ b/src/main/java/net/minecraft/world/entity/ai/navigation/PathNavigation.java
@@ -157,7 +157,7 @@ public abstract class PathNavigation { @@ -156,7 +156,7 @@ public abstract class PathNavigation {
// Paper start - Pathfind event // Paper start - Pathfind event
boolean copiedSet = false; boolean copiedSet = false;
for (BlockPos possibleTarget : positions) { for (BlockPos possibleTarget : positions) {
- if (!new com.destroystokyo.paper.event.entity.EntityPathfindEvent(this.mob.getBukkitEntity(), - if (!new com.destroystokyo.paper.event.entity.EntityPathfindEvent(this.mob.getBukkitEntity(),
+ if (!this.mob.getCommandSenderWorld().getWorldBorder().isWithinBounds(possibleTarget) || !new com.destroystokyo.paper.event.entity.EntityPathfindEvent(this.mob.getBukkitEntity(), // Paper - don't path out of world border + if (!this.mob.getCommandSenderWorld().getWorldBorder().isWithinBounds(possibleTarget) || !new com.destroystokyo.paper.event.entity.EntityPathfindEvent(this.mob.getBukkitEntity(), // Paper - don't path out of world border
MCUtil.toLocation(this.mob.level, possibleTarget), target == null ? null : target.getBukkitEntity()).callEvent()) { net.minecraft.server.MCUtil.toLocation(this.mob.level, possibleTarget), target == null ? null : target.getBukkitEntity()).callEvent()) {
if (!copiedSet) { if (!copiedSet) {
copiedSet = true; copiedSet = true;

View File

@ -7,10 +7,10 @@ Prevents pathfinding from spamming failures for things such as
arrow attacks. arrow attacks.
diff --git a/src/main/java/net/minecraft/world/entity/ai/navigation/PathNavigation.java b/src/main/java/net/minecraft/world/entity/ai/navigation/PathNavigation.java diff --git a/src/main/java/net/minecraft/world/entity/ai/navigation/PathNavigation.java b/src/main/java/net/minecraft/world/entity/ai/navigation/PathNavigation.java
index 649c2fdba307d986d13916bf90e311c862ccefc1..af53372391d05dd6aa3757556418e8723b8b6d80 100644 index 64cbff139ee8ccf5cdfe7c3d97fa69d8244becb2..c1781c92ff59f0c9eb47cbbef01e3252c5e1a1bf 100644
--- a/src/main/java/net/minecraft/world/entity/ai/navigation/PathNavigation.java --- a/src/main/java/net/minecraft/world/entity/ai/navigation/PathNavigation.java
+++ b/src/main/java/net/minecraft/world/entity/ai/navigation/PathNavigation.java +++ b/src/main/java/net/minecraft/world/entity/ai/navigation/PathNavigation.java
@@ -191,9 +191,29 @@ public abstract class PathNavigation { @@ -190,9 +190,29 @@ public abstract class PathNavigation {
return this.moveTo(this.createPath(x, y, z, 1), speed); return this.moveTo(this.createPath(x, y, z, 1), speed);
} }

View File

@ -183,10 +183,10 @@ index 25149dde919738859f6fb6b2d0405e90d1732f2b..a7a403d34551453a1e0502fe1f7bc139
if (paperConfig().fixes.disableUnloadedChunkEnderpearlExploit && entity instanceof net.minecraft.world.entity.projectile.ThrownEnderpearl pearl) { if (paperConfig().fixes.disableUnloadedChunkEnderpearlExploit && entity instanceof net.minecraft.world.entity.projectile.ThrownEnderpearl pearl) {
pearl.cachedOwner = null; pearl.cachedOwner = null;
diff --git a/src/main/java/net/minecraft/world/entity/ai/navigation/PathNavigation.java b/src/main/java/net/minecraft/world/entity/ai/navigation/PathNavigation.java diff --git a/src/main/java/net/minecraft/world/entity/ai/navigation/PathNavigation.java b/src/main/java/net/minecraft/world/entity/ai/navigation/PathNavigation.java
index af53372391d05dd6aa3757556418e8723b8b6d80..3f672d7c2377fca16a6d8d31cf7aaae4f009fdce 100644 index c1781c92ff59f0c9eb47cbbef01e3252c5e1a1bf..02653adc591d390ca8b4ee13289510d4652c8894 100644
--- a/src/main/java/net/minecraft/world/entity/ai/navigation/PathNavigation.java --- a/src/main/java/net/minecraft/world/entity/ai/navigation/PathNavigation.java
+++ b/src/main/java/net/minecraft/world/entity/ai/navigation/PathNavigation.java +++ b/src/main/java/net/minecraft/world/entity/ai/navigation/PathNavigation.java
@@ -29,7 +29,7 @@ import net.minecraft.world.phys.Vec3; @@ -28,7 +28,7 @@ import net.minecraft.world.phys.Vec3;
public abstract class PathNavigation { public abstract class PathNavigation {
private static final int MAX_TIME_RECOMPUTE = 20; private static final int MAX_TIME_RECOMPUTE = 20;
@ -195,7 +195,7 @@ index af53372391d05dd6aa3757556418e8723b8b6d80..3f672d7c2377fca16a6d8d31cf7aaae4
protected final Level level; protected final Level level;
@Nullable @Nullable
protected Path path; protected Path path;
@@ -42,7 +42,7 @@ public abstract class PathNavigation { @@ -41,7 +41,7 @@ public abstract class PathNavigation {
protected long lastTimeoutCheck; protected long lastTimeoutCheck;
protected double timeoutLimit; protected double timeoutLimit;
protected float maxDistanceToWaypoint = 0.5F; protected float maxDistanceToWaypoint = 0.5F;
@ -204,7 +204,7 @@ index af53372391d05dd6aa3757556418e8723b8b6d80..3f672d7c2377fca16a6d8d31cf7aaae4
protected long timeLastRecompute; protected long timeLastRecompute;
protected NodeEvaluator nodeEvaluator; protected NodeEvaluator nodeEvaluator;
@Nullable @Nullable
@@ -420,7 +420,7 @@ public abstract class PathNavigation { @@ -419,7 +419,7 @@ public abstract class PathNavigation {
public boolean shouldRecomputePath(BlockPos pos) { public boolean shouldRecomputePath(BlockPos pos) {
if (this.hasDelayedRecomputation) { if (this.hasDelayedRecomputation) {
return false; return false;
@ -213,7 +213,7 @@ index af53372391d05dd6aa3757556418e8723b8b6d80..3f672d7c2377fca16a6d8d31cf7aaae4
Node node = this.path.getEndNode(); Node node = this.path.getEndNode();
Vec3 vec3 = new Vec3(((double)node.x + this.mob.getX()) / 2.0D, ((double)node.y + this.mob.getY()) / 2.0D, ((double)node.z + this.mob.getZ()) / 2.0D); Vec3 vec3 = new Vec3(((double)node.x + this.mob.getX()) / 2.0D, ((double)node.y + this.mob.getY()) / 2.0D, ((double)node.z + this.mob.getZ()) / 2.0D);
return pos.closerToCenterThan(vec3, (double)(this.path.getNodeCount() - this.path.getNextNodeIndex())); return pos.closerToCenterThan(vec3, (double)(this.path.getNodeCount() - this.path.getNextNodeIndex()));
@@ -436,4 +436,11 @@ public abstract class PathNavigation { @@ -435,4 +435,11 @@ public abstract class PathNavigation {
public boolean isStuck() { public boolean isStuck() {
return this.isStuck; return this.isStuck;
} }