From 0656f9d6add597c85249538e13b7634ed4b1dc60 Mon Sep 17 00:00:00 2001 From: fullwall Date: Thu, 13 Aug 2020 12:54:45 +0800 Subject: [PATCH] Update pathfinder --- .../nms/v1_16_R2/util/PlayerNavigation.java | 10 +-- .../nms/v1_16_R2/util/PlayerPathfinder.java | 89 ++++++++----------- .../v1_16_R2/util/PlayerPathfinderNormal.java | 55 +++++------- 3 files changed, 61 insertions(+), 93 deletions(-) diff --git a/v1_16_R2/src/main/java/net/citizensnpcs/nms/v1_16_R2/util/PlayerNavigation.java b/v1_16_R2/src/main/java/net/citizensnpcs/nms/v1_16_R2/util/PlayerNavigation.java index b626c41f1..7a38e82b7 100644 --- a/v1_16_R2/src/main/java/net/citizensnpcs/nms/v1_16_R2/util/PlayerNavigation.java +++ b/v1_16_R2/src/main/java/net/citizensnpcs/nms/v1_16_R2/util/PlayerNavigation.java @@ -236,7 +236,7 @@ public class PlayerNavigation extends NavigationAbstract { this.f = this.e; this.g = var0; } - if (this.c != null && !this.c.b()) { + if (this.c != null && !this.c.c()) { BaseBlockPosition var1 = this.c.g(); if (var1.equals(this.h)) { this.i += SystemUtils.getMonotonicMillis() - this.j; @@ -354,12 +354,12 @@ public class PlayerNavigation extends NavigationAbstract { return; if (a()) { l(); - } else if (this.c != null && this.c.f() < this.c.e()) { + } else if (this.c != null && !this.c.c()) { Vec3D vec3D1 = b(); - Vec3D vec3D2 = this.c.a(this.a, this.c.f()); + Vec3D vec3D2 = this.c.a(this.a); if (vec3D1.y > vec3D2.y && !this.a.isOnGround() && MathHelper.floor(vec3D1.x) == MathHelper.floor(vec3D2.x) && MathHelper.floor(vec3D1.z) == MathHelper.floor(vec3D2.z)) - this.c.c(this.c.f() + 1); + this.c.a(); } if (m()) return; @@ -503,7 +503,7 @@ public class PlayerNavigation extends NavigationAbstract { if (var3.a(Blocks.CAULDRON)) { this.c.a(var0, var1.a(var1.a, var1.b + 1, var1.c)); if (var2 != null && var1.b >= var2.b) - this.c.a(var0 + 1, var2.a(var2.a, var1.b + 1, var2.c)); + this.c.a(var0 + 1, var1.a(var2.a, var1.b + 1, var2.c)); } } } diff --git a/v1_16_R2/src/main/java/net/citizensnpcs/nms/v1_16_R2/util/PlayerPathfinder.java b/v1_16_R2/src/main/java/net/citizensnpcs/nms/v1_16_R2/util/PlayerPathfinder.java index bb2f96666..2a9f449e8 100644 --- a/v1_16_R2/src/main/java/net/citizensnpcs/nms/v1_16_R2/util/PlayerPathfinder.java +++ b/v1_16_R2/src/main/java/net/citizensnpcs/nms/v1_16_R2/util/PlayerPathfinder.java @@ -1,7 +1,6 @@ package net.citizensnpcs.nms.v1_16_R2.util; import java.util.Comparator; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Optional; @@ -65,70 +64,55 @@ public class PlayerPathfinder extends Pathfinder { } private PathEntity a(PathPoint var0, BlockPosition var1, boolean var2) { - List var3 = Lists.newArrayList(); + List var3 = Lists.newArrayList(); PathPoint var4 = var0; - var3.add(0, var0); - + var3.add(0, var4); while (var4.h != null) { var4 = var4.h; var3.add(0, var4); } - return new PathEntity(var3, var1, var2); } private PathEntity a(PathPoint var0, Map var1, float var2, int var3, float var4) { - Set var5 = var1.keySet(); + Set var5 = var1.keySet(); var0.e = 0.0F; - var0.f = this.a(var0, var5); + var0.f = a(var0, var5); var0.g = var0.f; this.d.a(); this.d.a(var0); - Set var6 = ImmutableSet.of(); + ImmutableSet immutableSet = ImmutableSet.of(); int var7 = 0; Set var8 = Sets.newHashSetWithExpectedSize(var5.size()); int var9 = (int) (this.b * var4); - - while (!this.d.e()) { - ++var7; - if (var7 >= var9) { - break; - } - - PathPoint var10 = this.d.c(); - var10.i = true; - Iterator var12 = var5.iterator(); - - while (var12.hasNext()) { - PathDestination var122 = (PathDestination) var12.next(); - if (var10.c(var122) <= var3) { - var122.e(); - var8.add(var122); + while (!this.d.e() && ++var7 < var9) { + PathPoint pathPoint = this.d.c(); + pathPoint.i = true; + for (PathDestination pathDestination : var5) { + if (pathPoint.c(pathDestination) <= var3) { + pathDestination.e(); + var8.add(pathDestination); } } - - if (!var8.isEmpty()) { + if (!var8.isEmpty()) break; - } - - if (var10.a(var0) < var2) { - int var11 = this.c.a(this.a, var10); - - for (int var12i = 0; var12i < var11; ++var12i) { - PathPoint var13 = this.a[var12i]; - float var14 = var10.a(var13); - var13.j = var10.j + var14; - float var15 = var10.e + var14 + var13.k; - if (var13.j < var2 && (!var13.c() || var15 < var13.e)) { - var13.h = var10; - var13.e = var15; - var13.f = this.a(var13, var5) * 1.5F; - if (var13.c()) { - this.d.a(var13, var13.e + var13.f); - } else { - var13.g = var13.e + var13.f; - this.d.a(var13); - } + if (pathPoint.a(var0) >= var2) + continue; + int i = this.c.a(this.a, pathPoint); + for (int var12 = 0; var12 < i; var12++) { + PathPoint var13 = this.a[var12]; + float var14 = pathPoint.a(var13); + pathPoint.j += var14; + float var15 = pathPoint.e + var14 + var13.k; + if (var13.j < var2 && (!var13.c() || var15 < var13.e)) { + var13.h = pathPoint; + var13.e = var15; + var13.f = a(var13, var5) * 1.5F; + if (var13.c()) { + this.d.a(var13, var13.e + var13.f); + } else { + var13.g = var13.e + var13.f; + this.d.a(var13); } } } @@ -144,16 +128,13 @@ public class PlayerPathfinder extends Pathfinder { } } - private float a(PathPoint var0, Set var1) { + private float a(PathPoint var0, Set var1) { float var2 = Float.MAX_VALUE; - - float var5; - for (Iterator var4 = var1.iterator(); var4.hasNext(); var2 = Math.min(var5, var2)) { - PathDestination var44 = (PathDestination) var4.next(); - var5 = var0.a(var44); - var44.a(var5, var0); + for (PathDestination var4 : var1) { + float var5 = var0.a(var4); + var4.a(var5, var0); + var2 = Math.min(var5, var2); } - return var2; } diff --git a/v1_16_R2/src/main/java/net/citizensnpcs/nms/v1_16_R2/util/PlayerPathfinderNormal.java b/v1_16_R2/src/main/java/net/citizensnpcs/nms/v1_16_R2/util/PlayerPathfinderNormal.java index 78d6fd2d9..e1ca6fd53 100644 --- a/v1_16_R2/src/main/java/net/citizensnpcs/nms/v1_16_R2/util/PlayerPathfinderNormal.java +++ b/v1_16_R2/src/main/java/net/citizensnpcs/nms/v1_16_R2/util/PlayerPathfinderNormal.java @@ -115,7 +115,7 @@ public class PlayerPathfinderNormal extends PlayerPathfinderAbstract { if (var4.a(var15) >= var4.a(var13)) var13 = var15; } - if (var11 == PathType.OPEN && var4.a(var13) == 0.0F) + if (var11 == PathType.OPEN && var4.a(var13) == 0.0F && var5 <= 1) return PathType.OPEN; return var13; } @@ -209,47 +209,35 @@ public class PlayerPathfinderNormal extends PlayerPathfinderAbstract { } } if (var12 == PathType.OPEN) { - AxisAlignedBB var16 = new AxisAlignedBB(var0 - var14 + 0.5D, var1 + 0.001D, var2 - var14 + 0.5D, - var0 + var14 + 0.5D, (var1 + this.b.getHeight()), var2 + var14 + 0.5D); - if (a(var16)) - return null; - if (this.b.getWidth() >= 1.0F) { - PathType pathType = a(this.b, var0, var1 - 1, var2); - if (pathType == PathType.BLOCKED) { - var8 = a(var0, var1, var2); - var8.l = PathType.WALKABLE; - var8.k = Math.max(var8.k, var13); - return var8; - } - } - int var17 = 0; - int var18 = var1; + int var16 = 0; + int var17 = var1; while (var12 == PathType.OPEN) { var1--; if (var1 < 0) { - PathPoint pathPoint = a(var0, var18, var2); - pathPoint.l = PathType.BLOCKED; - pathPoint.k = -1.0F; - return pathPoint; + PathPoint var18 = a(var0, var17, var2); + var18.l = PathType.BLOCKED; + var18.k = -1.0F; + return var18; } - PathPoint var19 = a(var0, var1, var2); - if (var17++ >= this.b.bO()) { - var19.l = PathType.BLOCKED; - var19.k = -1.0F; - return var19; + if (var16++ >= this.b.bO()) { + PathPoint var18 = a(var0, var1, var2); + var18.l = PathType.BLOCKED; + var18.k = -1.0F; + return var18; } var12 = a(this.b, var0, var1, var2); var13 = this.b.a(var12); if (var12 != PathType.OPEN && var13 >= 0.0F) { - var8 = var19; + var8 = a(var0, var1, var2); var8.l = var12; var8.k = Math.max(var8.k, var13); break; } if (var13 < 0.0F) { - var19.l = PathType.BLOCKED; - var19.k = -1.0F; - return var19; + PathPoint var18 = a(var0, var1, var2); + var18.l = PathType.BLOCKED; + var18.k = -1.0F; + return var18; } } } @@ -286,6 +274,8 @@ public class PlayerPathfinderNormal extends PlayerPathfinderAbstract { return false; if (var2.b > var0.b || var1.b > var0.b) return false; + if (var1.l == PathType.WALKABLE_DOOR || var2.l == PathType.WALKABLE_DOOR || var3.l == PathType.WALKABLE_DOOR) + return false; boolean var4 = (var2.l == PathType.FENCE && var1.l == PathType.FENCE && this.b.getWidth() < 0.5D); return (var3.k >= 0.0F && (var2.b < var0.b || var2.k >= 0.0F || var4) && (var1.b < var0.b || var1.k >= 0.0F || var4)); @@ -418,11 +408,8 @@ public class PlayerPathfinderNormal extends PlayerPathfinderAbstract { return PathType.DANGER_OTHER; if (a(var9)) return PathType.DANGER_FIRE; - Fluid var10 = var0.getFluid(var1); - if (var10.a(TagsFluid.WATER)) + if (var0.getFluid(var1).a(TagsFluid.WATER)) return PathType.WATER_BORDER; - if (var10.a(TagsFluid.LAVA)) - return PathType.LAVA; } } } @@ -431,7 +418,7 @@ public class PlayerPathfinderNormal extends PlayerPathfinderAbstract { } private static boolean a(IBlockData var0) { - return (var0.a(TagsBlock.FIRE) || var0.a(Blocks.MAGMA_BLOCK) || BlockCampfire.g(var0)); + return (var0.a(TagsBlock.FIRE) || var0.a(Blocks.LAVA) || var0.a(Blocks.MAGMA_BLOCK) || BlockCampfire.g(var0)); } public static double aa(IBlockAccess var0, BlockPosition var1) {