Search in sources :

Example 16 with PathPoint

use of net.minecraft.pathfinding.PathPoint in project Galacticraft by micdoodle8.

the class WalkNodeProcessorCeiling method findPathOptions.

@Override
public int findPathOptions(PathPoint[] pathOptions, PathPoint currentPoint, PathPoint targetPoint, float maxDistance) {
    int i = 0;
    int j = 0;
    PathNodeType pathnodetype = this.getPathNodeType(this.entity, currentPoint.x, currentPoint.y + 1, currentPoint.z);
    if (this.entity.getPathPriority(pathnodetype) >= 0.0F) {
        j = MathHelper.floor(Math.max(1.0F, this.entity.stepHeight));
    }
    BlockPos blockpos = (new BlockPos(currentPoint.x, currentPoint.y, currentPoint.z)).down();
    double d0 = (double) currentPoint.y - (1.0D - this.blockaccess.getBlockState(blockpos).getBoundingBox(this.blockaccess, blockpos).maxY);
    PathPoint pathpoint = this.getSafePoint(currentPoint.x, currentPoint.y, currentPoint.z + 1, j, d0, EnumFacing.SOUTH);
    PathPoint pathpoint1 = this.getSafePoint(currentPoint.x - 1, currentPoint.y, currentPoint.z, j, d0, EnumFacing.WEST);
    PathPoint pathpoint2 = this.getSafePoint(currentPoint.x + 1, currentPoint.y, currentPoint.z, j, d0, EnumFacing.EAST);
    PathPoint pathpoint3 = this.getSafePoint(currentPoint.x, currentPoint.y, currentPoint.z - 1, j, d0, EnumFacing.NORTH);
    if (pathpoint != null && !pathpoint.visited && pathpoint.distanceTo(targetPoint) < maxDistance) {
        pathOptions[i++] = pathpoint;
    }
    if (pathpoint1 != null && !pathpoint1.visited && pathpoint1.distanceTo(targetPoint) < maxDistance) {
        pathOptions[i++] = pathpoint1;
    }
    if (pathpoint2 != null && !pathpoint2.visited && pathpoint2.distanceTo(targetPoint) < maxDistance) {
        pathOptions[i++] = pathpoint2;
    }
    if (pathpoint3 != null && !pathpoint3.visited && pathpoint3.distanceTo(targetPoint) < maxDistance) {
        pathOptions[i++] = pathpoint3;
    }
    boolean flag = pathpoint3 == null || pathpoint3.nodeType == PathNodeType.OPEN || pathpoint3.costMalus != 0.0F;
    boolean flag1 = pathpoint == null || pathpoint.nodeType == PathNodeType.OPEN || pathpoint.costMalus != 0.0F;
    boolean flag2 = pathpoint2 == null || pathpoint2.nodeType == PathNodeType.OPEN || pathpoint2.costMalus != 0.0F;
    boolean flag3 = pathpoint1 == null || pathpoint1.nodeType == PathNodeType.OPEN || pathpoint1.costMalus != 0.0F;
    if (flag && flag3) {
        PathPoint pathpoint4 = this.getSafePoint(currentPoint.x - 1, currentPoint.y, currentPoint.z - 1, j, d0, EnumFacing.NORTH);
        if (pathpoint4 != null && !pathpoint4.visited && pathpoint4.distanceTo(targetPoint) < maxDistance) {
            pathOptions[i++] = pathpoint4;
        }
    }
    if (flag && flag2) {
        PathPoint pathpoint5 = this.getSafePoint(currentPoint.x + 1, currentPoint.y, currentPoint.z - 1, j, d0, EnumFacing.NORTH);
        if (pathpoint5 != null && !pathpoint5.visited && pathpoint5.distanceTo(targetPoint) < maxDistance) {
            pathOptions[i++] = pathpoint5;
        }
    }
    if (flag1 && flag3) {
        PathPoint pathpoint6 = this.getSafePoint(currentPoint.x - 1, currentPoint.y, currentPoint.z + 1, j, d0, EnumFacing.SOUTH);
        if (pathpoint6 != null && !pathpoint6.visited && pathpoint6.distanceTo(targetPoint) < maxDistance) {
            pathOptions[i++] = pathpoint6;
        }
    }
    if (flag1 && flag2) {
        PathPoint pathpoint7 = this.getSafePoint(currentPoint.x + 1, currentPoint.y, currentPoint.z + 1, j, d0, EnumFacing.SOUTH);
        if (pathpoint7 != null && !pathpoint7.visited && pathpoint7.distanceTo(targetPoint) < maxDistance) {
            pathOptions[i++] = pathpoint7;
        }
    }
    return i;
}
Also used : PathPoint(net.minecraft.pathfinding.PathPoint) PathNodeType(net.minecraft.pathfinding.PathNodeType) BlockPos(net.minecraft.util.math.BlockPos) PathPoint(net.minecraft.pathfinding.PathPoint)

