Search in sources :

Example 1 with BetterBlockPos

use of baritone.api.utils.BetterBlockPos in project baritone by cabaletta.

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)

Example 2 with BetterBlockPos

use of baritone.api.utils.BetterBlockPos in project baritone by cabaletta.

the class WaypointCollection method load.

private synchronized void load(Waypoint.Tag tag) {
    this.waypoints.put(tag, new HashSet<>());
    Path fileName = this.directory.resolve(tag.name().toLowerCase() + ".mp4");
    if (!Files.exists(fileName)) {
        return;
    }
    try (FileInputStream fileIn = new FileInputStream(fileName.toFile());
        BufferedInputStream bufIn = new BufferedInputStream(fileIn);
        DataInputStream in = new DataInputStream(bufIn)) {
        long magic = in.readLong();
        if (magic != WAYPOINT_MAGIC_VALUE) {
            throw new IOException("Bad magic value " + magic);
        }
        // Yes I want 9,223,372,036,854,775,807 waypoints, do you not?
        long length = in.readLong();
        while (length-- > 0) {
            String name = in.readUTF();
            long creationTimestamp = in.readLong();
            int x = in.readInt();
            int y = in.readInt();
            int z = in.readInt();
            this.waypoints.get(tag).add(new Waypoint(name, tag, new BetterBlockPos(x, y, z), creationTimestamp));
        }
    } catch (IOException ignored) {
    }
}
Also used : Path(java.nio.file.Path) BetterBlockPos(baritone.api.utils.BetterBlockPos) IWaypoint(baritone.api.cache.IWaypoint) Waypoint(baritone.api.cache.Waypoint) IWaypoint(baritone.api.cache.IWaypoint) Waypoint(baritone.api.cache.Waypoint)

Example 3 with BetterBlockPos

use of baritone.api.utils.BetterBlockPos in project baritone by cabaletta.

the class FindCommand method execute.

@Override
public void execute(String label, IArgConsumer args) throws CommandException {
    List<Block> toFind = new ArrayList<>();
    while (args.hasAny()) {
        toFind.add(args.getDatatypeFor(BlockById.INSTANCE));
    }
    BetterBlockPos origin = ctx.playerFeet();
    toFind.stream().flatMap(block -> ctx.worldData().getCachedWorld().getLocationsOf(Block.REGISTRY.getNameForObject(block).getPath(), Integer.MAX_VALUE, origin.x, origin.y, 4).stream()).map(BetterBlockPos::new).map(BetterBlockPos::toString).forEach(this::logDirect);
}
Also used : BetterBlockPos(baritone.api.utils.BetterBlockPos) IBaritone(baritone.api.IBaritone) Arrays(java.util.Arrays) List(java.util.List) BlockById(baritone.api.command.datatypes.BlockById) Stream(java.util.stream.Stream) Block(net.minecraft.block.Block) Command(baritone.api.command.Command) CommandException(baritone.api.command.exception.CommandException) IArgConsumer(baritone.api.command.argument.IArgConsumer) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) BetterBlockPos(baritone.api.utils.BetterBlockPos) Block(net.minecraft.block.Block)

Example 4 with BetterBlockPos

use of baritone.api.utils.BetterBlockPos in project baritone by cabaletta.

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 5 with BetterBlockPos

use of baritone.api.utils.BetterBlockPos in project baritone by cabaletta.

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)

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