Search in sources :

Example 1 with SurfaceType

use of com.minecolonies.api.entity.pathfinding.SurfaceType in project minecolonies by Minecolonies.

the class AbstractPathJob method getGroundHeight.

/**
 * Get the height of the ground at the given x,z coordinate, within 1 step of y.
 *
 * @param parent parent node.
 * @param pos    coordinate of block.
 * @return y height of first open, viable block above ground, or -1 if blocked or too far a drop.
 */
protected int getGroundHeight(final Node parent, @NotNull final BlockPos pos) {
    // lower body (headroom drop) or lower body (jump up)
    if (checkHeadBlock(parent, pos)) {
        return handleTargetNotPassable(parent, pos.above(), world.getBlockState(pos.above()));
    }
    // Now check the block we want to move to
    final BlockState target = world.getBlockState(pos);
    if (!isPassable(target, pos, parent)) {
        return handleTargetNotPassable(parent, pos, target);
    }
    // Do we have something to stand on in the target space?
    final BlockState below = world.getBlockState(pos.below());
    final SurfaceType walkability = getSurfaceType(world, below, pos);
    if (walkability == SurfaceType.WALKABLE) {
        // Level path
        return pos.getY();
    } else if (walkability == SurfaceType.NOT_PASSABLE) {
        return -1;
    }
    return handleNotStanding(parent, pos, below);
}
Also used : SurfaceType(com.minecolonies.api.entity.pathfinding.SurfaceType) SurfaceType.getSurfaceType(com.minecolonies.api.entity.pathfinding.SurfaceType.getSurfaceType)

Example 2 with SurfaceType

use of com.minecolonies.api.entity.pathfinding.SurfaceType in project minecolonies by ldtteam.

the class AbstractPathJob method getGroundHeight.

/**
 * Get the height of the ground at the given x,z coordinate, within 1 step of y.
 *
 * @param parent parent node.
 * @param pos    coordinate of block.
 * @return y height of first open, viable block above ground, or -1 if blocked or too far a drop.
 */
protected int getGroundHeight(final Node parent, @NotNull final BlockPos pos) {
    // lower body (headroom drop) or lower body (jump up)
    if (checkHeadBlock(parent, pos)) {
        return handleTargetNotPassable(parent, pos.above(), world.getBlockState(pos.above()));
    }
    // Now check the block we want to move to
    final BlockState target = world.getBlockState(pos);
    if (!isPassable(target, pos, parent)) {
        return handleTargetNotPassable(parent, pos, target);
    }
    // Do we have something to stand on in the target space?
    final BlockState below = world.getBlockState(pos.below());
    final SurfaceType walkability = getSurfaceType(world, below, pos);
    if (walkability == SurfaceType.WALKABLE) {
        // Level path
        return pos.getY();
    } else if (walkability == SurfaceType.NOT_PASSABLE) {
        return -1;
    }
    return handleNotStanding(parent, pos, below);
}
Also used : SurfaceType(com.minecolonies.api.entity.pathfinding.SurfaceType) SurfaceType.getSurfaceType(com.minecolonies.api.entity.pathfinding.SurfaceType.getSurfaceType)

Aggregations

SurfaceType (com.minecolonies.api.entity.pathfinding.SurfaceType)2 SurfaceType.getSurfaceType (com.minecolonies.api.entity.pathfinding.SurfaceType.getSurfaceType)2