Search in sources :

Example 1 with BlockStateInterface

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

the class PathExecutor method onTick.

/**
 * Tick this executor
 *
 * @return True if a movement just finished (and the player is therefore in a "stable" state, like,
 * not sneaking out over lava), false otherwise
 */
public boolean onTick() {
    if (pathPosition == path.length() - 1) {
        pathPosition++;
    }
    if (pathPosition >= path.length()) {
        // stop bugging me, I'm done
        return true;
    }
    Movement movement = (Movement) path.movements().get(pathPosition);
    BetterBlockPos whereAmI = ctx.playerFeet();
    if (!movement.getValidPositions().contains(whereAmI)) {
        for (int i = 0; i < pathPosition && i < path.length(); i++) {
            // this happens for example when you lag out and get teleported back a couple blocks
            if (((Movement) path.movements().get(i)).getValidPositions().contains(whereAmI)) {
                int previousPos = pathPosition;
                pathPosition = i;
                for (int j = pathPosition; j <= previousPos; j++) {
                    path.movements().get(j).reset();
                }
                onChangeInPathPosition();
                onTick();
                return false;
            }
        }
        for (int i = pathPosition + 3; i < path.length() - 1; i++) {
            // also don't check pathPosition+2 because reasons
            if (((Movement) path.movements().get(i)).getValidPositions().contains(whereAmI)) {
                if (i - pathPosition > 2) {
                    logDebug("Skipping forward " + (i - pathPosition) + " steps, to " + i);
                }
                // System.out.println("Double skip sundae");
                pathPosition = i - 1;
                onChangeInPathPosition();
                onTick();
                return false;
            }
        }
    }
    Tuple<Double, BlockPos> status = closestPathPos(path);
    if (possiblyOffPath(status, MAX_DIST_FROM_PATH)) {
        ticksAway++;
        System.out.println("FAR AWAY FROM PATH FOR " + ticksAway + " TICKS. Current distance: " + status.getFirst() + ". Threshold: " + MAX_DIST_FROM_PATH);
        if (ticksAway > MAX_TICKS_AWAY) {
            logDebug("Too far away from path for too long, cancelling path");
            cancel();
            return false;
        }
    } else {
        ticksAway = 0;
    }
    if (possiblyOffPath(status, MAX_MAX_DIST_FROM_PATH)) {
        // ok, stop right away, we're way too far.
        logDebug("too far from path");
        cancel();
        return false;
    }
    // long start = System.nanoTime() / 1000000L;
    BlockStateInterface bsi = new BlockStateInterface(ctx);
    for (int i = pathPosition - 10; i < pathPosition + 10; i++) {
        if (i < 0 || i >= path.movements().size()) {
            continue;
        }
        Movement m = (Movement) path.movements().get(i);
        List<BlockPos> prevBreak = m.toBreak(bsi);
        List<BlockPos> prevPlace = m.toPlace(bsi);
        List<BlockPos> prevWalkInto = m.toWalkInto(bsi);
        m.resetBlockCache();
        if (!prevBreak.equals(m.toBreak(bsi))) {
            recalcBP = true;
        }
        if (!prevPlace.equals(m.toPlace(bsi))) {
            recalcBP = true;
        }
        if (!prevWalkInto.equals(m.toWalkInto(bsi))) {
            recalcBP = true;
        }
    }
    if (recalcBP) {
        HashSet<BlockPos> newBreak = new HashSet<>();
        HashSet<BlockPos> newPlace = new HashSet<>();
        HashSet<BlockPos> newWalkInto = new HashSet<>();
        for (int i = pathPosition; i < path.movements().size(); i++) {
            Movement m = (Movement) path.movements().get(i);
            newBreak.addAll(m.toBreak(bsi));
            newPlace.addAll(m.toPlace(bsi));
            newWalkInto.addAll(m.toWalkInto(bsi));
        }
        toBreak = newBreak;
        toPlace = newPlace;
        toWalkInto = newWalkInto;
        recalcBP = false;
    }
    /*long end = System.nanoTime() / 1000000L;
        if (end - start > 0) {
            System.out.println("Recalculating break and place took " + (end - start) + "ms");
        }*/
    if (pathPosition < path.movements().size() - 1) {
        IMovement next = path.movements().get(pathPosition + 1);
        if (!behavior.baritone.bsi.worldContainsLoadedChunk(next.getDest().x, next.getDest().z)) {
            logDebug("Pausing since destination is at edge of loaded chunks");
            clearKeys();
            return true;
        }
    }
    boolean canCancel = movement.safeToCancel();
    if (costEstimateIndex == null || costEstimateIndex != pathPosition) {
        costEstimateIndex = pathPosition;
        // do this only once, when the movement starts, and deliberately get the cost as cached when this path was calculated, not the cost as it is right now
        currentMovementOriginalCostEstimate = movement.getCost();
        for (int i = 1; i < Baritone.settings().costVerificationLookahead.value && pathPosition + i < path.length() - 1; i++) {
            if (((Movement) path.movements().get(pathPosition + i)).calculateCost(behavior.secretInternalGetCalculationContext()) >= ActionCosts.COST_INF && canCancel) {
                logDebug("Something has changed in the world and a future movement has become impossible. Cancelling.");
                cancel();
                return true;
            }
        }
    }
    double currentCost = movement.recalculateCost(behavior.secretInternalGetCalculationContext());
    if (currentCost >= ActionCosts.COST_INF && canCancel) {
        logDebug("Something has changed in the world and this movement has become impossible. Cancelling.");
        cancel();
        return true;
    }
    if (!movement.calculatedWhileLoaded() && currentCost - currentMovementOriginalCostEstimate > Baritone.settings().maxCostIncrease.value && canCancel) {
        // don't do this if the movement was calculated while loaded
        // that means that this isn't a cache error, it's just part of the path interfering with a later part
        logDebug("Original cost " + currentMovementOriginalCostEstimate + " current cost " + currentCost + ". Cancelling.");
        cancel();
        return true;
    }
    if (shouldPause()) {
        logDebug("Pausing since current best path is a backtrack");
        clearKeys();
        return true;
    }
    MovementStatus movementStatus = movement.update();
    if (movementStatus == UNREACHABLE || movementStatus == FAILED) {
        logDebug("Movement returns status " + movementStatus);
        cancel();
        return true;
    }
    if (movementStatus == SUCCESS) {
        // System.out.println("Movement done, next path");
        pathPosition++;
        onChangeInPathPosition();
        onTick();
        return true;
    } else {
        sprintNextTick = shouldSprintNextTick();
        if (!sprintNextTick) {
            // letting go of control doesn't make you stop sprinting actually
            ctx.player().setSprinting(false);
        }
        ticksOnCurrent++;
        if (ticksOnCurrent > currentMovementOriginalCostEstimate + Baritone.settings().movementTimeoutTicks.value) {
            // only cancel if the total time has exceeded the initial estimate
            // as you break the blocks required, the remaining cost goes down, to the point where
            // ticksOnCurrent is greater than recalculateCost + 100
            // this is why we cache cost at the beginning, and don't recalculate for this comparison every tick
            logDebug("This movement has taken too long (" + ticksOnCurrent + " ticks, expected " + currentMovementOriginalCostEstimate + "). Cancelling.");
            cancel();
            return true;
        }
    }
    // movement is in progress, but if it reports cancellable, PathingBehavior is good to cut onto the next path
    return canCancel;
}
Also used : BlockStateInterface(baritone.utils.BlockStateInterface) IMovement(baritone.api.pathing.movement.IMovement) Movement(baritone.pathing.movement.Movement) IMovement(baritone.api.pathing.movement.IMovement) MovementStatus(baritone.api.pathing.movement.MovementStatus) BlockPos(net.minecraft.util.math.BlockPos)

