use of net.minecraft.world.level.pathfinder.Node in project Citizens2 by CitizensDev.
the class PlayerNodeEvaluator method getNeighbors.
@Override
public int getNeighbors(Node[] var0, Node var1) {
int var2 = 0;
int var3 = 0;
BlockPathTypes var4 = getCachedBlockType(this.mob, var1.x, var1.y + 1, var1.z);
BlockPathTypes var5 = getCachedBlockType(this.mob, var1.x, var1.y, var1.z);
if (this.mob.getPathfindingMalus(var4) >= 0.0F && var5 != BlockPathTypes.STICKY_HONEY)
var3 = Mth.floor(Math.max(1.0F, this.mob.maxUpStep));
double var6 = getFloorLevel(new BlockPos(var1.x, var1.y, var1.z));
Node var8 = findAcceptedNode(var1.x, var1.y, var1.z + 1, var3, var6, Direction.SOUTH, var5);
if (isNeighborValid(var8, var1))
var0[var2++] = var8;
Node var9 = findAcceptedNode(var1.x - 1, var1.y, var1.z, var3, var6, Direction.WEST, var5);
if (isNeighborValid(var9, var1))
var0[var2++] = var9;
Node var10 = findAcceptedNode(var1.x + 1, var1.y, var1.z, var3, var6, Direction.EAST, var5);
if (isNeighborValid(var10, var1))
var0[var2++] = var10;
Node var11 = findAcceptedNode(var1.x, var1.y, var1.z - 1, var3, var6, Direction.NORTH, var5);
if (isNeighborValid(var11, var1))
var0[var2++] = var11;
Node var12 = findAcceptedNode(var1.x - 1, var1.y, var1.z - 1, var3, var6, Direction.NORTH, var5);
if (isDiagonalValid(var1, var9, var11, var12))
var0[var2++] = var12;
Node var13 = findAcceptedNode(var1.x + 1, var1.y, var1.z - 1, var3, var6, Direction.NORTH, var5);
if (isDiagonalValid(var1, var10, var11, var13))
var0[var2++] = var13;
Node var14 = findAcceptedNode(var1.x - 1, var1.y, var1.z + 1, var3, var6, Direction.SOUTH, var5);
if (isDiagonalValid(var1, var9, var8, var14))
var0[var2++] = var14;
Node var15 = findAcceptedNode(var1.x + 1, var1.y, var1.z + 1, var3, var6, Direction.SOUTH, var5);
if (isDiagonalValid(var1, var10, var8, var15))
var0[var2++] = var15;
return var2;
}
use of net.minecraft.world.level.pathfinder.Node in project Citizens2 by CitizensDev.
the class PlayerPathfinder method findPath.
private Path findPath(ProfilerFiller var0, Node var1, Map<Target, BlockPos> var2, float var3, int var4, float var5) {
var0.push("find_path");
var0.markForCharting(MetricCategory.PATH_FINDING);
Set<Target> var6 = var2.keySet();
var1.g = 0.0F;
var1.h = getBestH(var1, var6);
var1.f = var1.h;
this.openSet.clear();
this.openSet.insert(var1);
ImmutableSet immutableSet = ImmutableSet.of();
int var8 = 0;
Set<Target> var9 = Sets.newHashSetWithExpectedSize(var6.size());
int var10 = (int) (this.maxVisitedNodes * var5);
while (!this.openSet.isEmpty() && ++var8 < var10) {
Node node = this.openSet.pop();
node.closed = true;
for (Target target : var6) {
if (node.distanceManhattan(target) <= var4) {
target.setReached();
var9.add(target);
}
}
if (!var9.isEmpty())
break;
if (node.distanceTo(var1) >= var3)
continue;
int i = this.nodeEvaluator.getNeighbors(this.neighbors, node);
for (int var13 = 0; var13 < i; var13++) {
Node var14 = this.neighbors[var13];
float var15 = node.distanceTo(var14);
node.walkedDistance += var15;
float var16 = node.g + var15 + var14.costMalus;
if (var14.walkedDistance < var3 && (!var14.inOpenSet() || var16 < var14.g)) {
var14.cameFrom = node;
var14.g = var16;
var14.h = getBestH(var14, var6) * 1.5F;
if (var14.inOpenSet()) {
this.openSet.changeCost(var14, var14.g + var14.h);
} else {
var14.f = var14.g + var14.h;
this.openSet.insert(var14);
}
}
}
}
Optional<Path> var11 = !var9.isEmpty() ? var9.stream().map(p -> reconstructPath(p.getBestNode(), var2.get(p), true)).min(Comparator.comparingInt(Path::getNodeCount)) : getFallbackDestinations(var2, var6).findFirst();
var0.pop();
if (!var11.isPresent())
return null;
Path var12 = var11.get();
return var12;
}
use of net.minecraft.world.level.pathfinder.Node in project Citizens2 by CitizensDev.
the class PlayerPathfinder method findPath.
public Path findPath(PathNavigationRegion var0, EntityHumanNPC var1, Set<BlockPos> var2, float var3, int var4, float var5) {
this.openSet.clear();
this.nodeEvaluator.prepare(var0, var1);
Node var6 = this.nodeEvaluator.getStart();
Map<Target, BlockPos> var7 = var2.stream().collect(Collectors.toMap(p -> this.nodeEvaluator.getGoal(p.getX(), p.getY(), p.getZ()), Function.identity()));
Path var8 = findPath(var0.getProfiler(), var6, var7, var3, var4, var5);
this.nodeEvaluator.done();
return var8;
}
use of net.minecraft.world.level.pathfinder.Node in project Citizens2 by CitizensDev.
the class PlayerPathfinder method reconstructPath.
private Path reconstructPath(Node var0, BlockPos var1, boolean var2) {
List<Node> var3 = Lists.newArrayList();
Node var4 = var0;
var3.add(0, var4);
while (var4.cameFrom != null) {
var4 = var4.cameFrom;
var3.add(0, var4);
}
return new Path(var3, var1, var2);
}
use of net.minecraft.world.level.pathfinder.Node in project Citizens2 by CitizensDev.
the class PlayerNavigation method supertrimPath.
protected void supertrimPath() {
if (this.path == null)
return;
for (int var0 = 0; var0 < this.path.getNodeCount(); var0++) {
Node var1 = this.path.getNode(var0);
Node var2 = (var0 + 1 < this.path.getNodeCount()) ? this.path.getNode(var0 + 1) : null;
BlockState var3 = this.level.getBlockState(new BlockPos(var1.x, var1.y, var1.z));
if (var3.is(BlockTags.CAULDRONS)) {
this.path.replaceNode(var0, var1.cloneAndMove(var1.x, var1.y + 1, var1.z));
if (var2 != null && var1.y >= var2.y)
this.path.replaceNode(var0 + 1, var1.cloneAndMove(var2.x, var1.y + 1, var2.z));
}
}
}
Aggregations