Handle exception to ensure recalculating is reset

This commit is contained in:
Brady
2023-06-17 19:58:19 -05:00
parent 91609f4ebf
commit fcf8cd35d2

View File

@@ -95,7 +95,11 @@ public final class ElytraBehavior extends Behavior implements Helper {
public void pathToDestination(BlockPos destination) {
this.destination = destination;
this.path0(ctx.playerFeet(), destination, UnaryOperator.identity())
.thenRun(() -> {
.whenComplete((__, ex) -> {
if (ex != null) {
logDirect("Failed to compute path to destination");
return;
}
final int distance = (int) this.pathAt(0).distanceTo(this.pathAt(this.path.size() - 1));
if (this.completePath) {
logDirect(String.format("Computed path (%d blocks)", distance));
@@ -115,8 +119,12 @@ public final class ElytraBehavior extends Behavior implements Helper {
final boolean complete = this.completePath;
this.path0(ctx.playerFeet(), this.path.get(upToIncl), segment -> segment.append(after.stream(), complete))
.thenRun(() -> {
.whenComplete((__, ex) -> {
this.recalculating = false;
if (ex != null) {
logDirect("Failed to recompute segment");
return;
}
final int recompute = this.path.size() - after.size() - 1;
final int distance = (int) this.pathAt(0).distanceTo(this.pathAt(recompute));
logDirect(String.format("Recomputed segment (Next %d blocks)", distance));
@@ -132,8 +140,13 @@ public final class ElytraBehavior extends Behavior implements Helper {
final List<BetterBlockPos> before = this.path.subList(0, afterIncl + 1);
this.path0(this.path.get(afterIncl), this.destination, segment -> segment.prepend(before.stream()))
.thenRun(() -> {
.whenComplete((__, ex) -> {
this.recalculating = false;
if (ex != null) {
logDirect("Failed to compute next segment");
return;
}
final int recompute = this.path.size() - before.size() - 1;
final int distance = (int) this.pathAt(0).distanceTo(this.pathAt(recompute));