Distinguish unexpected exceptions in path calc

This commit is contained in:
Brady
2023-06-21 00:52:43 -05:00
parent cfd9a69052
commit 877fd25608
5 changed files with 64 additions and 18 deletions

View File

@@ -23,6 +23,7 @@ import baritone.api.event.events.*;
import baritone.api.utils.*;
import baritone.behavior.elytra.NetherPathfinderContext;
import baritone.behavior.elytra.NetherPath;
import baritone.behavior.elytra.PathCalculationException;
import baritone.behavior.elytra.UnpackedSegment;
import baritone.utils.BlockStateInterface;
import baritone.utils.accessor.IEntityFireworkRocket;
@@ -108,7 +109,7 @@ public final class ElytraBehavior extends Behavior implements IElytraBehavior, H
this.attemptNextSegment();
}
public void pathToDestination(BlockPos destination) {
public void pathToDestination(final BlockPos destination) {
this.destination = destination;
final long start = System.nanoTime();
this.path0(ctx.playerFeet(), destination, UnaryOperator.identity())
@@ -123,7 +124,11 @@ public final class ElytraBehavior extends Behavior implements IElytraBehavior, H
.whenComplete((result, ex) -> {
this.recalculating = false;
if (ex != null) {
logDirect("Failed to compute path to destination");
if (ex instanceof PathCalculationException) {
logDirect("Failed to compute path to destination");
} else {
logUnhandledException(ex);
}
}
});
}
@@ -141,7 +146,11 @@ public final class ElytraBehavior extends Behavior implements IElytraBehavior, H
.whenComplete((result, ex) -> {
this.recalculating = false;
if (ex != null) {
logDirect("Failed to recompute segment");
if (ex instanceof PathCalculationException) {
logDirect("Failed to recompute segment");
} else {
logUnhandledException(ex);
}
}
});
}
@@ -168,8 +177,10 @@ public final class ElytraBehavior extends Behavior implements IElytraBehavior, H
})
.whenComplete((result, ex) -> {
this.recalculating = false;
if (ex != null) {
if (ex instanceof PathCalculationException) {
logDirect("Failed to compute next segment");
} else {
logUnhandledException(ex);
}
});
}

View File

@@ -52,14 +52,19 @@ public final class NetherPathfinderContext {
}
public CompletableFuture<PathSegment> pathFindAsync(final BlockPos src, final BlockPos dst) {
return CompletableFuture.supplyAsync(() ->
NetherPathfinder.pathFind(
this.context,
src.getX(), src.getY(), src.getZ(),
dst.getX(), dst.getY(), dst.getZ(),
true,
10000
), this.executor);
return CompletableFuture.supplyAsync(() -> {
final PathSegment segment = NetherPathfinder.pathFind(
this.context,
src.getX(), src.getY(), src.getZ(),
dst.getX(), dst.getY(), dst.getZ(),
true,
10000
);
if (segment == null) {
throw new PathCalculationException("Path calculation failed");
}
return segment;
}, this.executor);
}
/**

View File

@@ -0,0 +1,28 @@
/*
* This file is part of Baritone.
*
* Baritone is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Baritone is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/
package baritone.behavior.elytra;
/**
* @author Brady
*/
public final class PathCalculationException extends RuntimeException {
public PathCalculationException(final String message) {
super(message);
}
}