Search in sources :

Example 31 with BetterBlockPos

use of baritone.api.utils.BetterBlockPos in project Spark-Client by Spark-Client-Development.

the class BuilderProcess method searchForPlaceables.

private Optional<Placement> searchForPlaceables(BuilderCalculationContext bcc, List<IBlockState> desirableOnHotbar) {
    BetterBlockPos center = ctx.playerFeet();
    for (int dx = -5; dx <= 5; dx++) {
        for (int dy = -5; dy <= 1; dy++) {
            for (int dz = -5; dz <= 5; dz++) {
                int x = center.x + dx;
                int y = center.y + dy;
                int z = center.z + dz;
                IBlockState desired = bcc.getSchematic(x, y, z, bcc.bsi.get0(x, y, z));
                if (desired == null) {
                    // irrelevant
                    continue;
                }
                IBlockState curr = bcc.bsi.get0(x, y, z);
                if (MovementHelper.isReplaceable(x, y, z, curr, bcc.bsi) && !valid(curr, desired, false)) {
                    if (dy == 1 && bcc.bsi.get0(x, y + 1, z).getBlock() == Blocks.AIR) {
                        continue;
                    }
                    desirableOnHotbar.add(desired);
                    Optional<Placement> opt = possibleToPlace(desired, x, y, z, bcc.bsi);
                    if (opt.isPresent()) {
                        return opt;
                    }
                }
            }
        }
    }
    return Optional.empty();
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BetterBlockPos(baritone.api.utils.BetterBlockPos)

Example 32 with BetterBlockPos

use of baritone.api.utils.BetterBlockPos in project Spark-Client by Spark-Client-Development.

the class MovementDiagonal method calculateValidPositions.

@Override
protected Set<BetterBlockPos> calculateValidPositions() {
    BetterBlockPos diagA = new BetterBlockPos(src.x, src.y, dest.z);
    BetterBlockPos diagB = new BetterBlockPos(dest.x, src.y, src.z);
    if (dest.y < src.y) {
        return ImmutableSet.of(src, dest.up(), diagA, diagB, dest, diagA.down(), diagB.down());
    }
    if (dest.y > src.y) {
        return ImmutableSet.of(src, src.up(), diagA, diagB, dest, diagA.up(), diagB.up());
    }
    return ImmutableSet.of(src, dest, diagA, diagB);
}
Also used : BetterBlockPos(baritone.api.utils.BetterBlockPos)

Example 33 with BetterBlockPos

use of baritone.api.utils.BetterBlockPos in project Spark-Client by Spark-Client-Development.

the class MovementDiagonal method safeToCancel.

@Override
protected boolean safeToCancel(MovementState state) {
    // too simple. backfill does not work after cornering with this
    // return MovementHelper.canWalkOn(ctx, ctx.playerFeet().down());
    EntityPlayerSP player = ctx.player();
    double offset = 0.25;
    double x = player.posX;
    double y = player.posY - 1;
    double z = player.posZ;
    // standard
    if (ctx.playerFeet().equals(src)) {
        return true;
    }
    // both corners are walkable
    if (MovementHelper.canWalkOn(ctx, new BlockPos(src.x, src.y - 1, dest.z)) && MovementHelper.canWalkOn(ctx, new BlockPos(dest.x, src.y - 1, src.z))) {
        return true;
    }
    // we are in a likely unwalkable corner, check for a supporting block
    if (ctx.playerFeet().equals(new BetterBlockPos(src.x, src.y, dest.z)) || ctx.playerFeet().equals(new BetterBlockPos(dest.x, src.y, src.z))) {
        return (MovementHelper.canWalkOn(ctx, new BetterBlockPos(x + offset, y, z + offset)) || MovementHelper.canWalkOn(ctx, new BetterBlockPos(x + offset, y, z - offset)) || MovementHelper.canWalkOn(ctx, new BetterBlockPos(x - offset, y, z + offset)) || MovementHelper.canWalkOn(ctx, new BetterBlockPos(x - offset, y, z - offset)));
    }
    return true;
}
Also used : BetterBlockPos(baritone.api.utils.BetterBlockPos) BlockPos(net.minecraft.util.math.BlockPos) BetterBlockPos(baritone.api.utils.BetterBlockPos) EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP)

