Search in sources :

Example 11 with CalculationContext

use of baritone.pathing.movement.CalculationContext in project Spark-Client by Spark-Client-Development.

the class PathExecutor method shouldSprintNextTick.

private boolean shouldSprintNextTick() {
    boolean requested = behavior.baritone.getInputOverrideHandler().isInputForcedDown(Input.SPRINT);
    // we'll take it from here, no need for minecraft to see we're holding down control and sprint for us
    behavior.baritone.getInputOverrideHandler().setInputForceState(Input.SPRINT, false);
    // first and foremost, if allowSprint is off, or if we don't have enough hunger, don't try and sprint
    if (!new CalculationContext(behavior.baritone).canSprint) {
        return false;
    }
    IMovement current = path.movements().get(pathPosition);
    // traverse requests sprinting, so we need to do this check first
    if (current instanceof MovementTraverse && pathPosition < path.length() - 3) {
        IMovement next = path.movements().get(pathPosition + 1);
        if (next instanceof MovementAscend && sprintableAscend(ctx, (MovementTraverse) current, (MovementAscend) next, path.movements().get(pathPosition + 2))) {
            if (skipNow(ctx, current)) {
                logDebug("Skipping traverse to straight ascend");
                pathPosition++;
                onChangeInPathPosition();
                onTick();
                behavior.baritone.getInputOverrideHandler().setInputForceState(Input.JUMP, true);
                return true;
            } else {
                logDebug("Too far to the side to safely sprint ascend");
            }
        }
    }
    // if the movement requested sprinting, then we're done
    if (requested) {
        return true;
    }
    // however, descend and ascend don't request sprinting, because they don't know the context of what movement comes after it
    if (current instanceof MovementDescend) {
        if (((MovementDescend) current).safeMode() && !((MovementDescend) current).skipToAscend()) {
            logDebug("Sprinting would be unsafe");
            return false;
        }
        if (pathPosition < path.length() - 2) {
            IMovement next = path.movements().get(pathPosition + 1);
            if (next instanceof MovementAscend && current.getDirection().up().equals(next.getDirection().down())) {
                // a descend then an ascend in the same direction
                pathPosition++;
                onChangeInPathPosition();
                onTick();
                // okay to skip clearKeys and / or onChangeInPathPosition here since this isn't possible to repeat, since it's asymmetric
                logDebug("Skipping descend to straight ascend");
                return true;
            }
            if (canSprintFromDescendInto(ctx, current, next)) {
                if (ctx.playerFeet().equals(current.getDest())) {
                    pathPosition++;
                    onChangeInPathPosition();
                    onTick();
                }
                return true;
            }
        // logDebug("Turning off sprinting " + movement + " " + next + " " + movement.getDirection() + " " + next.getDirection().down() + " " + next.getDirection().down().equals(movement.getDirection()));
        }
    }
    if (current instanceof MovementAscend && pathPosition != 0) {
        IMovement prev = path.movements().get(pathPosition - 1);
        if (prev instanceof MovementDescend && prev.getDirection().up().equals(current.getDirection().down())) {
            BlockPos center = current.getSrc().up();
            // 0.07 is to account for farmland
            if (ctx.player().posY >= center.getY() - 0.07) {
                behavior.baritone.getInputOverrideHandler().setInputForceState(Input.JUMP, false);
                return true;
            }
        }
        if (pathPosition < path.length() - 2 && prev instanceof MovementTraverse && sprintableAscend(ctx, (MovementTraverse) prev, (MovementAscend) current, path.movements().get(pathPosition + 1))) {
            return true;
        }
    }
    if (current instanceof MovementFall) {
        Tuple<Vec3d, BlockPos> data = overrideFall((MovementFall) current);
        if (data != null) {
            BetterBlockPos fallDest = new BetterBlockPos(data.getSecond());
            if (!path.positions().contains(fallDest)) {
                throw new IllegalStateException();
            }
            if (ctx.playerFeet().equals(fallDest)) {
                pathPosition = path.positions().indexOf(fallDest);
                onChangeInPathPosition();
                onTick();
                return true;
            }
            clearKeys();
            behavior.baritone.getLookBehavior().updateTarget(RotationUtils.calcRotationFromVec3d(ctx.playerHead(), data.getFirst(), ctx.playerRotations()), false);
            behavior.baritone.getInputOverrideHandler().setInputForceState(Input.MOVE_FORWARD, true);
            return true;
        }
    }
    return false;
}
Also used : CalculationContext(baritone.pathing.movement.CalculationContext) IMovement(baritone.api.pathing.movement.IMovement) BlockPos(net.minecraft.util.math.BlockPos) Vec3d(net.minecraft.util.math.Vec3d)

