Search in sources :

Example 41 with BetterBlockPos

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

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

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

the class GoalCommand method execute.

@Override
public void execute(String label, IArgConsumer args) throws CommandException {
    ICustomGoalProcess goalProcess = baritone.getCustomGoalProcess();
    if (args.hasAny() && Arrays.asList("reset", "clear", "none").contains(args.peekString())) {
        args.requireMax(1);
        if (goalProcess.getGoal() != null) {
            goalProcess.setGoal(null);
            logDirect("Cleared goal");
        } else {
            logDirect("There was no goal to clear");
        }
    } else {
        args.requireMax(3);
        BetterBlockPos origin = baritone.getPlayerContext().playerFeet();
        Goal goal = args.getDatatypePost(RelativeGoal.INSTANCE, origin);
        goalProcess.setGoal(goal);
        logDirect(String.format("Goal: %s", goal.toString()));
    }
}
Also used : RelativeGoal(baritone.api.command.datatypes.RelativeGoal) Goal(baritone.api.pathing.goals.Goal) ICustomGoalProcess(baritone.api.process.ICustomGoalProcess) BetterBlockPos(baritone.api.utils.BetterBlockPos)

Example 43 with BetterBlockPos

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

the class FarmCommand method execute.

@Override
public void execute(String label, IArgConsumer args) throws CommandException {
    args.requireMax(2);
    int range = 0;
    BetterBlockPos origin = null;
    // range
    if (args.has(1)) {
        range = args.getAs(Integer.class);
    }
    // waypoint
    if (args.has(1)) {
        IWaypoint[] waypoints = args.getDatatypeFor(ForWaypoints.INSTANCE);
        IWaypoint waypoint = null;
        switch(waypoints.length) {
            case 0:
                throw new CommandInvalidStateException("No waypoints found");
            case 1:
                waypoint = waypoints[0];
                break;
            default:
                throw new CommandInvalidStateException("Multiple waypoints were found");
        }
        origin = waypoint.getLocation();
    }
    baritone.getFarmProcess().farm(range, origin);
    logDirect("Farming");
}
Also used : IWaypoint(baritone.api.cache.IWaypoint) BetterBlockPos(baritone.api.utils.BetterBlockPos) CommandInvalidStateException(baritone.api.command.exception.CommandInvalidStateException) IWaypoint(baritone.api.cache.IWaypoint)

Example 44 with BetterBlockPos

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

the class BuilderProcess method toBreakNearPlayer.

private Optional<Tuple<BetterBlockPos, Rotation>> toBreakNearPlayer(BuilderCalculationContext bcc) {
    BetterBlockPos center = ctx.playerFeet();
    BetterBlockPos pathStart = baritone.getPathingBehavior().pathStart();
    for (int dx = -5; dx <= 5; dx++) {
        for (int dy = Baritone.settings().breakFromAbove.value ? -1 : 0; dy <= 5; dy++) {
            for (int dz = -5; dz <= 5; dz++) {
                int x = center.x + dx;
                int y = center.y + dy;
                int z = center.z + dz;
                if (dy == -1 && x == pathStart.x && z == pathStart.z) {
                    // dont mine what we're supported by, but not directly standing on
                    continue;
                }
                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 (curr.getBlock() != Blocks.AIR && !(curr.getBlock() instanceof BlockLiquid) && !valid(curr, desired, false)) {
                    BetterBlockPos pos = new BetterBlockPos(x, y, z);
                    Optional<Rotation> rot = RotationUtils.reachable(ctx.player(), pos, ctx.playerController().getBlockReachDistance());
                    if (rot.isPresent()) {
                        return Optional.of(new Tuple<>(pos, rot.get()));
                    }
                }
            }
        }
    }
    return Optional.empty();
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BetterBlockPos(baritone.api.utils.BetterBlockPos) Rotation(baritone.api.utils.Rotation)

Example 45 with BetterBlockPos

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

the class BuilderProcess method possibleToPlace.

private Optional<Placement> possibleToPlace(IBlockState toPlace, int x, int y, int z, BlockStateInterface bsi) {
    for (EnumFacing against : EnumFacing.values()) {
        BetterBlockPos placeAgainstPos = new BetterBlockPos(x, y, z).offset(against);
        IBlockState placeAgainstState = bsi.get0(placeAgainstPos);
        if (MovementHelper.isReplaceable(placeAgainstPos.x, placeAgainstPos.y, placeAgainstPos.z, placeAgainstState, bsi)) {
            continue;
        }
        if (!ctx.world().mayPlace(toPlace.getBlock(), new BetterBlockPos(x, y, z), false, against, null)) {
            continue;
        }
        AxisAlignedBB aabb = placeAgainstState.getBoundingBox(ctx.world(), placeAgainstPos);
        for (Vec3d placementMultiplier : aabbSideMultipliers(against)) {
            double placeX = placeAgainstPos.x + aabb.minX * placementMultiplier.x + aabb.maxX * (1 - placementMultiplier.x);
            double placeY = placeAgainstPos.y + aabb.minY * placementMultiplier.y + aabb.maxY * (1 - placementMultiplier.y);
            double placeZ = placeAgainstPos.z + aabb.minZ * placementMultiplier.z + aabb.maxZ * (1 - placementMultiplier.z);
            Rotation rot = RotationUtils.calcRotationFromVec3d(RayTraceUtils.inferSneakingEyePosition(ctx.player()), new Vec3d(placeX, placeY, placeZ), ctx.playerRotations());
            RayTraceResult result = RayTraceUtils.rayTraceTowards(ctx.player(), rot, ctx.playerController().getBlockReachDistance(), true);
            if (result != null && result.typeOfHit == RayTraceResult.Type.BLOCK && result.getBlockPos().equals(placeAgainstPos) && result.sideHit == against.getOpposite()) {
                OptionalInt hotbar = hasAnyItemThatWouldPlace(toPlace, result, rot);
                if (hotbar.isPresent()) {
                    return Optional.of(new Placement(hotbar.getAsInt(), placeAgainstPos, against.getOpposite(), rot));
                }
            }
        }
    }
    return Optional.empty();
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) EnumFacing(net.minecraft.util.EnumFacing) BetterBlockPos(baritone.api.utils.BetterBlockPos) Rotation(baritone.api.utils.Rotation)

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