Optimize Pathfinding

Prevents pathfinding from spamming failures for things such as
arrow attacks.
This commit is contained in:
Aikar 2016-03-03 02:02:07 -06:00
parent 7659c20386
commit aa8e04867f

View file

@ -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) {