Search in sources :

Example 1 with Helper

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

the class PathingBehavior method pathStart.

/**
 * See issue #209
 *
 * @return The starting {@link BlockPos} for a new path
 */
public BetterBlockPos pathStart() {
    // TODO move to a helper or util class
    BetterBlockPos feet = ctx.playerFeet();
    if (!MovementHelper.canWalkOn(ctx, feet.down())) {
        if (ctx.player().onGround) {
            double playerX = ctx.player().posX;
            double playerZ = ctx.player().posZ;
            ArrayList<BetterBlockPos> closest = new ArrayList<>();
            for (int dx = -1; dx <= 1; dx++) {
                for (int dz = -1; dz <= 1; dz++) {
                    closest.add(new BetterBlockPos(feet.x + dx, feet.y, feet.z + dz));
                }
            }
            closest.sort(Comparator.comparingDouble(pos -> ((pos.x + 0.5D) - playerX) * ((pos.x + 0.5D) - playerX) + ((pos.z + 0.5D) - playerZ) * ((pos.z + 0.5D) - playerZ)));
            for (int i = 0; i < 4; i++) {
                BetterBlockPos possibleSupport = closest.get(i);
                double xDist = Math.abs((possibleSupport.x + 0.5D) - playerX);
                double zDist = Math.abs((possibleSupport.z + 0.5D) - playerZ);
                if (xDist > 0.8 && zDist > 0.8) {
                    // can't possibly be sneaking off of this one, we're too far away
                    continue;
                }
                if (MovementHelper.canWalkOn(ctx, possibleSupport.down()) && MovementHelper.canWalkThrough(ctx, possibleSupport) && MovementHelper.canWalkThrough(ctx, possibleSupport.up())) {
                    // logDebug("Faking path start assuming player is standing off the edge of a block");
                    return possibleSupport;
                }
            }
        } else {
            // we're in the middle of a jump
            if (MovementHelper.canWalkOn(ctx, feet.down().down())) {
                // logDebug("Faking path start assuming player is midair and falling");
                return feet.down();
            }
        }
    }
    return feet;
}
Also used : IPathingBehavior(baritone.api.behavior.IPathingBehavior) Helper(baritone.api.utils.Helper) PathCalculationResult(baritone.api.utils.PathCalculationResult) IGoalRenderPos(baritone.api.utils.interfaces.IGoalRenderPos) MovementHelper(baritone.pathing.movement.MovementHelper) ArrayList(java.util.ArrayList) GoalXZ(baritone.api.pathing.goals.GoalXZ) AStarPathFinder(baritone.pathing.calc.AStarPathFinder) Favoring(baritone.utils.pathing.Favoring) AbstractNodeCostSearch(baritone.pathing.calc.AbstractNodeCostSearch) baritone.api.event.events(baritone.api.event.events) BlockPos(net.minecraft.util.math.BlockPos) CalculationContext(baritone.pathing.movement.CalculationContext) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Goal(baritone.api.pathing.goals.Goal) BetterBlockPos(baritone.api.utils.BetterBlockPos) Objects(java.util.Objects) PathingCommand(baritone.api.process.PathingCommand) PathingCommandContext(baritone.utils.PathingCommandContext) IPath(baritone.api.pathing.calc.IPath) PathRenderer(baritone.utils.PathRenderer) Baritone(baritone.Baritone) Optional(java.util.Optional) PathExecutor(baritone.pathing.path.PathExecutor) Comparator(java.util.Comparator) BetterBlockPos(baritone.api.utils.BetterBlockPos) ArrayList(java.util.ArrayList)

Example 2 with Helper

use of baritone.api.utils.Helper in project baritone by cabaletta.

the class PathingBehavior method pathStart.

/**
 * See issue #209
 *
 * @return The starting {@link BlockPos} for a new path
 */
