Search in sources :

Example 1 with PathingCommand

use of baritone.api.process.PathingCommand in project baritone by cabaletta.

the class PathingControlManager method executeProcesses.

public PathingCommand executeProcesses() {
    for (IBaritoneProcess process : processes) {
        if (process.isActive()) {
            if (!active.contains(process)) {
                // put a newly active process at the very front of the queue
                active.add(0, process);
            }
        } else {
            active.remove(process);
        }
    }
    // ties are broken by which was added to the beginning of the list first
    active.sort(Comparator.comparingDouble(IBaritoneProcess::priority).reversed());
    Iterator<IBaritoneProcess> iterator = active.iterator();
    while (iterator.hasNext()) {
        IBaritoneProcess proc = iterator.next();
        PathingCommand exec = proc.onTick(Objects.equals(proc, inControlLastTick) && baritone.getPathingBehavior().calcFailedLastTick(), baritone.getPathingBehavior().isSafeToCancel());
        if (exec == null) {
            if (proc.isActive()) {
                throw new IllegalStateException(proc.displayName() + " actively returned null PathingCommand");
            }
        // no need to call onLostControl; they are reporting inactive.
        } else if (exec.commandType != PathingCommandType.DEFER) {
            inControlThisTick = proc;
            if (!proc.isTemporary()) {
                iterator.forEachRemaining(IBaritoneProcess::onLostControl);
            }
            return exec;
        }
    }
    return null;
}
Also used : PathingCommand(baritone.api.process.PathingCommand) IBaritoneProcess(baritone.api.process.IBaritoneProcess)

Example 2 with PathingCommand

use of baritone.api.process.PathingCommand in project baritone by cabaletta.

the class GetToBlockProcess method onTick.

@Override
public synchronized PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) {
    if (knownLocations == null) {
        rescan(new ArrayList<>(), new GetToBlockCalculationContext(false));
    }
    if (knownLocations.isEmpty()) {
        if (Baritone.settings().exploreForBlocks.value && !calcFailed) {
            return new PathingCommand(new GoalRunAway(1, start) {

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

                @Override
                public double heuristic() {
                    return Double.NEGATIVE_INFINITY;
                }
            }, PathingCommandType.FORCE_REVALIDATE_GOAL_AND_PATH);
        }
        logDirect("No known locations of " + gettingTo + ", canceling GetToBlock");
        if (isSafeToCancel) {
            onLostControl();
        }
        return new PathingCommand(null, PathingCommandType.CANCEL_AND_SET_GOAL);
    }
    Goal goal = new GoalComposite(knownLocations.stream().map(this::createGoal).toArray(Goal[]::new));
    if (calcFailed) {
        if (Baritone.settings().blacklistClosestOnFailure.value) {
            logDirect("Unable to find any path to " + gettingTo + ", blacklisting presumably unreachable closest instances...");
            blacklistClosest();
            // gamer moment
            return onTick(false, isSafeToCancel);
        } else {
            logDirect("Unable to find any path to " + gettingTo + ", canceling GetToBlock");
            if (isSafeToCancel) {
                onLostControl();
            }
            return new PathingCommand(goal, PathingCommandType.CANCEL_AND_SET_GOAL);
        }
    }
    int mineGoalUpdateInterval = Baritone.settings().mineGoalUpdateInterval.value;
    if (mineGoalUpdateInterval != 0 && tickCount++ % mineGoalUpdateInterval == 0) {
        // big brain
        List<BlockPos> current = new ArrayList<>(knownLocations);
        CalculationContext context = new GetToBlockCalculationContext(true);
        Baritone.getExecutor().execute(() -> rescan(current, context));
    }
    if (goal.isInGoal(ctx.playerFeet()) && goal.isInGoal(baritone.getPathingBehavior().pathStart()) && isSafeToCancel) {
        // we're there
        if (rightClickOnArrival(gettingTo.getBlock())) {
            if (rightClick()) {
                onLostControl();
                return new PathingCommand(null, PathingCommandType.CANCEL_AND_SET_GOAL);
            }
        } else {
            onLostControl();
            return new PathingCommand(null, PathingCommandType.CANCEL_AND_SET_GOAL);
        }
    }
    return new PathingCommand(goal, PathingCommandType.REVALIDATE_GOAL_AND_PATH);
}
Also used : PathingCommand(baritone.api.process.PathingCommand) CalculationContext(baritone.pathing.movement.CalculationContext) BlockPos(net.minecraft.util.math.BlockPos)

Example 3 with PathingCommand

use of baritone.api.process.PathingCommand in project Spark-Client by Spark-Client-Development.