Example 12 with CalculationContext

use of baritone.pathing.movement.CalculationContext in project Spark-Client by Spark-Client-Development.

the class MineProcess method onTick.

@Override
public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) {
    if (desiredQuantity > 0) {
        int curr = ctx.player().inventory.mainInventory.stream().filter(stack -> filter.has(stack)).mapToInt(ItemStack::getCount).sum();
        System.out.println("Currently have " + curr + " valid items");
        if (curr >= desiredQuantity) {
            logDirect("Have " + curr + " valid items");
            cancel();
            return null;
        }
    }
    if (calcFailed) {
        if (!knownOreLocations.isEmpty() && Baritone.settings().blacklistClosestOnFailure.getValue()) {
            logDirect("Unable to find any path to " + filter + ", blacklisting presumably unreachable closest instance...");
            if (Baritone.settings().desktopNotifications.getValue() && Baritone.settings().notificationOnMineFail.getValue()) {
                NotificationHelper.notify("Unable to find any path to " + filter + ", blacklisting presumably unreachable closest instance...", true);
            }
            knownOreLocations.stream().min(Comparator.comparingDouble(ctx.player()::getDistanceSq)).ifPresent(blacklist::add);
            knownOreLocations.removeIf(blacklist::contains);
        } else {
            logDirect("Unable to find any path to " + filter + ", canceling mine");
            if (Baritone.settings().desktopNotifications.getValue() && Baritone.settings().notificationOnMineFail.getValue()) {
                NotificationHelper.notify("Unable to find any path to " + filter + ", canceling mine", true);
            }
            cancel();
            return null;
        }
    }
    if (!Baritone.settings().allowBreak.getValue()) {
        logDirect("Unable to mine when allowBreak is false!");
        cancel();
        return null;
    }
    updateLoucaSystem();
    int mineGoalUpdateInterval = Baritone.settings().mineGoalUpdateInterval.getValue();
    List<BlockPos> curr = new ArrayList<>(knownOreLocations);
    if (mineGoalUpdateInterval != 0 && tickCount++ % mineGoalUpdateInterval == 0) {
        // big brain
        CalculationContext context = new CalculationContext(baritone, true);
        Baritone.getExecutor().execute(() -> rescan(curr, context));
    }
    if (Baritone.settings().legitMine.getValue()) {
        addNearby();
    }
    Optional<BlockPos> shaft = curr.stream().filter(pos -> pos.getX() == ctx.playerFeet().getX() && pos.getZ() == ctx.playerFeet().getZ()).filter(pos -> pos.getY() >= ctx.playerFeet().getY()).filter(// after breaking a block, it takes mineGoalUpdateInterval ticks for it to actually update this list =(
    pos -> !(BlockStateInterface.get(ctx, pos).getBlock() instanceof BlockAir)).min(Comparator.comparingDouble(ctx.player()::getDistanceSq));
    baritone.getInputOverrideHandler().clearAllKeys();
    if (shaft.isPresent() && ctx.player().onGround) {
        BlockPos pos = shaft.get();
        IBlockState state = baritone.bsi.get0(pos);
        if (!MovementHelper.avoidBreaking(baritone.bsi, pos.getX(), pos.getY(), pos.getZ(), state)) {
            Optional<Rotation> rot = RotationUtils.reachable(ctx, pos);
            if (rot.isPresent() && isSafeToCancel) {
                baritone.getLookBehavior().updateTarget(rot.get(), true);
                MovementHelper.switchToBestToolFor(ctx, ctx.world().getBlockState(pos));
                if (ctx.isLookingAt(pos) || ctx.playerRotations().isReallyCloseTo(rot.get())) {
                    baritone.getInputOverrideHandler().setInputForceState(Input.CLICK_LEFT, true);
                }
                return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE);
            }
        }
    }
    PathingCommand command = updateGoal();
    if (command == null) {
        // none in range
        // maybe say something in chat? (ahem impact)
        cancel();
        return null;
    }
    return command;
}
Also used : IMineProcess(baritone.api.process.IMineProcess) java.util(java.util) Blocks(net.minecraft.init.Blocks) COST_INF(baritone.api.pathing.movement.ActionCosts.COST_INF) BaritoneProcessHelper(baritone.utils.BaritoneProcessHelper) MovementHelper(baritone.pathing.movement.MovementHelper) ItemStack(net.minecraft.item.ItemStack) Block(net.minecraft.block.Block) baritone.api.utils(baritone.api.utils) EntityItem(net.minecraft.entity.item.EntityItem) Entity(net.minecraft.entity.Entity) WorldScanner(baritone.cache.WorldScanner) BlockFalling(net.minecraft.block.BlockFalling) BlockAir(net.minecraft.block.BlockAir) PathingCommandType(baritone.api.process.PathingCommandType) BlockPos(net.minecraft.util.math.BlockPos) CalculationContext(baritone.pathing.movement.CalculationContext) Collectors(java.util.stream.Collectors) PathingCommand(baritone.api.process.PathingCommand) IBlockState(net.minecraft.block.state.IBlockState) baritone.api.pathing.goals(baritone.api.pathing.goals) Baritone(baritone.Baritone) CachedChunk(baritone.cache.CachedChunk) BlockStateInterface(baritone.utils.BlockStateInterface) NotificationHelper(baritone.utils.NotificationHelper) Input(baritone.api.utils.input.Input) BlockAir(net.minecraft.block.BlockAir) IBlockState(net.minecraft.block.state.IBlockState) CalculationContext(baritone.pathing.movement.CalculationContext) PathingCommand(baritone.api.process.PathingCommand) BlockPos(net.minecraft.util.math.BlockPos)

