Search in sources :

Example 6 with CalculationContext

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

the class MovementFall method willPlaceBucket.

private boolean willPlaceBucket() {
    CalculationContext context = new CalculationContext(baritone);
    MutableMoveResult result = new MutableMoveResult();
    return MovementDescend.dynamicFallCost(context, src.x, src.y, src.z, dest.x, dest.z, 0, context.get(dest.x, src.y - 2, dest.z), result);
}
Also used : CalculationContext(baritone.pathing.movement.CalculationContext) MutableMoveResult(baritone.utils.pathing.MutableMoveResult)

Example 7 with CalculationContext

use of baritone.pathing.movement.CalculationContext 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)

Example 8 with CalculationContext

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

the class MineProcess method prune.

private static List<BlockPos> prune(CalculationContext ctx, List<BlockPos> locs2, BlockOptionalMetaLookup filter, int max, List<BlockPos> blacklist, List<BlockPos> dropped) {
    dropped.removeIf(drop -> {
        for (BlockPos pos : locs2) {
            if (pos.distanceSq(drop) <= 9 && filter.has(ctx.get(pos.getX(), pos.getY(), pos.getZ())) && MineProcess.plausibleToBreak(ctx, pos)) {
                // TODO maybe drop also has to be supported? no lava below?
                return true;
            }
        }
        return false;
    });
    List<BlockPos> locs = locs2.stream().distinct().filter(pos -> !ctx.bsi.worldContainsLoadedChunk(pos.getX(), pos.getZ()) || filter.has(ctx.get(pos.getX(), pos.getY(), pos.getZ())) || dropped.contains(pos)).filter(pos -> MineProcess.plausibleToBreak(ctx, pos)).filter(pos -> {
        if (Baritone.settings().allowOnlyExposedOres.getValue()) {
            return isNextToAir(ctx, pos);
        } else {
            return true;
        }
    }).filter(pos -> pos.getY() >= Baritone.settings().minYLevelWhileMining.getValue()).filter(pos -> !blacklist.contains(pos)).sorted(Comparator.comparingDouble(ctx.getBaritone().getPlayerContext().player()::getDistanceSq)).collect(Collectors.toList());
    if (locs.size() > max) {
        return locs.subList(0, max);
    }
    return locs;
}
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) BlockPos(net.minecraft.util.math.BlockPos)

Example 9 with CalculationContext

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

the class MineProcess method mine.

@Override
public void mine(int quantity, BlockOptionalMetaLookup filter) {
    this.filter = filter;
    if (filter != null && !Baritone.settings().allowBreak.getValue()) {
        logDirect("Unable to mine when allowBreak is false!");
        this.mine(quantity, (BlockOptionalMetaLookup) null);
        return;
    }
    this.desiredQuantity = quantity;
    this.knownOreLocations = new ArrayList<>();
    this.blacklist = new ArrayList<>();
    this.branchPoint = null;
    this.branchPointRunaway = null;
    this.anticipatedDrops = new HashMap<>();
    if (filter != null) {
        rescan(new ArrayList<>(), new CalculationContext(baritone));
    }
}
Also used : CalculationContext(baritone.pathing.movement.CalculationContext)

Example 10 with CalculationContext

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

the class MovementPillar method updateState.

