Search in sources :

Example 1 with Target

use of net.minecraft.world.level.pathfinder.Target 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;
}
Also used : Path(net.minecraft.world.level.pathfinder.Path) Target(net.minecraft.world.level.pathfinder.Target) ImmutableSet(com.google.common.collect.ImmutableSet) Node(net.minecraft.world.level.pathfinder.Node)

Example 2 with Target

use of net.minecraft.world.level.pathfinder.Target 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;
}
Also used : EntityHumanNPC(net.citizensnpcs.nms.v1_18_R2.entity.EntityHumanNPC) Path(net.minecraft.world.level.pathfinder.Path) ProfilerFiller(net.minecraft.util.profiling.ProfilerFiller) Set(java.util.Set) Setting(net.citizensnpcs.Settings.Setting) BinaryHeap(net.minecraft.world.level.pathfinder.BinaryHeap) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) List(java.util.List) Stream(java.util.stream.Stream) Lists(com.google.common.collect.Lists) BlockPos(net.minecraft.core.BlockPos) Target(net.minecraft.world.level.pathfinder.Target) Map(java.util.Map) MetricCategory(net.minecraft.util.profiling.metrics.MetricCategory) PathFinder(net.minecraft.world.level.pathfinder.PathFinder) Optional(java.util.Optional) Comparator(java.util.Comparator) Mob(net.minecraft.world.entity.Mob) PathNavigationRegion(net.minecraft.world.level.PathNavigationRegion) Node(net.minecraft.world.level.pathfinder.Node) Path(net.minecraft.world.level.pathfinder.Path) Target(net.minecraft.world.level.pathfinder.Target) Node(net.minecraft.world.level.pathfinder.Node) BlockPos(net.minecraft.core.BlockPos)

Example 3 with Target

use of net.minecraft.world.level.pathfinder.Target in project Citizens2 by CitizensDev.

the class PlayerPathfinder method findPath.

@Override
public Path findPath(PathNavigationRegion var0, Mob 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;
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Path(net.minecraft.world.level.pathfinder.Path) ProfilerFiller(net.minecraft.util.profiling.ProfilerFiller) Set(java.util.Set) Setting(net.citizensnpcs.Settings.Setting) BinaryHeap(net.minecraft.world.level.pathfinder.BinaryHeap) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) List(java.util.List) Stream(java.util.stream.Stream) Lists(com.google.common.collect.Lists) EntityHumanNPC(net.citizensnpcs.nms.v1_17_R1.entity.EntityHumanNPC) BlockPos(net.minecraft.core.BlockPos) Target(net.minecraft.world.level.pathfinder.Target) Map(java.util.Map) MetricCategory(net.minecraft.util.profiling.metrics.MetricCategory) PathFinder(net.minecraft.world.level.pathfinder.PathFinder) Optional(java.util.Optional) Comparator(java.util.Comparator) Mob(net.minecraft.world.entity.Mob) PathNavigationRegion(net.minecraft.world.level.PathNavigationRegion) Node(net.minecraft.world.level.pathfinder.Node) Path(net.minecraft.world.level.pathfinder.Path) Target(net.minecraft.world.level.pathfinder.Target) Node(net.minecraft.world.level.pathfinder.Node) BlockPos(net.minecraft.core.BlockPos)

Example 4 with Target

use of net.minecraft.world.level.pathfinder.Target 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;
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Path(net.minecraft.world.level.pathfinder.Path) ProfilerFiller(net.minecraft.util.profiling.ProfilerFiller) Set(java.util.Set) Setting(net.citizensnpcs.Settings.Setting) BinaryHeap(net.minecraft.world.level.pathfinder.BinaryHeap) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) List(java.util.List) Stream(java.util.stream.Stream) Lists(com.google.common.collect.Lists) EntityHumanNPC(net.citizensnpcs.nms.v1_17_R1.entity.EntityHumanNPC) BlockPos(net.minecraft.core.BlockPos) Target(net.minecraft.world.level.pathfinder.Target) Map(java.util.Map) MetricCategory(net.minecraft.util.profiling.metrics.MetricCategory) PathFinder(net.minecraft.world.level.pathfinder.PathFinder) Optional(java.util.Optional) Comparator(java.util.Comparator) Mob(net.minecraft.world.entity.Mob) PathNavigationRegion(net.minecraft.world.level.PathNavigationRegion) Node(net.minecraft.world.level.pathfinder.Node) Path(net.minecraft.world.level.pathfinder.Path) Target(net.minecraft.world.level.pathfinder.Target) Node(net.minecraft.world.level.pathfinder.Node) BlockPos(net.minecraft.core.BlockPos)

Example 5 with Target

use of net.minecraft.world.level.pathfinder.Target in project Citizens2 by CitizensDev.

the class PlayerPathfinder method getBestH.

private float getBestH(Node var0, Set<Target> var1) {
    float var2 = Float.MAX_VALUE;
    for (Target var4 : var1) {
        float var5 = var0.distanceTo(var4);
        var4.updateBest(var5, var0);
        var2 = Math.min(var5, var2);
    }
    return var2;
}
Also used : Target(net.minecraft.world.level.pathfinder.Target)

Aggregations

Target (net.minecraft.world.level.pathfinder.Target)8 Node (net.minecraft.world.level.pathfinder.Node)6 Path (net.minecraft.world.level.pathfinder.Path)6 Lists (com.google.common.collect.Lists)4 Sets (com.google.common.collect.Sets)4 Comparator (java.util.Comparator)4 List (java.util.List)4 Map (java.util.Map)4 Optional (java.util.Optional)4 Set (java.util.Set)4 Function (java.util.function.Function)4 Collectors (java.util.stream.Collectors)4 Stream (java.util.stream.Stream)4 Setting (net.citizensnpcs.Settings.Setting)4 BlockPos (net.minecraft.core.BlockPos)4 ProfilerFiller (net.minecraft.util.profiling.ProfilerFiller)4 MetricCategory (net.minecraft.util.profiling.metrics.MetricCategory)4 Mob (net.minecraft.world.entity.Mob)4 PathNavigationRegion (net.minecraft.world.level.PathNavigationRegion)4 BinaryHeap (net.minecraft.world.level.pathfinder.BinaryHeap)4