Example 2 with BlockStateInterface

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

the class SelCommand method execute.

@Override
public void execute(String label, IArgConsumer args) throws CommandException {
    Action action = Action.getByName(args.getString());
    if (action == null) {
        throw new CommandInvalidTypeException(args.consumed(), "an action");
    }
    if (action == Action.POS1 || action == Action.POS2) {
        if (action == Action.POS2 && pos1 == null) {
            throw new CommandInvalidStateException("Set pos1 first before using pos2");
        }
        BetterBlockPos playerPos = mc.getRenderViewEntity() != null ? BetterBlockPos.from(new BlockPos(mc.getRenderViewEntity())) : ctx.playerFeet();
        BetterBlockPos pos = args.hasAny() ? args.getDatatypePost(RelativeBlockPos.INSTANCE, playerPos) : playerPos;
        args.requireMax(0);
        if (action == Action.POS1) {
            pos1 = pos;
            logDirect("Position 1 has been set");
        } else {
            manager.addSelection(pos1, pos);
            pos1 = null;
            logDirect("Selection added");
        }
    } else if (action == Action.CLEAR) {
        args.requireMax(0);
        pos1 = null;
        logDirect(String.format("Removed %d selections", manager.removeAllSelections().length));
    } else if (action == Action.UNDO) {
        args.requireMax(0);
        if (pos1 != null) {
            pos1 = null;
            logDirect("Undid pos1");
        } else {
            ISelection[] selections = manager.getSelections();
            if (selections.length < 1) {
                throw new CommandInvalidStateException("Nothing to undo!");
            } else {
                pos1 = manager.removeSelection(selections[selections.length - 1]).pos1();
                logDirect("Undid pos2");
            }
        }
    } else if (action == Action.SET || action == Action.WALLS || action == Action.SHELL || action == Action.CLEARAREA || action == Action.REPLACE) {
        BlockOptionalMeta type = action == Action.CLEARAREA ? new BlockOptionalMeta(Blocks.AIR) : args.getDatatypeFor(ForBlockOptionalMeta.INSTANCE);
        BlockOptionalMetaLookup replaces = null;
        if (action == Action.REPLACE) {
            args.requireMin(1);
            List<BlockOptionalMeta> replacesList = new ArrayList<>();
            replacesList.add(type);
            while (args.has(2)) {
                replacesList.add(args.getDatatypeFor(ForBlockOptionalMeta.INSTANCE));
            }
            type = args.getDatatypeFor(ForBlockOptionalMeta.INSTANCE);
            replaces = new BlockOptionalMetaLookup(replacesList.toArray(new BlockOptionalMeta[0]));
        } else {
            args.requireMax(0);
        }
        ISelection[] selections = manager.getSelections();
        if (selections.length == 0) {
            throw new CommandInvalidStateException("No selections");
        }
        BetterBlockPos origin = selections[0].min();
        CompositeSchematic composite = new CompositeSchematic(0, 0, 0);
        for (ISelection selection : selections) {
            BetterBlockPos min = selection.min();
            origin = new BetterBlockPos(Math.min(origin.x, min.x), Math.min(origin.y, min.y), Math.min(origin.z, min.z));
        }
        for (ISelection selection : selections) {
            Vec3i size = selection.size();
            BetterBlockPos min = selection.min();
            ISchematic schematic = new FillSchematic(size.getX(), size.getY(), size.getZ(), type);
            if (action == Action.WALLS) {
                schematic = new WallsSchematic(schematic);
            } else if (action == Action.SHELL) {
                schematic = new ShellSchematic(schematic);
            } else if (action == Action.REPLACE) {
                schematic = new ReplaceSchematic(schematic, replaces);
            }
            composite.put(schematic, min.x - origin.x, min.y - origin.y, min.z - origin.z);
        }
        baritone.getBuilderProcess().build("Fill", composite, origin);
        logDirect("Filling now");
    } else if (action == Action.COPY) {
        BetterBlockPos playerPos = mc.getRenderViewEntity() != null ? BetterBlockPos.from(new BlockPos(mc.getRenderViewEntity())) : ctx.playerFeet();
        BetterBlockPos pos = args.hasAny() ? args.getDatatypePost(RelativeBlockPos.INSTANCE, playerPos) : playerPos;
        args.requireMax(0);
        ISelection[] selections = manager.getSelections();
        if (selections.length < 1) {
            throw new CommandInvalidStateException("No selections");
        }
        BlockStateInterface bsi = new BlockStateInterface(ctx);
        BetterBlockPos origin = selections[0].min();
        CompositeSchematic composite = new CompositeSchematic(0, 0, 0);
        for (ISelection selection : selections) {
            BetterBlockPos min = selection.min();
            origin = new BetterBlockPos(Math.min(origin.x, min.x), Math.min(origin.y, min.y), Math.min(origin.z, min.z));
        }
        for (ISelection selection : selections) {
            Vec3i size = selection.size();
            BetterBlockPos min = selection.min();
            IBlockState[][][] blockstates = new IBlockState[size.getX()][size.getZ()][size.getY()];
            for (int x = 0; x < size.getX(); x++) {
                for (int y = 0; y < size.getY(); y++) {
                    for (int z = 0; z < size.getZ(); z++) {
                        blockstates[x][z][y] = bsi.get0(min.x + x, min.y + y, min.z + z);
                    }
                }
            }
            ISchematic schematic = new StaticSchematic() {

                {
                    states = blockstates;
                    x = size.getX();
                    y = size.getY();
                    z = size.getZ();
                }
            };
            composite.put(schematic, min.x - origin.x, min.y - origin.y, min.z - origin.z);
        }
        clipboard = composite;
        clipboardOffset = origin.subtract(pos);
        logDirect("Selection copied");
    } else if (action == Action.PASTE) {
        BetterBlockPos playerPos = mc.getRenderViewEntity() != null ? BetterBlockPos.from(new BlockPos(mc.getRenderViewEntity())) : ctx.playerFeet();
        BetterBlockPos pos = args.hasAny() ? args.getDatatypePost(RelativeBlockPos.INSTANCE, playerPos) : playerPos;
        args.requireMax(0);
        if (clipboard == null) {
            throw new CommandInvalidStateException("You need to copy a selection first");
        }
        baritone.getBuilderProcess().build("Fill", clipboard, pos.add(clipboardOffset));
        logDirect("Building now");
    } else if (action == Action.EXPAND || action == Action.CONTRACT || action == Action.SHIFT) {
        args.requireExactly(3);
        TransformTarget transformTarget = TransformTarget.getByName(args.getString());
        if (transformTarget == null) {
            throw new CommandInvalidStateException("Invalid transform type");
        }
        EnumFacing direction = args.getDatatypeFor(ForEnumFacing.INSTANCE);
        int blocks = args.getAs(Integer.class);
        ISelection[] selections = manager.getSelections();
        if (selections.length < 1) {
            throw new CommandInvalidStateException("No selections found");
        }
        selections = transformTarget.transform(selections);
        for (ISelection selection : selections) {
            if (action == Action.EXPAND) {
                manager.expand(selection, direction, blocks);
            } else if (action == Action.CONTRACT) {
                manager.contract(selection, direction, blocks);
            } else {
                manager.shift(selection, direction, blocks);
            }
        }
        logDirect(String.format("Transformed %d selections", selections.length));
    }
}
Also used : CommandInvalidTypeException(baritone.api.command.exception.CommandInvalidTypeException) EnumFacing(net.minecraft.util.EnumFacing) ForEnumFacing(baritone.api.command.datatypes.ForEnumFacing) StaticSchematic(baritone.utils.schematic.StaticSchematic) BetterBlockPos(baritone.api.utils.BetterBlockPos) ISelection(baritone.api.selection.ISelection) BlockPos(net.minecraft.util.math.BlockPos) BetterBlockPos(baritone.api.utils.BetterBlockPos) RelativeBlockPos(baritone.api.command.datatypes.RelativeBlockPos) List(java.util.List) CommandInvalidStateException(baritone.api.command.exception.CommandInvalidStateException) Vec3i(net.minecraft.util.math.Vec3i) BlockStateInterface(baritone.utils.BlockStateInterface) IBlockState(net.minecraft.block.state.IBlockState) BlockOptionalMetaLookup(baritone.api.utils.BlockOptionalMetaLookup) ForBlockOptionalMeta(baritone.api.command.datatypes.ForBlockOptionalMeta) BlockOptionalMeta(baritone.api.utils.BlockOptionalMeta)