the class BuilderProcess method onTick.

public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel, int recursions) {
    if (recursions > 1000) {
        // onTick calls itself, don't crash
        return new PathingCommand(null, PathingCommandType.SET_GOAL_AND_PATH);
    }
    approxPlaceable = approxPlaceable(36);
    if (baritone.getInputOverrideHandler().isInputForcedDown(Input.CLICK_LEFT)) {
        ticks = 5;
    } else {
        ticks--;
    }
    baritone.getInputOverrideHandler().clearAllKeys();
    if (paused) {
        return new PathingCommand(null, PathingCommandType.CANCEL_AND_SET_GOAL);
    }
    if (Baritone.settings().buildInLayers.getValue()) {
        if (realSchematic == null) {
            realSchematic = schematic;
        }
        // wrap this properly, dont just have the inner class refer to the builderprocess.this
        ISchematic realSchematic = this.realSchematic;
        int minYInclusive;
        int maxYInclusive;
        // layer = realSchematic.heightY() should be everything
        if (Baritone.settings().layerOrder.getValue()) {
            // top to bottom
            maxYInclusive = realSchematic.heightY() - 1;
            minYInclusive = realSchematic.heightY() - layer;
        } else {
            maxYInclusive = layer - 1;
            minYInclusive = 0;
        }
        schematic = new ISchematic() {

            @Override
            public IBlockState desiredState(int x, int y, int z, IBlockState current, List<IBlockState> approxPlaceable) {
                return realSchematic.desiredState(x, y, z, current, BuilderProcess.this.approxPlaceable);
            }

            @Override
            public boolean inSchematic(int x, int y, int z, IBlockState currentState) {
                return ISchematic.super.inSchematic(x, y, z, currentState) && y >= minYInclusive && y <= maxYInclusive && realSchematic.inSchematic(x, y, z, currentState);
            }

            @Override
            public void reset() {
                realSchematic.reset();
            }

            @Override
            public int widthX() {
                return realSchematic.widthX();
            }

            @Override
            public int heightY() {
                return realSchematic.heightY();
            }

            @Override
            public int lengthZ() {
                return realSchematic.lengthZ();
            }
        };
    }
    BuilderCalculationContext bcc = new BuilderCalculationContext();
    if (!recalc(bcc)) {
        if (Baritone.settings().buildInLayers.getValue() && layer < realSchematic.heightY()) {
            logDirect("Starting layer " + layer);
            layer++;
            return onTick(calcFailed, isSafeToCancel, recursions + 1);
        }
        Vec3i repeat = Baritone.settings().buildRepeat.getValue();
        int max = Baritone.settings().buildRepeatCount.getValue();
        numRepeats++;
        if (repeat.equals(new Vec3i(0, 0, 0)) || (max != -1 && numRepeats >= max)) {
            logDirect("Done building");
            if (Baritone.settings().desktopNotifications.getValue() && Baritone.settings().notificationOnBuildFinished.getValue()) {
                NotificationHelper.notify("Done building", false);
            }
            onLostControl();
            return null;
        }
        // build repeat time
        layer = 0;
        origin = new BlockPos(origin).add(repeat);
        if (!Baritone.settings().buildRepeatSneaky.getValue()) {
            schematic.reset();
        }
        logDirect("Repeating build in vector " + repeat + ", new origin is " + origin);
        return onTick(calcFailed, isSafeToCancel, recursions + 1);
    }
    if (Baritone.settings().distanceTrim.getValue()) {
        trim();
    }
    Optional<Tuple<BetterBlockPos, Rotation>> toBreak = toBreakNearPlayer(bcc);
    if (toBreak.isPresent() && isSafeToCancel && ctx.player().onGround) {
        // we'd like to pause to break this block
        // only change look direction if it's safe (don't want to fuck up an in progress parkour for example
        Rotation rot = toBreak.get().getSecond();
        BetterBlockPos pos = toBreak.get().getFirst();
        baritone.getLookBehavior().updateTarget(rot, true);
        MovementHelper.switchToBestToolFor(ctx, bcc.get(pos));
        if (ctx.player().isSneaking()) {
            // really horrible bug where a block is visible for breaking while sneaking but not otherwise
            // so you can't see it, it goes to place something else, sneaks, then the next tick it tries to break
            // and is unable since it's unsneaked in the intermediary tick
            baritone.getInputOverrideHandler().setInputForceState(Input.SNEAK, true);
        }
        if (ctx.isLookingAt(pos) || ctx.playerRotations().isReallyCloseTo(rot)) {
            baritone.getInputOverrideHandler().setInputForceState(Input.CLICK_LEFT, true);
        }
        return new PathingCommand(null, PathingCommandType.CANCEL_AND_SET_GOAL);
    }
    List<IBlockState> desirableOnHotbar = new ArrayList<>();
    Optional<Placement> toPlace = searchForPlaceables(bcc, desirableOnHotbar);
    if (toPlace.isPresent() && isSafeToCancel && ctx.player().onGround && ticks <= 0) {
        Rotation rot = toPlace.get().rot;
        baritone.getLookBehavior().updateTarget(rot, true);
        ctx.player().inventory.currentItem = toPlace.get().hotbarSelection;
        baritone.getInputOverrideHandler().setInputForceState(Input.SNEAK, true);
        if ((ctx.isLookingAt(toPlace.get().placeAgainst) && ctx.objectMouseOver().sideHit.equals(toPlace.get().side)) || ctx.playerRotations().isReallyCloseTo(rot)) {
            baritone.getInputOverrideHandler().setInputForceState(Input.CLICK_RIGHT, true);
        }
        return new PathingCommand(null, PathingCommandType.CANCEL_AND_SET_GOAL);
    }
    if (Baritone.settings().allowInventory.getValue()) {
        ArrayList<Integer> usefulSlots = new ArrayList<>();
        List<IBlockState> noValidHotbarOption = new ArrayList<>();
        outer: for (IBlockState desired : desirableOnHotbar) {
            for (int i = 0; i < 9; i++) {
                if (valid(approxPlaceable.get(i), desired, true)) {
                    usefulSlots.add(i);
                    continue outer;
                }
            }
            noValidHotbarOption.add(desired);
        }
        outer: for (int i = 9; i < 36; i++) {
            for (IBlockState desired : noValidHotbarOption) {
                if (valid(approxPlaceable.get(i), desired, true)) {
                    baritone.getInventoryBehavior().attemptToPutOnHotbar(i, usefulSlots::contains);
                    break outer;
                }
            }
        }
    }
    Goal goal = assemble(bcc, approxPlaceable.subList(0, 9));
    if (goal == null) {
        // we're far away, so assume that we have our whole inventory to recalculate placeable properly
        goal = assemble(bcc, approxPlaceable, true);
        if (goal == null) {
            if (Baritone.settings().skipFailedLayers.getValue() && Baritone.settings().buildInLayers.getValue() && layer < realSchematic.heightY()) {
                logDirect("Skipping layer that I cannot construct! Layer #" + layer);
                layer++;
                return onTick(calcFailed, isSafeToCancel, recursions + 1);
            }
            logDirect("Unable to do it. Pausing. resume to resume, cancel to cancel");
            paused = true;
            return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE);
        }
    }
    return new PathingCommandContext(goal, PathingCommandType.FORCE_REVALIDATE_GOAL_AND_PATH, bcc);
}
Also used : ISchematic(baritone.api.schematic.ISchematic) IBlockState(net.minecraft.block.state.IBlockState) Rotation(baritone.api.utils.Rotation) Goal(baritone.api.pathing.goals.Goal) PathingCommand(baritone.api.process.PathingCommand) BetterBlockPos(baritone.api.utils.BetterBlockPos) PathingCommandContext(baritone.utils.PathingCommandContext) BetterBlockPos(baritone.api.utils.BetterBlockPos) Tuple(net.minecraft.util.Tuple)