Example 34 with BetterBlockPos

use of baritone.api.utils.BetterBlockPos in project Spark-Client by Spark-Client-Development.

the class MovementFall method buildPositionsToBreak.

private static BetterBlockPos[] buildPositionsToBreak(BetterBlockPos src, BetterBlockPos dest) {
    BetterBlockPos[] toBreak;
    int diffX = src.getX() - dest.getX();
    int diffZ = src.getZ() - dest.getZ();
    int diffY = src.getY() - dest.getY();
    toBreak = new BetterBlockPos[diffY + 2];
    for (int i = 0; i < toBreak.length; i++) {
        toBreak[i] = new BetterBlockPos(src.getX() - diffX, src.getY() + 1 - i, src.getZ() - diffZ);
    }
    return toBreak;
}
Also used : BetterBlockPos(baritone.api.utils.BetterBlockPos)

Example 35 with BetterBlockPos

use of baritone.api.utils.BetterBlockPos in project Spark-Client by Spark-Client-Development.

the class IPath method sanityCheck.

/**
 * Performs a series of checks to ensure that the assembly of the path went as expected.
 */
default void sanityCheck() {
    List<BetterBlockPos> path = positions();
    List<IMovement> movements = movements();
    if (!getSrc().equals(path.get(0))) {
        throw new IllegalStateException("Start node does not equal first path element");
    }
    if (!getDest().equals(path.get(path.size() - 1))) {
        throw new IllegalStateException("End node does not equal last path element");
    }
    if (path.size() != movements.size() + 1) {
        throw new IllegalStateException("Size of path array is unexpected");
    }
    HashSet<BetterBlockPos> seenSoFar = new HashSet<>();
    for (int i = 0; i < path.size() - 1; i++) {
        BetterBlockPos src = path.get(i);
        BetterBlockPos dest = path.get(i + 1);
        IMovement movement = movements.get(i);
        if (!src.equals(movement.getSrc())) {
            throw new IllegalStateException("Path source is not equal to the movement source");
        }
        if (!dest.equals(movement.getDest())) {
            throw new IllegalStateException("Path destination is not equal to the movement destination");
        }
        if (seenSoFar.contains(src)) {
            throw new IllegalStateException("Path doubles back on itself, making a loop");
        }
        seenSoFar.add(src);
    }
}
Also used : BetterBlockPos(baritone.api.utils.BetterBlockPos) IMovement(baritone.api.pathing.movement.IMovement) HashSet(java.util.HashSet)

Aggregations

BetterBlockPos (baritone.api.utils.BetterBlockPos)57 IBlockState (net.minecraft.block.state.IBlockState)15 Goal (baritone.api.pathing.goals.Goal)14 BlockPos (net.minecraft.util.math.BlockPos)10 CommandInvalidStateException (baritone.api.command.exception.CommandInvalidStateException)9 IWaypoint (baritone.api.cache.IWaypoint)6 GoalBlock (baritone.api.pathing.goals.GoalBlock)6 Waypoint (baritone.api.cache.Waypoint)5 Rotation (baritone.api.utils.Rotation)5 EnumFacing (net.minecraft.util.EnumFacing)5 IBaritone (baritone.api.IBaritone)4 Command (baritone.api.command.Command)4 IArgConsumer (baritone.api.command.argument.IArgConsumer)4 ForBlockOptionalMeta (baritone.api.command.datatypes.ForBlockOptionalMeta)4 RelativeBlockPos (baritone.api.command.datatypes.RelativeBlockPos)4 RelativeGoal (baritone.api.command.datatypes.RelativeGoal)4 CommandException (baritone.api.command.exception.CommandException)4 CommandInvalidTypeException (baritone.api.command.exception.CommandInvalidTypeException)4 IPath (baritone.api.pathing.calc.IPath)4 PathingCommand (baritone.api.process.PathingCommand)4