Skip to content

Commit

Permalink
Merge branch '1.19.4' into 1.20.1
Browse files Browse the repository at this point in the history
  • Loading branch information
leijurv committed Aug 22, 2023
2 parents 3b30b06 + 2cd5c6b commit 97067b9
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions src/main/java/baritone/process/elytra/ElytraBehavior.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import baritone.api.event.events.*;
import baritone.api.pathing.goals.GoalBlock;
import baritone.api.utils.*;
import baritone.api.utils.input.Input;
import baritone.pathing.movement.MovementHelper;
import baritone.process.ElytraProcess;
import baritone.utils.BlockStateInterface;
Expand Down Expand Up @@ -103,7 +104,7 @@ public final class ElytraBehavior implements Helper {

private BlockStateInterface bsi;
private final BlockStateOctreeInterface boi;
public final BlockPos destination;
public final BetterBlockPos destination;
private final boolean appendDestination;

private final ExecutorService solverExecutor;
Expand All @@ -124,7 +125,7 @@ public ElytraBehavior(Baritone baritone, ElytraProcess process, BlockPos destina
this.blockedLines = new CopyOnWriteArrayList<>();
this.pathManager = this.new PathManager();
this.process = process;
this.destination = destination;
this.destination = new BetterBlockPos(destination);
this.appendDestination = appendDestination;
this.solverExecutor = Executors.newSingleThreadExecutor();
this.nextTickBoostCounter = new int[2];
Expand Down Expand Up @@ -193,16 +194,16 @@ public CompletableFuture<Void> pathToDestination(final BlockPos from) {
});
}

public CompletableFuture<Void> pathRecalcSegment(final int upToIncl) {
public CompletableFuture<Void> pathRecalcSegment(final OptionalInt upToIncl) {
if (this.recalculating) {
throw new IllegalStateException("already recalculating");
}

this.recalculating = true;
final List<BetterBlockPos> after = this.path.subList(upToIncl + 1, this.path.size());
final List<BetterBlockPos> after = upToIncl.isPresent() ? this.path.subList(upToIncl.getAsInt() + 1, this.path.size()) : Collections.emptyList();
final boolean complete = this.completePath;

return this.path0(ctx.playerFeet(), this.path.get(upToIncl), segment -> segment.append(after.stream(), complete))
return this.path0(ctx.playerFeet(), upToIncl.isPresent() ? this.path.get(upToIncl.getAsInt()) : ElytraBehavior.this.destination, segment -> segment.append(after.stream(), complete || (segment.isFinished() && !upToIncl.isPresent())))
.whenComplete((result, ex) -> {
this.recalculating = false;
if (ex != null) {
Expand Down Expand Up @@ -320,7 +321,7 @@ private void pathfindAroundObstacles() {
}

if (ElytraBehavior.this.process.state != ElytraProcess.State.LANDING && this.ticksNearUnchanged > 100) {
this.pathRecalcSegment(rangeEndExcl - 1)
this.pathRecalcSegment(OptionalInt.of(rangeEndExcl - 1))
.thenRun(() -> {
logDirect("Recalculating segment, no progress in last 100 ticks");
});
Expand All @@ -336,15 +337,15 @@ private void pathfindAroundObstacles() {
if (!ElytraBehavior.this.clearView(this.path.getVec(i), this.path.getVec(i + 1), false)) {
// obstacle. where do we return to pathing?
// if the end of render distance is closer to goal, then that's fine, otherwise we'd be "digging our hole deeper" and making an already bad backtrack worse
int rejoinMainPathAt;
if (this.path.get(rangeEndExcl - 1).distanceSq(this.path.get(path.size() - 1)) < ctx.playerFeet().distanceSq(this.path.get(path.size() - 1))) {
rejoinMainPathAt = rangeEndExcl - 1; // rejoin after current render distance
OptionalInt rejoinMainPathAt;
if (this.path.get(rangeEndExcl - 1).distanceSq(ElytraBehavior.this.destination) < ctx.playerFeet().distanceSq(ElytraBehavior.this.destination)) {
rejoinMainPathAt = OptionalInt.of(rangeEndExcl - 1); // rejoin after current render distance
} else {
rejoinMainPathAt = path.size() - 1; // large backtrack detected. ignore render distance, rejoin later on
rejoinMainPathAt = OptionalInt.empty(); // large backtrack detected. ignore render distance, rejoin later on
}

final BetterBlockPos blockage = this.path.get(i);
final double distance = ctx.playerFeet().distanceTo(this.path.get(rejoinMainPathAt));
final double distance = ctx.playerFeet().distanceTo(this.path.get(rejoinMainPathAt.orElse(path.size() - 1)));

final long start = System.nanoTime();
this.pathRecalcSegment(rejoinMainPathAt)
Expand All @@ -361,7 +362,7 @@ private void pathfindAroundObstacles() {
}
}
if (!canSeeAny && rangeStartIncl < rangeEndExcl - 2 && process.state != ElytraProcess.State.GET_TO_JUMP) {
this.pathRecalcSegment(rangeEndExcl - 1).thenRun(() -> logDirect("Recalculated segment since no path points were visible"));
this.pathRecalcSegment(OptionalInt.of(rangeEndExcl - 1)).thenRun(() -> logDirect("Recalculated segment since no path points were visible"));
}
}

Expand Down Expand Up @@ -604,6 +605,11 @@ public void tick() {
this.deployedFireworkLastTick = false;
}

final boolean inLava = ctx.player().isInLava();
if (inLava) {
baritone.getInputOverrideHandler().setInputForceState(Input.JUMP, true);
}

if (solution == null) {
logDirect("no solution");
return;
Expand All @@ -622,7 +628,7 @@ public void tick() {
solution.context.start,
solution.goingTo,
solution.context.boost.isBoosted(),
solution.forceUseFirework
solution.forceUseFirework || inLava
);
}

Expand Down Expand Up @@ -1004,7 +1010,7 @@ public boolean clearView(Vec3 start, Vec3 dest, boolean ignoreLava) {
// if start == dest then the cpp raytracer dies
clear = start.equals(dest) || this.context.raytrace(start, dest);
} else {
clear = ctx.world().clip(new ClipContext(start, dest, ClipContext.Block.COLLIDER, ClipContext.Fluid.ANY, ctx.player())).getType() == HitResult.Type.MISS;
clear = ctx.world().clip(new ClipContext(start, dest, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, ctx.player())).getType() == HitResult.Type.MISS;
}

if (Baritone.settings().elytraRenderRaytraces.value) {
Expand Down

0 comments on commit 97067b9

Please sign in to comment.