mirror of https://github.com/cabaletta/baritone
Distinguish unexpected exceptions in path calc
This commit is contained in:
parent
cfd9a69052
commit
877fd25608
|
@ -19,7 +19,6 @@ package baritone.api.command.exception;
|
|||
|
||||
import baritone.api.command.ICommand;
|
||||
import baritone.api.command.argument.ICommandArgument;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -37,10 +36,6 @@ public class CommandUnhandledException extends RuntimeException implements IComm
|
|||
|
||||
@Override
|
||||
public void handle(ICommand command, List<ICommandArgument> args) {
|
||||
HELPER.logDirect("An unhandled exception occurred. " +
|
||||
"The error is in your game's log, please report this at https://github.com/cabaletta/baritone/issues",
|
||||
TextFormatting.RED);
|
||||
|
||||
this.printStackTrace();
|
||||
HELPER.logUnhandledException(this);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -230,4 +230,11 @@ public interface Helper {
|
|||
default void logDirect(String message) {
|
||||
logDirect(message, BaritoneAPI.getSettings().logAsToast.value);
|
||||
}
|
||||
|
||||
default void logUnhandledException(final Throwable exception) {
|
||||
HELPER.logDirect("An unhandled exception occurred. " +
|
||||
"The error is in your game's log, please report this at https://github.com/cabaletta/baritone/issues",
|
||||
TextFormatting.RED);
|
||||
exception.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue