Search in sources :

Example 1 with PathPoint

use of net.minecraft.pathfinding.PathPoint in project NetherEx by LogicTechCorp.

the class EntityAIFenceGateInteract method shouldExecute.

@Override
public boolean shouldExecute() {
    if (!theEntity.isCollidedHorizontally) {
        return false;
    } else {
        PathNavigateGround pathnavigateground = (PathNavigateGround) theEntity.getNavigator();
        Path path = pathnavigateground.getPath();
        if (path != null && !path.isFinished() && pathnavigateground.getEnterDoors()) {
            for (int i = 0; i < Math.min(path.getCurrentPathIndex() + 2, path.getCurrentPathLength()); ++i) {
                PathPoint pathpoint = path.getPathPointFromIndex(i);
                fenceGatePos = new BlockPos(pathpoint.xCoord, pathpoint.yCoord, pathpoint.zCoord);
                if (theEntity.getDistanceSq((double) fenceGatePos.getX(), theEntity.posY, (double) fenceGatePos.getZ()) <= 2.25D) {
                    fenceGate = getFenceGate(fenceGatePos);
                    if (fenceGate != null) {
                        return true;
                    }
                }
            }
            fenceGatePos = (new BlockPos(theEntity));
            fenceGate = getFenceGate(fenceGatePos);
            return fenceGate != null;
        } else {
            return false;
        }
    }
}
Also used : Path(net.minecraft.pathfinding.Path) PathPoint(net.minecraft.pathfinding.PathPoint) BlockPos(net.minecraft.util.math.BlockPos) PathPoint(net.minecraft.pathfinding.PathPoint) PathNavigateGround(net.minecraft.pathfinding.PathNavigateGround)