@Override
public MovementState updateState(MovementState state) {
    super.updateState(state);
    if (state.getStatus() != MovementStatus.RUNNING) {
        return state;
    }
    if (ctx.playerFeet().y < src.y) {
        return state.setStatus(MovementStatus.UNREACHABLE);
    }
    IBlockState fromDown = BlockStateInterface.get(ctx, src);
    if (MovementHelper.isWater(fromDown.getBlock()) && MovementHelper.isWater(ctx, dest)) {
        // stay centered while swimming up a water column
        state.setTarget(new MovementState.MovementTarget(RotationUtils.calcRotationFromVec3d(ctx.playerHead(), VecUtils.getBlockPosCenter(dest), ctx.playerRotations()), false));
        Vec3d destCenter = VecUtils.getBlockPosCenter(dest);
        if (Math.abs(ctx.player().posX - destCenter.x) > 0.2 || Math.abs(ctx.player().posZ - destCenter.z) > 0.2) {
            state.setInput(Input.MOVE_FORWARD, true);
        }
        if (ctx.playerFeet().equals(dest)) {
            return state.setStatus(MovementStatus.SUCCESS);
        }
        return state;
    }
    boolean ladder = fromDown.getBlock() == Blocks.LADDER || fromDown.getBlock() == Blocks.VINE;
    boolean vine = fromDown.getBlock() == Blocks.VINE;
    Rotation rotation = RotationUtils.calcRotationFromVec3d(ctx.playerHead(), VecUtils.getBlockPosCenter(positionToPlace), new Rotation(ctx.player().rotationYaw, ctx.player().rotationPitch));
    if (!ladder) {
        state.setTarget(new MovementState.MovementTarget(new Rotation(ctx.player().rotationYaw, rotation.getPitch()), true));
    }
    boolean blockIsThere = MovementHelper.canWalkOn(ctx, src) || ladder;
    if (ladder) {
        BlockPos against = vine ? getAgainst(new CalculationContext(baritone), src) : src.offset(fromDown.getValue(BlockLadder.FACING).getOpposite());
        if (against == null) {
            logDirect("Unable to climb vines. Consider disabling allowVines.");
            return state.setStatus(MovementStatus.UNREACHABLE);
        }
        if (ctx.playerFeet().equals(against.up()) || ctx.playerFeet().equals(dest)) {
            return state.setStatus(MovementStatus.SUCCESS);
        }
        if (MovementHelper.isBottomSlab(BlockStateInterface.get(ctx, src.down()))) {
            state.setInput(Input.JUMP, true);
        }
        /*
            if (thePlayer.getPosition0().getX() != from.getX() || thePlayer.getPosition0().getZ() != from.getZ()) {
                Baritone.moveTowardsBlock(from);
            }
             */
        MovementHelper.moveTowards(ctx, state, against);
        return state;
    } else {
        // Get ready to place a throwaway block
        if (!((Baritone) baritone).getInventoryBehavior().selectThrowawayForLocation(true, src.x, src.y, src.z)) {
            return state.setStatus(MovementStatus.UNREACHABLE);
        }
        // delay placement by 1 tick for ncp compatibility
        state.setInput(Input.SNEAK, ctx.player().posY > dest.getY() || ctx.player().posY < src.getY() + 0.2D);
        // since (lower down) we only right click once player.isSneaking, and that happens the tick after we request to sneak
        double diffX = ctx.player().posX - (dest.getX() + 0.5);
        double diffZ = ctx.player().posZ - (dest.getZ() + 0.5);
        double dist = Math.sqrt(diffX * diffX + diffZ * diffZ);
        double flatMotion = Math.sqrt(ctx.player().motionX * ctx.player().motionX + ctx.player().motionZ * ctx.player().motionZ);
        if (dist > 0.17) {
            // why 0.17? because it seemed like a good number, that's why
            // [explanation added after baritone port lol] also because it needs to be less than 0.2 because of the 0.3 sneak limit
            // and 0.17 is reasonably less than 0.2
            // If it's been more than forty ticks of trying to jump and we aren't done yet, go forward, maybe we are stuck
            state.setInput(Input.MOVE_FORWARD, true);
            // revise our target to both yaw and pitch if we're going to be moving forward
            state.setTarget(new MovementState.MovementTarget(rotation, true));
        } else if (flatMotion < 0.05) {
            // If our Y coordinate is above our goal, stop jumping
            state.setInput(Input.JUMP, ctx.player().posY < dest.getY());
        }
        if (!blockIsThere) {
            IBlockState frState = BlockStateInterface.get(ctx, src);
            Block fr = frState.getBlock();
            // TODO: Evaluate usage of getMaterial().isReplaceable()
            if (!(fr instanceof BlockAir || frState.getMaterial().isReplaceable())) {
                RotationUtils.reachable(ctx.player(), src, ctx.playerController().getBlockReachDistance()).map(rot -> new MovementState.MovementTarget(rot, true)).ifPresent(state::setTarget);
                // breaking is like 5x slower when you're jumping
                state.setInput(Input.JUMP, false);
                state.setInput(Input.CLICK_LEFT, true);
                blockIsThere = false;
            } else if (ctx.player().isSneaking() && (Objects.equals(src.down(), ctx.objectMouseOver().getBlockPos()) || Objects.equals(src, ctx.objectMouseOver().getBlockPos())) && ctx.player().posY > dest.getY() + 0.1) {
                state.setInput(Input.CLICK_RIGHT, true);
            }
        }
    }
    // If we are at our goal and the block below us is placed
    if (ctx.playerFeet().equals(dest) && blockIsThere) {
        return state.setStatus(MovementStatus.SUCCESS);
    }
    return state;
}
Also used : Rotation(baritone.api.utils.Rotation) ImmutableSet(com.google.common.collect.ImmutableSet) Blocks(net.minecraft.init.Blocks) VecUtils(baritone.api.utils.VecUtils) Set(java.util.Set) BlockPos(net.minecraft.util.math.BlockPos) CalculationContext(baritone.pathing.movement.CalculationContext) MovementHelper(baritone.pathing.movement.MovementHelper) BetterBlockPos(baritone.api.utils.BetterBlockPos) Objects(java.util.Objects) IBlockState(net.minecraft.block.state.IBlockState) IBaritone(baritone.api.IBaritone) MovementStatus(baritone.api.pathing.movement.MovementStatus) Movement(baritone.pathing.movement.Movement) Vec3d(net.minecraft.util.math.Vec3d) net.minecraft.block(net.minecraft.block) Baritone(baritone.Baritone) BlockStateInterface(baritone.utils.BlockStateInterface) RotationUtils(baritone.api.utils.RotationUtils) MovementState(baritone.pathing.movement.MovementState) Input(baritone.api.utils.input.Input) IBlockState(net.minecraft.block.state.IBlockState) CalculationContext(baritone.pathing.movement.CalculationContext) Rotation(baritone.api.utils.Rotation) Vec3d(net.minecraft.util.math.Vec3d) MovementState(baritone.pathing.movement.MovementState) IBaritone(baritone.api.IBaritone) Baritone(baritone.Baritone) BlockPos(net.minecraft.util.math.BlockPos) BetterBlockPos(baritone.api.utils.BetterBlockPos)

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