Search in sources :

Example 16 with Path

use of net.minecraft.pathfinding.Path in project pnc-repressurized by TeamPneumatic.

the class PathfinderDrone method findPath.

@Nullable
private Path findPath(PathPoint pathFrom, PathPoint pathTo, float maxDistance) {
    pathFrom.totalPathDistance = 0.0F;
    pathFrom.distanceToNext = pathFrom.distanceManhattan(pathTo);
    pathFrom.distanceToTarget = pathFrom.distanceToNext;
    this.path.clearPath();
    this.closedSet.clear();
    this.path.addPoint(pathFrom);
    PathPoint pathpoint = pathFrom;
    int i = 0;
    while (!this.path.isPathEmpty()) {
        ++i;
        // if (i >= 200) Remove the pathpoint constraint the super class has.
        // {
        // break;
        // }
        PathPoint pathpoint1 = this.path.dequeue();
        if (pathpoint1.equals(pathTo)) {
            pathpoint = pathTo;
            break;
        }
        if (pathpoint1.distanceManhattan(pathTo) < pathpoint.distanceManhattan(pathTo)) {
            pathpoint = pathpoint1;
        }
        pathpoint1.visited = true;
        int j = this.nodeProcessor.findPathOptions(this.pathOptions, pathpoint1, pathTo, maxDistance);
        for (int k = 0; k < j; ++k) {
            PathPoint pathpoint2 = this.pathOptions[k];
            float f = pathpoint1.distanceManhattan(pathpoint2);
            pathpoint2.distanceFromOrigin = pathpoint1.distanceFromOrigin + f;
            pathpoint2.cost = f + pathpoint2.costMalus;
            float f1 = pathpoint1.totalPathDistance + pathpoint2.cost;
            if (pathpoint2.distanceFromOrigin < maxDistance && (!pathpoint2.isAssigned() || f1 < pathpoint2.totalPathDistance)) {
                pathpoint2.previous = pathpoint1;
                pathpoint2.totalPathDistance = f1;
                pathpoint2.distanceToNext = pathpoint2.distanceManhattan(pathTo) + pathpoint2.costMalus;
                if (pathpoint2.isAssigned()) {
                    this.path.changeDistance(pathpoint2, pathpoint2.totalPathDistance + pathpoint2.distanceToNext);
                } else {
                    pathpoint2.distanceToTarget = pathpoint2.totalPathDistance + pathpoint2.distanceToNext;
                    this.path.addPoint(pathpoint2);
                }
            }
        }
    }
    if (pathpoint == pathFrom) {
        return null;
    } else {
        Path path = this.createPath(pathFrom, pathpoint);
        return path;
    }
}
Also used : Path(net.minecraft.pathfinding.Path) PathPoint(net.minecraft.pathfinding.PathPoint) PathPoint(net.minecraft.pathfinding.PathPoint) Nullable(javax.annotation.Nullable)

Aggregations

Path (net.minecraft.pathfinding.Path)16 PathPoint (net.minecraft.pathfinding.PathPoint)8 Vec3d (net.minecraft.util.math.Vec3d)5 BlockPos (net.minecraft.util.math.BlockPos)4 Nullable (javax.annotation.Nullable)3 NotNull (org.jetbrains.annotations.NotNull)3 PathNavigateGround (net.minecraft.pathfinding.PathNavigateGround)2 Nullable (org.jetbrains.annotations.Nullable)2 EntityAspectedDemonBase (WayofTime.bloodmagic.entity.mob.EntityAspectedDemonBase)1 IBlockState (net.minecraft.block.state.IBlockState)1 EntityLivingBase (net.minecraft.entity.EntityLivingBase)1 EntitySilverfish (net.minecraft.entity.monster.EntitySilverfish)1 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)1 World (net.minecraft.world.World)1 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)1