Example 17 with PathPoint

use of net.minecraft.pathfinding.PathPoint in project Galacticraft by micdoodle8.

the class WalkNodeProcessorCeiling method getSafePoint.

@Nullable
private PathPoint getSafePoint(int x, int y, int z, int p_186332_4_, double p_186332_5_, EnumFacing facing) {
    PathPoint pathpoint = null;
    BlockPos blockpos = new BlockPos(x, y, z);
    BlockPos blockpos1 = blockpos.down();
    double d0 = (double) y - (1.0D - this.blockaccess.getBlockState(blockpos1).getBoundingBox(this.blockaccess, blockpos1).maxY);
    if (d0 - p_186332_5_ > 1.125D) {
        return null;
    } else {
        PathNodeType pathnodetype = this.getPathNodeType(this.entity, x, y, z);
        float f = this.entity.getPathPriority(pathnodetype);
        double d1 = (double) this.entity.width / 2.0D;
        if (f >= 0.0F) {
            pathpoint = this.openPoint(x, y, z);
            pathpoint.nodeType = pathnodetype;
            pathpoint.costMalus = Math.max(pathpoint.costMalus, f);
        }
        if (pathnodetype == PathNodeType.WALKABLE) {
            return pathpoint;
        } else {
            if (pathpoint == null && p_186332_4_ > 0 && pathnodetype != PathNodeType.FENCE && pathnodetype != PathNodeType.TRAPDOOR) {
                pathpoint = this.getSafePoint(x, y + 1, z, p_186332_4_ - 1, p_186332_5_, facing);
                if (pathpoint != null && (pathpoint.nodeType == PathNodeType.OPEN || pathpoint.nodeType == PathNodeType.WALKABLE) && this.entity.width < 1.0F) {
                    double d2 = (double) (x - facing.getFrontOffsetX()) + 0.5D;
                    double d3 = (double) (z - facing.getFrontOffsetZ()) + 0.5D;
                    AxisAlignedBB axisalignedbb = new AxisAlignedBB(d2 - d1, (double) y + 0.001D, d3 - d1, d2 + d1, (double) ((float) y + this.entity.height), d3 + d1);
                    AxisAlignedBB axisalignedbb1 = this.blockaccess.getBlockState(blockpos).getBoundingBox(this.blockaccess, blockpos);
                    AxisAlignedBB axisalignedbb2 = axisalignedbb.expand(0.0D, axisalignedbb1.maxY - 0.002D, 0.0D);
                    if (this.entity.world.collidesWithAnyBlock(axisalignedbb2)) {
                        pathpoint = null;
                    }
                }
            }
            if (pathnodetype == PathNodeType.OPEN) {
                AxisAlignedBB axisalignedbb3 = new AxisAlignedBB((double) x - d1 + 0.5D, (double) y + 0.001D, (double) z - d1 + 0.5D, (double) x + d1 + 0.5D, (double) ((float) y + this.entity.height), (double) z + d1 + 0.5D);
                if (this.entity.world.collidesWithAnyBlock(axisalignedbb3)) {
                    return null;
                }
                if (this.entity.width >= 1.0F) {
                    PathNodeType pathnodetype1 = this.getPathNodeType(this.entity, x, y - 1, z);
                    if (pathnodetype1 == PathNodeType.BLOCKED) {
                        pathpoint = this.openPoint(x, y, z);
                        pathpoint.nodeType = PathNodeType.WALKABLE;
                        pathpoint.costMalus = Math.max(pathpoint.costMalus, f);
                        return pathpoint;
                    }
                }
                int i = 0;
                while (y > 0 && pathnodetype == PathNodeType.OPEN) {
                    --y;
                    if (i++ >= this.entity.getMaxFallHeight()) {
                        return null;
                    }
                    pathnodetype = this.getPathNodeType(this.entity, x, y, z);
                    f = this.entity.getPathPriority(pathnodetype);
                    if (pathnodetype != PathNodeType.OPEN && f >= 0.0F) {
                        pathpoint = this.openPoint(x, y, z);
                        pathpoint.nodeType = pathnodetype;
                        pathpoint.costMalus = Math.max(pathpoint.costMalus, f);
                        break;
                    }
                    if (f < 0.0F) {
                        return null;
                    }
                }
            }
            return pathpoint;
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) PathPoint(net.minecraft.pathfinding.PathPoint) BlockPos(net.minecraft.util.math.BlockPos) PathNodeType(net.minecraft.pathfinding.PathNodeType) PathPoint(net.minecraft.pathfinding.PathPoint) Nullable(javax.annotation.Nullable)

Example 18 with PathPoint

use of net.minecraft.pathfinding.PathPoint in project MorePlanets by SteveKunG.

the class WalkNodeProcessorMP method getStart.

@Override
public PathPoint getStart() {
    int i;
    if (this.getCanSwim() && this.entity.isInWater()) {
        i = (int) this.entity.getEntityBoundingBox().minY;
        BlockPos.MutableBlockPos mutablePos = new BlockPos.MutableBlockPos(MathHelper.floor(this.entity.posX), i, MathHelper.floor(this.entity.posZ));
        for (Block block = this.blockaccess.getBlockState(mutablePos).getBlock(); block == Blocks.FLOWING_WATER || block == Blocks.WATER || block instanceof BlockFluidBase; block = this.blockaccess.getBlockState(mutablePos).getBlock()) {
            ++i;
            mutablePos.setPos(MathHelper.floor(this.entity.posX), i, MathHelper.floor(this.entity.posZ));
        }
    } else if (this.entity.onGround) {
        i = MathHelper.floor(this.entity.getEntityBoundingBox().minY + 0.5D);
    } else {
        BlockPos pos;
        for (pos = new BlockPos(this.entity); (this.blockaccess.getBlockState(pos).getMaterial() == Material.AIR || this.blockaccess.getBlockState(pos).getBlock().isPassable(this.blockaccess, pos)) && pos.getY() > 0; pos = pos.down()) {
        }
        i = pos.up().getY();
    }
    BlockPos blockpos2 = new BlockPos(this.entity);
    PathNodeType pathnodetype1 = this.getPathNodeType(this.entity, blockpos2.getX(), i, blockpos2.getZ());
    if (this.entity.getPathPriority(pathnodetype1) < 0.0F) {
        Set<BlockPos> set = new HashSet<>();
        set.add(new BlockPos(this.entity.getEntityBoundingBox().minX, i, this.entity.getEntityBoundingBox().minZ));
        set.add(new BlockPos(this.entity.getEntityBoundingBox().minX, i, this.entity.getEntityBoundingBox().maxZ));
        set.add(new BlockPos(this.entity.getEntityBoundingBox().maxX, i, this.entity.getEntityBoundingBox().minZ));
        set.add(new BlockPos(this.entity.getEntityBoundingBox().maxX, i, this.entity.getEntityBoundingBox().maxZ));
        for (BlockPos blockpos1 : set) {
            PathNodeType type = this.getPathNodeType(this.entity, blockpos1);
            if (this.entity.getPathPriority(type) >= 0.0F) {
                return this.openPoint(blockpos1.getX(), blockpos1.getY(), blockpos1.getZ());
            }
        }
    }
    return this.openPoint(blockpos2.getX(), i, blockpos2.getZ());
}
Also used : BlockFluidBase(net.minecraftforge.fluids.BlockFluidBase) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) PathNodeType(net.minecraft.pathfinding.PathNodeType) PathPoint(net.minecraft.pathfinding.PathPoint) HashSet(java.util.HashSet)

Example 19 with PathPoint

use of net.minecraft.pathfinding.PathPoint 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)