Example 13 with CalculationContext

use of baritone.pathing.movement.CalculationContext in project Spark-Client by Spark-Client-Development.

the class MineProcess method addNearby.

private void addNearby() {
    List<BlockPos> dropped = droppedItemsScan();
    knownOreLocations.addAll(dropped);
    BlockPos playerFeet = ctx.playerFeet();
    BlockStateInterface bsi = new BlockStateInterface(ctx);
    int searchDist = 10;
    // at least 10 * sqrt(3) with some extra space to account for positioning within the block
    double fakedBlockReachDistance = 20;
    for (int x = playerFeet.getX() - searchDist; x <= playerFeet.getX() + searchDist; x++) {
        for (int y = playerFeet.getY() - searchDist; y <= playerFeet.getY() + searchDist; y++) {
            for (int z = playerFeet.getZ() - searchDist; z <= playerFeet.getZ() + searchDist; z++) {
                // is an x-ray and it'll get caught
                if (filter.has(bsi.get0(x, y, z))) {
                    BlockPos pos = new BlockPos(x, y, z);
                    if ((Baritone.settings().legitMineIncludeDiagonals.getValue() && knownOreLocations.stream().anyMatch(ore -> ore.distanceSq(pos) <= 2)) || RotationUtils.reachable(ctx.player(), pos, fakedBlockReachDistance).isPresent()) {
                        knownOreLocations.add(pos);
                    }
                }
            }
        }
    }
    knownOreLocations = prune(new CalculationContext(baritone), knownOreLocations, filter, ORE_LOCATIONS_COUNT, blacklist, dropped);
}
Also used : IMineProcess(baritone.api.process.IMineProcess) java.util(java.util) Blocks(net.minecraft.init.Blocks) COST_INF(baritone.api.pathing.movement.ActionCosts.COST_INF) BaritoneProcessHelper(baritone.utils.BaritoneProcessHelper) MovementHelper(baritone.pathing.movement.MovementHelper) ItemStack(net.minecraft.item.ItemStack) Block(net.minecraft.block.Block) baritone.api.utils(baritone.api.utils) EntityItem(net.minecraft.entity.item.EntityItem) Entity(net.minecraft.entity.Entity) WorldScanner(baritone.cache.WorldScanner) BlockFalling(net.minecraft.block.BlockFalling) BlockAir(net.minecraft.block.BlockAir) PathingCommandType(baritone.api.process.PathingCommandType) BlockPos(net.minecraft.util.math.BlockPos) CalculationContext(baritone.pathing.movement.CalculationContext) Collectors(java.util.stream.Collectors) PathingCommand(baritone.api.process.PathingCommand) IBlockState(net.minecraft.block.state.IBlockState) baritone.api.pathing.goals(baritone.api.pathing.goals) Baritone(baritone.Baritone) CachedChunk(baritone.cache.CachedChunk) BlockStateInterface(baritone.utils.BlockStateInterface) NotificationHelper(baritone.utils.NotificationHelper) Input(baritone.api.utils.input.Input) BlockStateInterface(baritone.utils.BlockStateInterface) CalculationContext(baritone.pathing.movement.CalculationContext) BlockPos(net.minecraft.util.math.BlockPos)

Example 14 with CalculationContext

use of baritone.pathing.movement.CalculationContext in project Spark-Client by Spark-Client-Development.

