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);
}
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);
}
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;
}
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));
}
}
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;
}
Aggregations