Search in sources :

Example 1 with PathingCommandContext

use of baritone.utils.PathingCommandContext in project baritone by cabaletta.

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)

Example 2 with PathingCommandContext

use of baritone.utils.PathingCommandContext 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 3 with PathingCommandContext

use of baritone.utils.PathingCommandContext 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)

Example 4 with PathingCommandContext

use of baritone.utils.PathingCommandContext in project baritone by cabaletta.

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.value) {
        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.value) {
            // top to bottom
            maxYInclusive = realSchematic.heightY() - 1;
            minYInclusive = realSchematic.heightY() - layer * Baritone.settings().layerHeight.value;
        } else {
            maxYInclusive = layer * Baritone.settings().layerHeight.value - 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.value && layer * Baritone.settings().layerHeight.value < realSchematic.heightY()) {
            logDirect("Starting layer " + layer);
            layer++;
            return onTick(calcFailed, isSafeToCancel, recursions + 1);
        }
        Vec3i repeat = Baritone.settings().buildRepeat.value;
        int max = Baritone.settings().buildRepeatCount.value;
        numRepeats++;
        if (repeat.equals(new Vec3i(0, 0, 0)) || (max != -1 && numRepeats >= max)) {
            logDirect("Done building");
            if (Baritone.settings().notificationOnBuildFinished.value) {
                logNotification("Done building", false);
            }
            onLostControl();
            return null;
        }
        // build repeat time
        layer = 0;
        origin = new BlockPos(origin).add(repeat);
        if (!Baritone.settings().buildRepeatSneaky.value) {
            schematic.reset();
        }
        logDirect("Repeating build in vector " + repeat + ", new origin is " + origin);
        return onTick(calcFailed, isSafeToCancel, recursions + 1);
    }
    if (Baritone.settings().distanceTrim.value) {
        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.value) {
        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.value && Baritone.settings().buildInLayers.value && layer * Baritone.settings().layerHeight.value < 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)

Aggregations

PathingCommandContext (baritone.utils.PathingCommandContext)4 Goal (baritone.api.pathing.goals.Goal)2 PathingCommand (baritone.api.process.PathingCommand)2 ISchematic (baritone.api.schematic.ISchematic)2 BetterBlockPos (baritone.api.utils.BetterBlockPos)2 Rotation (baritone.api.utils.Rotation)2 CalculationContext (baritone.pathing.movement.CalculationContext)2 IBlockState (net.minecraft.block.state.IBlockState)2 Tuple (net.minecraft.util.Tuple)2