the class MineProcess method updateGoal.

private PathingCommand updateGoal() {
    boolean legit = Baritone.settings().legitMine.getValue();
    List<BlockPos> locs = knownOreLocations;
    if (!locs.isEmpty()) {
        CalculationContext context = new CalculationContext(baritone);
        List<BlockPos> locs2 = prune(context, new ArrayList<>(locs), filter, ORE_LOCATIONS_COUNT, blacklist, droppedItemsScan());
        // can't reassign locs, gotta make a new var locs2, because we use it in a lambda right here, and variables you use in a lambda must be effectively final
        Goal goal = new GoalComposite(locs2.stream().map(loc -> coalesce(loc, locs2, context)).toArray(Goal[]::new));
        knownOreLocations = locs2;
        return new PathingCommand(goal, legit ? PathingCommandType.FORCE_REVALIDATE_GOAL_AND_PATH : PathingCommandType.REVALIDATE_GOAL_AND_PATH);
    }
    // we don't know any ore locations at the moment
    if (!legit) {
        return null;
    }
    // only in non-Xray mode (aka legit mode) do we do this
    int y = Baritone.settings().legitMineYLevel.getValue();
    if (branchPoint == null) {
        /*if (!baritone.getPathingBehavior().isPathing() && playerFeet().y == y) {
                // cool, path is over and we are at desired y
                branchPoint = playerFeet();
                branchPointRunaway = null;
            } else {
                return new GoalYLevel(y);
            }*/
        branchPoint = ctx.playerFeet();
    }
    // TODO also, see if the GoalRunAway with maintain Y at 11 works even from the surface
    if (branchPointRunaway == null) {
        branchPointRunaway = new GoalRunAway(1, y, branchPoint) {

            @Override
            public boolean isInGoal(int x, int y, int z) {
                return false;
            }

            @Override
            public double heuristic() {
                return Double.NEGATIVE_INFINITY;
            }
        };
    }
    return new PathingCommand(branchPointRunaway, PathingCommandType.REVALIDATE_GOAL_AND_PATH);
}
Also used : PathingCommand(baritone.api.process.PathingCommand) CalculationContext(baritone.pathing.movement.CalculationContext) BlockPos(net.minecraft.util.math.BlockPos)

Example 15 with CalculationContext

use of baritone.pathing.movement.CalculationContext in project Spark-Client by Spark-Client-Development.

the class PathingBehavior method secretInternalSetGoalAndPath.

public boolean secretInternalSetGoalAndPath(PathingCommand command) {
    secretInternalSetGoal(command.goal);
    if (command instanceof PathingCommandContext) {
        context = ((PathingCommandContext) command).desiredCalcContext;
    } else {
        context = new CalculationContext(baritone, true);
    }
    if (goal == null) {
        return false;
    }
    if (goal.isInGoal(ctx.playerFeet()) || goal.isInGoal(expectedSegmentStart)) {
        return false;
    }
    synchronized (pathPlanLock) {
        if (current != null) {
            return false;
        }
        synchronized (pathCalcLock) {
            if (inProgress != null) {
                return false;
            }
            queuePathEvent(PathEvent.CALC_STARTED);
            findPathInNewThread(expectedSegmentStart, true, context);
            return true;
        }
    }
}
Also used : CalculationContext(baritone.pathing.movement.CalculationContext) PathingCommandContext(baritone.utils.PathingCommandContext)

Aggregations

CalculationContext (baritone.pathing.movement.CalculationContext)22 BlockPos (net.minecraft.util.math.BlockPos)16 PathingCommand (baritone.api.process.PathingCommand)10 IBlockState (net.minecraft.block.state.IBlockState)10 Baritone (baritone.Baritone)8 Input (baritone.api.utils.input.Input)8 MovementHelper (baritone.pathing.movement.MovementHelper)8 BlockStateInterface (baritone.utils.BlockStateInterface)8 Blocks (net.minecraft.init.Blocks)8 baritone.api.pathing.goals (baritone.api.pathing.goals)6 COST_INF (baritone.api.pathing.movement.ActionCosts.COST_INF)6 IMineProcess (baritone.api.process.IMineProcess)6 PathingCommandType (baritone.api.process.PathingCommandType)6 baritone.api.utils (baritone.api.utils)6 CachedChunk (baritone.cache.CachedChunk)6 WorldScanner (baritone.cache.WorldScanner)6 BaritoneProcessHelper (baritone.utils.BaritoneProcessHelper)6 java.util (java.util)6 Collectors (java.util.stream.Collectors)6 Block (net.minecraft.block.Block)6