public BetterBlockPos pathStart() {
    // TODO move to a helper or util class
    BetterBlockPos feet = ctx.playerFeet();
    if (!MovementHelper.canWalkOn(ctx, feet.down())) {
        if (ctx.player().onGround) {
            double playerX = ctx.player().posX;
            double playerZ = ctx.player().posZ;
            ArrayList<BetterBlockPos> closest = new ArrayList<>();
            for (int dx = -1; dx <= 1; dx++) {
                for (int dz = -1; dz <= 1; dz++) {
                    closest.add(new BetterBlockPos(feet.x + dx, feet.y, feet.z + dz));
                }
            }
            closest.sort(Comparator.comparingDouble(pos -> ((pos.x + 0.5D) - playerX) * ((pos.x + 0.5D) - playerX) + ((pos.z + 0.5D) - playerZ) * ((pos.z + 0.5D) - playerZ)));
            for (int i = 0; i < 4; i++) {
                BetterBlockPos possibleSupport = closest.get(i);
                double xDist = Math.abs((possibleSupport.x + 0.5D) - playerX);
                double zDist = Math.abs((possibleSupport.z + 0.5D) - playerZ);
                if (xDist > 0.8 && zDist > 0.8) {
                    // can't possibly be sneaking off of this one, we're too far away
                    continue;
                }
                if (MovementHelper.canWalkOn(ctx, possibleSupport.down()) && MovementHelper.canWalkThrough(ctx, possibleSupport) && MovementHelper.canWalkThrough(ctx, possibleSupport.up())) {
                    // logDebug("Faking path start assuming player is standing off the edge of a block");
                    return possibleSupport;
                }
            }
        } else {
            // we're in the middle of a jump
            if (MovementHelper.canWalkOn(ctx, feet.down().down())) {
                // logDebug("Faking path start assuming player is midair and falling");
                return feet.down();
            }
        }
    }
    return feet;
}
Also used : IPathingBehavior(baritone.api.behavior.IPathingBehavior) Helper(baritone.api.utils.Helper) PathCalculationResult(baritone.api.utils.PathCalculationResult) IGoalRenderPos(baritone.api.utils.interfaces.IGoalRenderPos) MovementHelper(baritone.pathing.movement.MovementHelper) ArrayList(java.util.ArrayList) GoalXZ(baritone.api.pathing.goals.GoalXZ) AStarPathFinder(baritone.pathing.calc.AStarPathFinder) Favoring(baritone.utils.pathing.Favoring) AbstractNodeCostSearch(baritone.pathing.calc.AbstractNodeCostSearch) baritone.api.event.events(baritone.api.event.events) BlockPos(net.minecraft.util.math.BlockPos) CalculationContext(baritone.pathing.movement.CalculationContext) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Goal(baritone.api.pathing.goals.Goal) BetterBlockPos(baritone.api.utils.BetterBlockPos) Objects(java.util.Objects) PathingCommand(baritone.api.process.PathingCommand) PathingCommandContext(baritone.utils.PathingCommandContext) IPath(baritone.api.pathing.calc.IPath) PathRenderer(baritone.utils.PathRenderer) Baritone(baritone.Baritone) Optional(java.util.Optional) PathExecutor(baritone.pathing.path.PathExecutor) Comparator(java.util.Comparator) BetterBlockPos(baritone.api.utils.BetterBlockPos) ArrayList(java.util.ArrayList)

Aggregations

Baritone (baritone.Baritone)2 IPathingBehavior (baritone.api.behavior.IPathingBehavior)2 baritone.api.event.events (baritone.api.event.events)2 IPath (baritone.api.pathing.calc.IPath)2 Goal (baritone.api.pathing.goals.Goal)2 GoalXZ (baritone.api.pathing.goals.GoalXZ)2 PathingCommand (baritone.api.process.PathingCommand)2 BetterBlockPos (baritone.api.utils.BetterBlockPos)2 Helper (baritone.api.utils.Helper)2 PathCalculationResult (baritone.api.utils.PathCalculationResult)2 IGoalRenderPos (baritone.api.utils.interfaces.IGoalRenderPos)2 AStarPathFinder (baritone.pathing.calc.AStarPathFinder)2 AbstractNodeCostSearch (baritone.pathing.calc.AbstractNodeCostSearch)2 CalculationContext (baritone.pathing.movement.CalculationContext)2 MovementHelper (baritone.pathing.movement.MovementHelper)2 PathExecutor (baritone.pathing.path.PathExecutor)2 PathRenderer (baritone.utils.PathRenderer)2 PathingCommandContext (baritone.utils.PathingCommandContext)2 Favoring (baritone.utils.pathing.Favoring)2 ArrayList (java.util.ArrayList)2