@@ -98,7 +98,7 @@ public final class ElytraBehavior implements Helper {
9898
9999 private BlockStateInterface bsi ;
100100 private final BlockStateOctreeInterface boi ;
101- public final BlockPos destination ;
101+ public final BetterBlockPos destination ;
102102 private final boolean appendDestination ;
103103
104104 private final ExecutorService solverExecutor ;
@@ -119,7 +119,7 @@ public ElytraBehavior(Baritone baritone, ElytraProcess process, BlockPos destina
119119 this .blockedLines = new CopyOnWriteArrayList <>();
120120 this .pathManager = this .new PathManager ();
121121 this .process = process ;
122- this .destination = destination ;
122+ this .destination = new BetterBlockPos ( destination ) ;
123123 this .appendDestination = appendDestination ;
124124 this .solverExecutor = Executors .newSingleThreadExecutor ();
125125 this .nextTickBoostCounter = new int [2 ];
@@ -188,16 +188,16 @@ public CompletableFuture<Void> pathToDestination(final BlockPos from) {
188188 });
189189 }
190190
191- public CompletableFuture <Void > pathRecalcSegment (final int upToIncl ) {
191+ public CompletableFuture <Void > pathRecalcSegment (final OptionalInt upToIncl ) {
192192 if (this .recalculating ) {
193193 throw new IllegalStateException ("already recalculating" );
194194 }
195195
196196 this .recalculating = true ;
197- final List <BetterBlockPos > after = this .path .subList (upToIncl + 1 , this .path .size ());
197+ final List <BetterBlockPos > after = upToIncl . isPresent () ? this .path .subList (upToIncl . getAsInt () + 1 , this .path .size ()) : Collections . emptyList ( );
198198 final boolean complete = this .completePath ;
199199
200- return this .path0 (ctx .playerFeet (), this .path .get (upToIncl ) , segment -> segment .append (after .stream (), complete ))
200+ 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 ()) ))
201201 .whenComplete ((result , ex ) -> {
202202 this .recalculating = false ;
203203 if (ex != null ) {
@@ -315,7 +315,7 @@ private void pathfindAroundObstacles() {
315315 }
316316
317317 if (ElytraBehavior .this .process .state != ElytraProcess .State .LANDING && this .ticksNearUnchanged > 100 ) {
318- this .pathRecalcSegment (rangeEndExcl - 1 )
318+ this .pathRecalcSegment (OptionalInt . of ( rangeEndExcl - 1 ) )
319319 .thenRun (() -> {
320320 logDirect ("Recalculating segment, no progress in last 100 ticks" );
321321 });
@@ -331,15 +331,15 @@ private void pathfindAroundObstacles() {
331331 if (!ElytraBehavior .this .clearView (this .path .getVec (i ), this .path .getVec (i + 1 ), false )) {
332332 // obstacle. where do we return to pathing?
333333 // 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
334- int rejoinMainPathAt ;
335- if (this .path .get (rangeEndExcl - 1 ).distanceSq (this .path . get ( path . size () - 1 )) < ctx .playerFeet ().distanceSq (this .path . get ( path . size () - 1 ) )) {
336- rejoinMainPathAt = rangeEndExcl - 1 ; // rejoin after current render distance
334+ OptionalInt rejoinMainPathAt ;
335+ if (this .path .get (rangeEndExcl - 1 ).distanceSq (ElytraBehavior . this .destination ) < ctx .playerFeet ().distanceSq (ElytraBehavior . this .destination )) {
336+ rejoinMainPathAt = OptionalInt . of ( rangeEndExcl - 1 ) ; // rejoin after current render distance
337337 } else {
338- rejoinMainPathAt = path . size () - 1 ; // large backtrack detected. ignore render distance, rejoin later on
338+ rejoinMainPathAt = OptionalInt . empty () ; // large backtrack detected. ignore render distance, rejoin later on
339339 }
340340
341341 final BetterBlockPos blockage = this .path .get (i );
342- final double distance = ctx .playerFeet ().distanceTo (this .path .get (rejoinMainPathAt ));
342+ final double distance = ctx .playerFeet ().distanceTo (this .path .get (rejoinMainPathAt . orElse ( path . size () - 1 ) ));
343343
344344 final long start = System .nanoTime ();
345345 this .pathRecalcSegment (rejoinMainPathAt )
@@ -356,7 +356,7 @@ private void pathfindAroundObstacles() {
356356 }
357357 }
358358 if (!canSeeAny && rangeStartIncl < rangeEndExcl - 2 && process .state != ElytraProcess .State .GET_TO_JUMP ) {
359- this .pathRecalcSegment (rangeEndExcl - 1 ).thenRun (() -> logDirect ("Recalculated segment since no path points were visible" ));
359+ this .pathRecalcSegment (OptionalInt . of ( rangeEndExcl - 1 ) ).thenRun (() -> logDirect ("Recalculated segment since no path points were visible" ));
360360 }
361361 }
362362
0 commit comments