runnable conversion

This commit is contained in:
Leijurv 2018-11-23 13:12:18 -08:00
parent 002c678b4a
commit 9c5274dde4
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
2 changed files with 7 additions and 6 deletions

View File

@ -40,10 +40,7 @@ import baritone.utils.PathRenderer;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.chunk.EmptyChunk; import net.minecraft.world.chunk.EmptyChunk;
import java.util.ArrayList; import java.util.*;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Optional;
import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.LinkedBlockingQueue;
import java.util.stream.Collectors; import java.util.stream.Collectors;

View File

@ -72,7 +72,7 @@ public class SegmentedCalculator {
return search.calculate(Baritone.settings().primaryTimeoutMS.get(), Baritone.settings().failureTimeoutMS.get()); // use normal time settings, not the plan ahead settings, so as to not overwhelm the computer return search.calculate(Baritone.settings().primaryTimeoutMS.get(), Baritone.settings().failureTimeoutMS.get()); // use normal time settings, not the plan ahead settings, so as to not overwhelm the computer
} }
public static void calculateSegmentsThreaded(BetterBlockPos start, Goal goal, CalculationContext context, Consumer<Optional<IPath>> onCompletion) { public static void calculateSegmentsThreaded(BetterBlockPos start, Goal goal, CalculationContext context, Consumer<IPath> onCompletion, Runnable onFailure) {
Baritone.getExecutor().execute(() -> { Baritone.getExecutor().execute(() -> {
Optional<IPath> result; Optional<IPath> result;
try { try {
@ -81,7 +81,11 @@ public class SegmentedCalculator {
ex.printStackTrace(); ex.printStackTrace();
result = Optional.empty(); result = Optional.empty();
} }
onCompletion.accept(result); if (result.isPresent()) {
onCompletion.accept(result.get());
} else {
onFailure.run();
}
}); });
} }
} }