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.ICommand;
|
||||||
import baritone.api.command.argument.ICommandArgument;
|
import baritone.api.command.argument.ICommandArgument;
|
||||||
import net.minecraft.util.text.TextFormatting;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -37,10 +36,6 @@ public class CommandUnhandledException extends RuntimeException implements IComm
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(ICommand command, List<ICommandArgument> args) {
|
public void handle(ICommand command, List<ICommandArgument> args) {
|
||||||
HELPER.logDirect("An unhandled exception occurred. " +
|
HELPER.logUnhandledException(this);
|
||||||
"The error is in your game's log, please report this at https://github.com/cabaletta/baritone/issues",
|
|
||||||
TextFormatting.RED);
|
|
||||||
|
|
||||||
this.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -230,4 +230,11 @@ public interface Helper {
|
||||||
default void logDirect(String message) {
|
default void logDirect(String message) {
|
||||||
logDirect(message, BaritoneAPI.getSettings().logAsToast.value);
|
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.api.utils.*;
|
||||||
import baritone.behavior.elytra.NetherPathfinderContext;
|
import baritone.behavior.elytra.NetherPathfinderContext;
|
||||||
import baritone.behavior.elytra.NetherPath;
|
import baritone.behavior.elytra.NetherPath;
|
||||||
|
import baritone.behavior.elytra.PathCalculationException;
|
||||||
import baritone.behavior.elytra.UnpackedSegment;
|
import baritone.behavior.elytra.UnpackedSegment;
|
||||||
import baritone.utils.BlockStateInterface;
|
import baritone.utils.BlockStateInterface;
|
||||||
import baritone.utils.accessor.IEntityFireworkRocket;
|
import baritone.utils.accessor.IEntityFireworkRocket;
|
||||||
|
@ -108,7 +109,7 @@ public final class ElytraBehavior extends Behavior implements IElytraBehavior, H
|
||||||
this.attemptNextSegment();
|
this.attemptNextSegment();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void pathToDestination(BlockPos destination) {
|
public void pathToDestination(final BlockPos destination) {
|
||||||
this.destination = destination;
|
this.destination = destination;
|
||||||
final long start = System.nanoTime();
|
final long start = System.nanoTime();
|
||||||
this.path0(ctx.playerFeet(), destination, UnaryOperator.identity())
|
this.path0(ctx.playerFeet(), destination, UnaryOperator.identity())
|
||||||
|
@ -123,7 +124,11 @@ public final class ElytraBehavior extends Behavior implements IElytraBehavior, H
|
||||||
.whenComplete((result, ex) -> {
|
.whenComplete((result, ex) -> {
|
||||||
this.recalculating = false;
|
this.recalculating = false;
|
||||||
if (ex != null) {
|
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) -> {
|
.whenComplete((result, ex) -> {
|
||||||
this.recalculating = false;
|
this.recalculating = false;
|
||||||
if (ex != null) {
|
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) -> {
|
.whenComplete((result, ex) -> {
|
||||||
this.recalculating = false;
|
this.recalculating = false;
|
||||||
if (ex != null) {
|
if (ex instanceof PathCalculationException) {
|
||||||
logDirect("Failed to compute next segment");
|
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) {
|
public CompletableFuture<PathSegment> pathFindAsync(final BlockPos src, final BlockPos dst) {
|
||||||
return CompletableFuture.supplyAsync(() ->
|
return CompletableFuture.supplyAsync(() -> {
|
||||||
NetherPathfinder.pathFind(
|
final PathSegment segment = NetherPathfinder.pathFind(
|
||||||
this.context,
|
this.context,
|
||||||
src.getX(), src.getY(), src.getZ(),
|
src.getX(), src.getY(), src.getZ(),
|
||||||
dst.getX(), dst.getY(), dst.getZ(),
|
dst.getX(), dst.getY(), dst.getZ(),
|
||||||
true,
|
true,
|
||||||
10000
|
10000
|
||||||
), this.executor);
|
);
|
||||||
|
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