Example 4 with PathingCommand

use of baritone.api.process.PathingCommand in project Spark-Client by Spark-Client-Development.

the class PathingControlManager method executeProcesses.

public PathingCommand executeProcesses() {
    for (IBaritoneProcess process : processes) {
        if (process.isActive()) {
            if (!active.contains(process)) {
                // put a newly active process at the very front of the queue
                active.add(0, process);
            }
        } else {
            active.remove(process);
        }
    }
    // ties are broken by which was added to the beginning of the list first
    active.sort(Comparator.comparingDouble(IBaritoneProcess::priority).reversed());
    Iterator<IBaritoneProcess> iterator = active.iterator();
    while (iterator.hasNext()) {
        IBaritoneProcess proc = iterator.next();
        PathingCommand exec = proc.onTick(Objects.equals(proc, inControlLastTick) && baritone.getPathingBehavior().calcFailedLastTick(), baritone.getPathingBehavior().isSafeToCancel());
        if (exec == null) {
            if (proc.isActive()) {
                throw new IllegalStateException(proc.displayName() + " actively returned null PathingCommand");
            }
        // no need to call onLostControl; they are reporting inactive.
        } else if (exec.commandType != PathingCommandType.DEFER) {
            inControlThisTick = proc;
            if (!proc.isTemporary()) {
                iterator.forEachRemaining(IBaritoneProcess::onLostControl);
            }
            return exec;
        }
    }
    return null;
}
Also used : PathingCommand(baritone.api.process.PathingCommand) IBaritoneProcess(baritone.api.process.IBaritoneProcess)