Example 3 with BlockStateInterface

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

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.value && 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) Input(baritone.api.utils.input.Input) BlockStateInterface(baritone.utils.BlockStateInterface) CalculationContext(baritone.pathing.movement.CalculationContext) BlockPos(net.minecraft.util.math.BlockPos)

Example 4 with BlockStateInterface

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

the class PathExecutor method onTick.

/**
 * Tick this executor
 *
 * @return True if a movement just finished (and the player is therefore in a "stable" state, like,
 * not sneaking out over lava), false otherwise
 */
public boolean onTick() {
    if (pathPosition == path.length() - 1) {
        pathPosition++;
    }
    if (pathPosition >= path.length()) {
        // stop bugging me, I'm done
        return true;
    }
    Movement movement = (Movement) path.movements().get(pathPosition);
    BetterBlockPos whereAmI = ctx.playerFeet();
    if (!movement.getValidPositions().contains(whereAmI)) {
        for (int i = 0; i < pathPosition && i < path.length(); i++) {
            // this happens for example when you lag out and get teleported back a couple blocks
            if (((Movement) path.movements().get(i)).getValidPositions().contains(whereAmI)) {
                int previousPos = pathPosition;
                pathPosition = i;
                for (int j = pathPosition; j <= previousPos; j++) {
                    path.movements().get(j).reset();
                }
                onChangeInPathPosition();
                onTick();
                return false;
            }
        }
        for (int i = pathPosition + 3; i < path.length() - 1; i++) {
            // also don't check pathPosition+2 because reasons
            if (((Movement) path.movements().get(i)).getValidPositions().contains(whereAmI)) {
                if (i - pathPosition > 2) {
                    logDebug("Skipping forward " + (i - pathPosition) + " steps, to " + i);
                }
                // System.out.println("Double skip sundae");
                pathPosition = i - 1;
                onChangeInPathPosition();
                onTick();
                return false;
            }
        }
    }
    Tuple<Double, BlockPos> status = closestPathPos(path);
    if (possiblyOffPath(status, MAX_DIST_FROM_PATH)) {
        ticksAway++;
        System.out.println("FAR AWAY FROM PATH FOR " + ticksAway + " TICKS. Current distance: " + status.getFirst() + ". Threshold: " + MAX_DIST_FROM_PATH);
        if (ticksAway > MAX_TICKS_AWAY) {
            logDebug("Too far away from path for too long, cancelling path");
            cancel();
            return false;
        }
    } else {
        ticksAway = 0;
    }
    if (possiblyOffPath(status, MAX_MAX_DIST_FROM_PATH)) {
        // ok, stop right away, we're way too far.
        logDebug("too far from path");
        cancel();
        return false;
    }
    // long start = System.nanoTime() / 1000000L;
    BlockStateInterface bsi = new BlockStateInterface(ctx);
    for (int i = pathPosition - 10; i < pathPosition + 10; i++) {
        if (i < 0 || i >= path.movements().size()) {
            continue;
        }
        Movement m = (Movement) path.movements().get(i);
        List<BlockPos> prevBreak = m.toBreak(bsi);
        List<BlockPos> prevPlace = m.toPlace(bsi);
        List<BlockPos> prevWalkInto = m.toWalkInto(bsi);
        m.resetBlockCache();
        if (!prevBreak.equals(m.toBreak(bsi))) {
            recalcBP = true;
        }
        if (!prevPlace.equals(m.toPlace(bsi))) {
            recalcBP = true;
        }
        if (!prevWalkInto.equals(m.toWalkInto(bsi))) {
            recalcBP = true;
        }
    }
    if (recalcBP) {
        HashSet<BlockPos> newBreak = new HashSet<>();
        HashSet<BlockPos> newPlace = new HashSet<>();
        HashSet<BlockPos> newWalkInto = new HashSet<>();
        for (int i = pathPosition; i < path.movements().size(); i++) {
            Movement m = (Movement) path.movements().get(i);
            newBreak.addAll(m.toBreak(bsi));
            newPlace.addAll(m.toPlace(bsi));
            newWalkInto.addAll(m.toWalkInto(bsi));
        }
        toBreak = newBreak;
        toPlace = newPlace;
        toWalkInto = newWalkInto;
        recalcBP = false;
    }
    /*long end = System.nanoTime() / 1000000L;
        if (end - start > 0) {
            System.out.println("Recalculating break and place took " + (end - start) + "ms");
        }*/
    if (pathPosition < path.movements().size() - 1) {
        IMovement next = path.movements().get(pathPosition + 1);
        if (!behavior.baritone.bsi.worldContainsLoadedChunk(next.getDest().x, next.getDest().z)) {
            logDebug("Pausing since destination is at edge of loaded chunks");
            clearKeys();
            return true;
        }
    }
    boolean canCancel = movement.safeToCancel();
    if (costEstimateIndex == null || costEstimateIndex != pathPosition) {
        costEstimateIndex = pathPosition;
        // do this only once, when the movement starts, and deliberately get the cost as cached when this path was calculated, not the cost as it is right now
        currentMovementOriginalCostEstimate = movement.getCost();
        for (int i = 1; i < Baritone.settings().costVerificationLookahead.getValue() && pathPosition + i < path.length() - 1; i++) {
            if (((Movement) path.movements().get(pathPosition + i)).calculateCost(behavior.secretInternalGetCalculationContext()) >= ActionCosts.COST_INF && canCancel) {
                logDebug("Something has changed in the world and a future movement has become impossible. Cancelling.");
                cancel();
                return true;
            }
        }
    }
    double currentCost = movement.recalculateCost(behavior.secretInternalGetCalculationContext());
    if (currentCost >= ActionCosts.COST_INF && canCancel) {
        logDebug("Something has changed in the world and this movement has become impossible. Cancelling.");
        cancel();
        return true;
    }
    if (!movement.calculatedWhileLoaded() && currentCost - currentMovementOriginalCostEstimate > Baritone.settings().maxCostIncrease.getValue() && canCancel) {
        // don't do this if the movement was calculated while loaded
        // that means that this isn't a cache error, it's just part of the path interfering with a later part
        logDebug("Original cost " + currentMovementOriginalCostEstimate + " current cost " + currentCost + ". Cancelling.");
        cancel();
        return true;
    }
    if (shouldPause()) {
        logDebug("Pausing since current best path is a backtrack");
        clearKeys();
        return true;
    }
    MovementStatus movementStatus = movement.update();
    if (movementStatus == UNREACHABLE || movementStatus == FAILED) {
        logDebug("Movement returns status " + movementStatus);
        cancel();
        return true;
    }
    if (movementStatus == SUCCESS) {
        // System.out.println("Movement done, next path");
        pathPosition++;
        onChangeInPathPosition();
        onTick();
        return true;
    } else {
        sprintNextTick = shouldSprintNextTick();
        if (!sprintNextTick) {
            // letting go of control doesn't make you stop sprinting actually
            ctx.player().setSprinting(false);
        }
        ticksOnCurrent++;
        if (ticksOnCurrent > currentMovementOriginalCostEstimate + Baritone.settings().movementTimeoutTicks.getValue()) {
            // only cancel if the total time has exceeded the initial estimate
            // as you break the blocks required, the remaining cost goes down, to the point where
            // ticksOnCurrent is greater than recalculateCost + 100
            // this is why we cache cost at the beginning, and don't recalculate for this comparison every tick
            logDebug("This movement has taken too long (" + ticksOnCurrent + " ticks, expected " + currentMovementOriginalCostEstimate + "). Cancelling.");
            cancel();
            return true;
        }
    }
    // movement is in progress, but if it reports cancellable, PathingBehavior is good to cut onto the next path
    return canCancel;
}
Also used : BlockStateInterface(baritone.utils.BlockStateInterface) IMovement(baritone.api.pathing.movement.IMovement) Movement(baritone.pathing.movement.Movement) IMovement(baritone.api.pathing.movement.IMovement) MovementStatus(baritone.api.pathing.movement.MovementStatus) BlockPos(net.minecraft.util.math.BlockPos)

Example 5 with BlockStateInterface

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

Aggregations

BlockStateInterface (baritone.utils.BlockStateInterface)6 BlockPos (net.minecraft.util.math.BlockPos)6 Block (net.minecraft.block.Block)3 IBlockState (net.minecraft.block.state.IBlockState)3 Baritone (baritone.Baritone)2 baritone.api.pathing.goals (baritone.api.pathing.goals)2 COST_INF (baritone.api.pathing.movement.ActionCosts.COST_INF)2 IMovement (baritone.api.pathing.movement.IMovement)2 MovementStatus (baritone.api.pathing.movement.MovementStatus)2 IMineProcess (baritone.api.process.IMineProcess)2 PathingCommand (baritone.api.process.PathingCommand)2 PathingCommandType (baritone.api.process.PathingCommandType)2 baritone.api.utils (baritone.api.utils)2 BetterBlockPos (baritone.api.utils.BetterBlockPos)2 Input (baritone.api.utils.input.Input)2 CachedChunk (baritone.cache.CachedChunk)2 WorldScanner (baritone.cache.WorldScanner)2 CalculationContext (baritone.pathing.movement.CalculationContext)2 Movement (baritone.pathing.movement.Movement)2 MovementHelper (baritone.pathing.movement.MovementHelper)2