Example 2 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 blockpos$mutableblockpos = new BlockPos.MutableBlockPos(MathHelper.floor(this.entity.posX), i, MathHelper.floor(this.entity.posZ));
        for (Block block = this.blockaccess.getBlockState(blockpos$mutableblockpos).getBlock(); block == Blocks.FLOWING_WATER || block == Blocks.WATER || block instanceof BlockFluidBase; block = this.blockaccess.getBlockState(blockpos$mutableblockpos).getBlock()) {
            ++i;
            blockpos$mutableblockpos.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 blockpos;
        for (blockpos = new BlockPos(this.entity); (this.blockaccess.getBlockState(blockpos).getMaterial() == Material.AIR || this.blockaccess.getBlockState(blockpos).getBlock().isPassable(this.blockaccess, blockpos)) && blockpos.getY() > 0; blockpos = blockpos.down()) {
        }
        i = blockpos.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 pathnodetype = this.getPathNodeType(this.entity, blockpos1);
            if (this.entity.getPathPriority(pathnodetype) >= 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 3 with PathPoint

use of net.minecraft.pathfinding.PathPoint in project minecolonies by Minecolonies.

the class EntityAIGateInteract method checkFenceGate.

/**
 * Checks if the citizen is close enough to an existing fence gate.
 *
 * @param path the path through the fence.
 * @return true if the gate can be passed
 */
private boolean checkFenceGate(@NotNull final Path path) {
    final int maxLengthToCheck = Math.min(path.getCurrentPathIndex() + LENGTH_TO_CHECK, path.getCurrentPathLength());
    for (int i = 0; i < maxLengthToCheck; ++i) {
        final PathPoint pathpoint = path.getPathPointFromIndex(i);
        for (int level = 0; level < HEIGHT_TO_CHECK; level++) {
            this.gatePosition = new BlockPos(pathpoint.x, pathpoint.y + level, pathpoint.z);
            if (this.theEntity.getDistanceSq((double) this.gatePosition.getX(), this.theEntity.posY, (double) this.gatePosition.getZ()) <= MIN_DISTANCE) {
                this.gateBlock = this.getBlockFence(this.gatePosition);
                if (this.gateBlock != null) {
                    return true;
                }
            }
        }
    }
    this.gatePosition = (new BlockPos(this.theEntity)).up();
    this.gateBlock = this.getBlockFence(this.gatePosition);
    return this.gateBlock != null;
}
Also used : PathPoint(net.minecraft.pathfinding.PathPoint) BlockPos(net.minecraft.util.math.BlockPos) PathPoint(net.minecraft.pathfinding.PathPoint)

Example 4 with PathPoint

use of net.minecraft.pathfinding.PathPoint in project minecolonies by Minecolonies.

the class AbstractPathJob method finalizePath.

/**
 * Generate the path to the target node.
 *
 * @param targetNode the node to path to.
 * @return the path.
 */
@NotNull
private Path finalizePath(final Node targetNode) {
    // Compute length of path, since we need to allocate an array.  This is cheaper/faster than building a List
    // and converting it.  Yes, we have targetNode.steps, but I do not want to rely on that being accurate (I might
    // fudge that value later on for cutoff purposes
    int pathLength = 0;
    @Nullable Node node = targetNode;
    while (node.parent != null) {
        ++pathLength;
        node = node.parent;
    }
    @NotNull final PathPoint[] points = new PathPoint[pathLength];
    @Nullable Node nextInPath = null;
    node = targetNode;
    while (node.parent != null) {
        if (debugDrawEnabled) {
            addPathNodeToDebug(node);
        }
        --pathLength;
        @NotNull final BlockPos pos = node.pos;
        if (node.isSwimming()) {
            // Not truly necessary but helps prevent them spinning in place at swimming nodes
            pos.add(BLOCKPOS_DOWN);
        }
        @NotNull final PathPointExtended p = new PathPointExtended(pos);
        // Climbing on a ladder?
        if (nextInPath != null && onALadder(node, nextInPath, pos)) {
            p.setOnLadder(true);
            if (nextInPath.pos.getY() > pos.getY()) {
                // We only care about facing if going up
                // In the case of BlockVines (Which does not have EnumFacing) we have to check the metadata of the vines... bitwise...
                setLadderFacing(world, pos, p);
            }
        } else if (onALadder(node.parent, node.parent, pos)) {
            p.setOnLadder(true);
        }
        points[pathLength] = p;
        nextInPath = node;
        node = node.parent;
    }
    doDebugPrinting(points);
    return new Path(points);
}
Also used : Path(net.minecraft.pathfinding.Path) PathPoint(net.minecraft.pathfinding.PathPoint) BlockPos(net.minecraft.util.math.BlockPos) NotNull(org.jetbrains.annotations.NotNull) PathPoint(net.minecraft.pathfinding.PathPoint) Nullable(org.jetbrains.annotations.Nullable) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with PathPoint

use of net.minecraft.pathfinding.PathPoint in project minecolonies by Minecolonies.

the class AbstractPathJob method doDebugPrinting.

/**
 * Turns on debug printing.
 *
 * @param points the points to print.
 */
private void doDebugPrinting(@NotNull final PathPoint[] points) {
    if (Configurations.pathfinding.pathfindingDebugVerbosity > DEBUG_VERBOSITY_NONE) {
        Log.getLogger().info("Path found:");
        for (@NotNull final PathPoint p : points) {
            Log.getLogger().info(String.format("Step: [%d,%d,%d]", p.x, p.y, p.z));
        }
        Log.getLogger().info(String.format("Total Nodes Visited %d / %d", totalNodesVisited, totalNodesAdded));
    }
}
Also used : PathPoint(net.minecraft.pathfinding.PathPoint) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

PathPoint (net.minecraft.pathfinding.PathPoint)18 Path (net.minecraft.pathfinding.Path)8 BlockPos (net.minecraft.util.math.BlockPos)6 Nullable (javax.annotation.Nullable)3 PathEntity (net.minecraft.pathfinding.PathEntity)3 Block (net.minecraft.block.Block)2 World (net.minecraft.world.World)2 NotNull (org.jetbrains.annotations.NotNull)2 SideOnly (cpw.mods.fml.relauncher.SideOnly)1 HashSet (java.util.HashSet)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 PathNodeType (net.minecraft.pathfinding.PathNodeType)1 Vec3 (net.minecraft.util.Vec3)1 Vec3d (net.minecraft.util.math.Vec3d)1 ChunkCache (net.minecraft.world.ChunkCache)1 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)1