Example 20 with PathPoint

use of net.minecraft.pathfinding.PathPoint in project PneumaticCraft by MineMaarten.

the class RenderNavigator method render.

public void render(boolean wirePath, boolean xRayEnabled, float partialTicks) {
    if (path == null)
        return;
    GL11.glDepthMask(false);
    if (xRayEnabled)
        GL11.glDisable(GL11.GL_DEPTH_TEST);
    GL11.glDisable(GL11.GL_CULL_FACE);
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glDisable(GL11.GL_TEXTURE_2D);
    GL11.glLineWidth(5.0F);
    boolean noDestinationPath = !tracedToDestination();
    Tessellator tess = Tessellator.instance;
    GL11.glPushMatrix();
    GL11.glTranslated(0, 0.01D, 0);
    // Draws just wires
    if (wirePath) {
        if (noDestinationPath) {
            GL11.glEnable(GL11.GL_LINE_STIPPLE);
            GL11.glLineStipple(4, (short) 0x00FF);
        }
        for (int i = 1; i < path.getCurrentPathLength(); i++) {
            double red = 1;
            if (path.getCurrentPathLength() - i < 200) {
                red = (path.getCurrentPathLength() - i) * 0.005D;
            }
            GL11.glColor4d(red, 1 - red, 0, 0.5D);
            PathPoint lastPoint = path.getPathPointFromIndex(i - 1);
            PathPoint pathPoint = path.getPathPointFromIndex(i);
            tess.startDrawing(GL11.GL_LINE_STRIP);
            tess.addVertex(lastPoint.xCoord + 0.5D, lastPoint.yCoord, lastPoint.zCoord + 0.5D);
            tess.addVertex((lastPoint.xCoord + pathPoint.xCoord) / 2D + 0.5D, Math.max(lastPoint.yCoord, pathPoint.yCoord), (lastPoint.zCoord + pathPoint.zCoord) / 2D + 0.5D);
            tess.addVertex(pathPoint.xCoord + 0.5D, pathPoint.yCoord, pathPoint.zCoord + 0.5D);
            tess.draw();
        }
    } else {
        if (noDestinationPath) {
            if (increaseAlpha) {
                alphaValue += 0.005D;
                if (alphaValue > 0.3D)
                    increaseAlpha = false;
            } else {
                alphaValue -= 0.005D;
                if (alphaValue < 0.2D)
                    increaseAlpha = true;
            }
        } else {
            if (alphaValue > 0.2D)
                alphaValue -= 0.005D;
        }
        for (int i = 0; i < path.getCurrentPathLength(); i++) {
            double red = 1;
            if (path.getCurrentPathLength() - i < 200) {
                red = (path.getCurrentPathLength() - i) * 0.005D;
            }
            GL11.glColor4d(red, 1 - red, 0, alphaValue);
            PathPoint pathPoint = path.getPathPointFromIndex(i);
            tess.startDrawingQuads();
            tess.addVertex(pathPoint.xCoord, pathPoint.yCoord, pathPoint.zCoord);
            tess.addVertex(pathPoint.xCoord, pathPoint.yCoord, pathPoint.zCoord + 1);
            tess.addVertex(pathPoint.xCoord + 1, pathPoint.yCoord, pathPoint.zCoord + 1);
            tess.addVertex(pathPoint.xCoord + 1, pathPoint.yCoord, pathPoint.zCoord);
            tess.draw();
        }
    }
    GL11.glPopMatrix();
    GL11.glEnable(GL11.GL_CULL_FACE);
    GL11.glEnable(GL11.GL_DEPTH_TEST);
    GL11.glDisable(GL11.GL_BLEND);
    GL11.glDisable(GL11.GL_LINE_STIPPLE);
    GL11.glDepthMask(true);
    GL11.glEnable(GL11.GL_TEXTURE_2D);
}
Also used : PathPoint(net.minecraft.pathfinding.PathPoint) Tessellator(net.minecraft.client.renderer.Tessellator) PathPoint(net.minecraft.pathfinding.PathPoint)

Aggregations

PathPoint (net.minecraft.pathfinding.PathPoint)22 BlockPos (net.minecraft.util.math.BlockPos)10 Path (net.minecraft.pathfinding.Path)8 PathNodeType (net.minecraft.pathfinding.PathNodeType)5 Nullable (javax.annotation.Nullable)4 Block (net.minecraft.block.Block)3 PathEntity (net.minecraft.pathfinding.PathEntity)3 HashSet (java.util.HashSet)2 World (net.minecraft.world.World)2 BlockFluidBase (net.minecraftforge.fluids.BlockFluidBase)2 NotNull (org.jetbrains.annotations.NotNull)2 SideOnly (cpw.mods.fml.relauncher.SideOnly)1 IBlockState (net.minecraft.block.state.IBlockState)1 BufferBuilder (net.minecraft.client.renderer.BufferBuilder)1 Tessellator (net.minecraft.client.renderer.Tessellator)1 PathFinderDrone (net.minecraft.pathfinding.PathFinderDrone)1 PathNavigateGround (net.minecraft.pathfinding.PathNavigateGround)1 Vec3 (net.minecraft.util.Vec3)1 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)1 Vec3d (net.minecraft.util.math.Vec3d)1