Example 5 with PathingCommand

use of baritone.api.process.PathingCommand in project Spark-Client by Spark-Client-Development.

the class GetToBlockProcess method onTick.

@Override
public synchronized PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) {
    if (knownLocations == null) {
        rescan(new ArrayList<>(), new GetToBlockCalculationContext(false));
    }
    if (knownLocations.isEmpty()) {
        if (Baritone.settings().exploreForBlocks.getValue() && !calcFailed) {
            return new PathingCommand(new GoalRunAway(1, start) {

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

                @Override
                public double heuristic() {
                    return Double.NEGATIVE_INFINITY;
                }
            }, PathingCommandType.FORCE_REVALIDATE_GOAL_AND_PATH);
        }
        logDirect("No known locations of " + gettingTo + ", canceling GetToBlock");
        if (isSafeToCancel) {
            onLostControl();
        }
        return new PathingCommand(null, PathingCommandType.CANCEL_AND_SET_GOAL);
    }
    Goal goal = new GoalComposite(knownLocations.stream().map(this::createGoal).toArray(Goal[]::new));
    if (calcFailed) {
        if (Baritone.settings().blacklistClosestOnFailure.getValue()) {
            logDirect("Unable to find any path to " + gettingTo + ", blacklisting presumably unreachable closest instances...");
            blacklistClosest();
            // gamer moment
            return onTick(false, isSafeToCancel);
        } else {
            logDirect("Unable to find any path to " + gettingTo + ", canceling GetToBlock");
            if (isSafeToCancel) {
                onLostControl();
            }
            return new PathingCommand(goal, PathingCommandType.CANCEL_AND_SET_GOAL);
        }
    }
    int mineGoalUpdateInterval = Baritone.settings().mineGoalUpdateInterval.getValue();
    if (mineGoalUpdateInterval != 0 && tickCount++ % mineGoalUpdateInterval == 0) {
        // big brain
        List<BlockPos> current = new ArrayList<>(knownLocations);
        CalculationContext context = new GetToBlockCalculationContext(true);
        Baritone.getExecutor().execute(() -> rescan(current, context));
    }
    if (goal.isInGoal(ctx.playerFeet()) && goal.isInGoal(baritone.getPathingBehavior().pathStart()) && isSafeToCancel) {
        // we're there
        if (rightClickOnArrival(gettingTo.getBlock())) {
            if (rightClick()) {
                onLostControl();
                return new PathingCommand(null, PathingCommandType.CANCEL_AND_SET_GOAL);
            }
        } else {
            onLostControl();
            return new PathingCommand(null, PathingCommandType.CANCEL_AND_SET_GOAL);
        }
    }
    return new PathingCommand(goal, PathingCommandType.REVALIDATE_GOAL_AND_PATH);
}
Also used : PathingCommand(baritone.api.process.PathingCommand) CalculationContext(baritone.pathing.movement.CalculationContext) BlockPos(net.minecraft.util.math.BlockPos)

Aggregations

PathingCommand (baritone.api.process.PathingCommand)18 Goal (baritone.api.pathing.goals.Goal)8 BlockPos (net.minecraft.util.math.BlockPos)8 GoalComposite (baritone.api.pathing.goals.GoalComposite)6 CalculationContext (baritone.pathing.movement.CalculationContext)6 IBlockState (net.minecraft.block.state.IBlockState)6 Rotation (baritone.api.utils.Rotation)4 Entity (net.minecraft.entity.Entity)4 EntityItem (net.minecraft.entity.item.EntityItem)4 Baritone (baritone.Baritone)2 baritone.api.pathing.goals (baritone.api.pathing.goals)2 GoalBlock (baritone.api.pathing.goals.GoalBlock)2 COST_INF (baritone.api.pathing.movement.ActionCosts.COST_INF)2 IBaritoneProcess (baritone.api.process.IBaritoneProcess)2 IMineProcess (baritone.api.process.IMineProcess)2 PathingCommandType (baritone.api.process.PathingCommandType)2 ISchematic (baritone.api.schematic.ISchematic)2 baritone.api.utils (baritone.api.utils)2 BetterBlockPos (baritone.api.utils.BetterBlockPos)2 Input (baritone.api.utils.input.Input)2