diff --git a/paper-server/patches/sources/net/minecraft/world/entity/ai/navigation/PathNavigation.java.patch b/paper-server/patches/sources/net/minecraft/world/entity/ai/navigation/PathNavigation.java.patch index 409cb206a..124ed4851 100644 --- a/paper-server/patches/sources/net/minecraft/world/entity/ai/navigation/PathNavigation.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/entity/ai/navigation/PathNavigation.java.patch @@ -67,3 +67,38 @@ ProfilerFiller profilerFiller = Profiler.get(); profilerFiller.push("pathfind"); BlockPos blockPos = useHeadPos ? this.mob.blockPosition().above() : this.mob.blockPosition(); +@@ -175,13 +209,33 @@ + return this.moveTo(this.createPath(x, y, z, 1), speed); + } + ++ // Paper start - Perf: Optimise pathfinding ++ private int lastFailure = 0; ++ private int pathfindFailures = 0; ++ // Paper end - Perf: Optimise pathfinding ++ + public boolean moveTo(double x, double y, double z, int distance, double speed) { + return this.moveTo(this.createPath(x, y, z, distance), speed); + } + + public boolean moveTo(Entity entity, double speed) { ++ // Paper start - Perf: Optimise pathfinding ++ if (this.pathfindFailures > 10 && this.path == null && net.minecraft.server.MinecraftServer.currentTick < this.lastFailure + 40) { ++ return false; ++ } ++ // Paper end - Perf: Optimise pathfinding + Path path = this.createPath(entity, 1); +- return path != null && this.moveTo(path, speed); ++ // Paper start - Perf: Optimise pathfinding ++ if (path != null && this.moveTo(path, speed)) { ++ this.lastFailure = 0; ++ this.pathfindFailures = 0; ++ return true; ++ } else { ++ this.pathfindFailures++; ++ this.lastFailure = net.minecraft.server.MinecraftServer.currentTick; ++ return false; ++ } ++ // Paper end - Perf: Optimise pathfinding + } + + public boolean moveTo(@Nullable Path path, double speed) {