Some clean ups
This commit is contained in:
parent
f0210f7c5f
commit
4c4bc8058b
@ -86,8 +86,7 @@ public final class AStarPathFinder extends AbstractNodeCostSearch {
|
||||
if (slowPath) {
|
||||
try {
|
||||
Thread.sleep(Baritone.settings().slowPathTimeDelayMS.value);
|
||||
} catch (InterruptedException ex) {
|
||||
}
|
||||
} catch (InterruptedException ignored) {}
|
||||
}
|
||||
PathNode currentNode = openSet.removeLowest();
|
||||
mostRecentConsidered = currentNode;
|
||||
|
@ -96,7 +96,7 @@ class Path extends PathBase {
|
||||
}
|
||||
PathNode current = end;
|
||||
LinkedList<BetterBlockPos> tempPath = new LinkedList<>();
|
||||
LinkedList<PathNode> tempNodes = new LinkedList();
|
||||
LinkedList<PathNode> tempNodes = new LinkedList<>();
|
||||
// Repeatedly inserting to the beginning of an arraylist is O(n^2)
|
||||
// Instead, do it into a linked list, then convert at the end
|
||||
while (current != null) {
|
||||
|
@ -64,10 +64,13 @@ public class Avoidance {
|
||||
double mobSpawnerCoeff = Baritone.settings().mobSpawnerAvoidanceCoefficient.value;
|
||||
double mobCoeff = Baritone.settings().mobAvoidanceCoefficient.value;
|
||||
if (mobSpawnerCoeff != 1.0D) {
|
||||
ctx.worldData().getCachedWorld().getLocationsOf("mob_spawner", 1, ctx.playerFeet().x, ctx.playerFeet().z, 2).forEach(mobspawner -> res.add(new Avoidance(mobspawner, mobSpawnerCoeff, Baritone.settings().mobSpawnerAvoidanceRadius.value)));
|
||||
ctx.worldData().getCachedWorld().getLocationsOf("mob_spawner", 1, ctx.playerFeet().x, ctx.playerFeet().z, 2)
|
||||
.forEach(mobspawner -> res.add(new Avoidance(mobspawner, mobSpawnerCoeff, Baritone.settings().mobSpawnerAvoidanceRadius.value)));
|
||||
}
|
||||
if (mobCoeff != 1.0D) {
|
||||
ctx.world().loadedEntityList.stream().filter(entity -> entity instanceof EntityMob).forEach(entity -> res.add(new Avoidance(new BlockPos(entity), mobCoeff, Baritone.settings().mobAvoidanceRadius.value)));
|
||||
ctx.world().loadedEntityList.stream()
|
||||
.filter(entity -> entity instanceof EntityMob)
|
||||
.forEach(entity -> res.add(new Avoidance(new BlockPos(entity), mobCoeff, Baritone.settings().mobAvoidanceRadius.value)));
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ public class SegmentedCalculator {
|
||||
private Optional<IPath> doCalc() {
|
||||
Optional<IPath> soFar = Optional.empty();
|
||||
while (true) {
|
||||
PathCalculationResult result = segment(soFar);
|
||||
PathCalculationResult result = segment(soFar.orElse(null));
|
||||
switch (result.getType()) {
|
||||
case SUCCESS_SEGMENT:
|
||||
case SUCCESS_TO_GOAL:
|
||||
@ -62,8 +62,8 @@ public class SegmentedCalculator {
|
||||
default: // CANCELLATION and null should not be possible, nothing else has access to this, so it can't have been canceled
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
IPath segment = result.getPath().get(); // path calculation result type is SUCCESS_SEGMENT, so the path must be present
|
||||
IPath combined = soFar.map(previous -> (IPath) SplicedPath.trySplice(previous, segment, true).get()).orElse(segment);
|
||||
IPath segment = result.getPath().orElseThrow(IllegalStateException::new); // path calculation result type is SUCCESS_SEGMENT, so the path must be present
|
||||
IPath combined = soFar.map(previous -> (IPath) SplicedPath.trySplice(previous, segment, true).orElseThrow(IllegalStateException::new)).orElse(segment);
|
||||
loadAdjacent(combined.getDest().getX(), combined.getDest().getZ());
|
||||
soFar = Optional.of(combined);
|
||||
if (result.getType() == PathCalculationResult.Type.SUCCESS_TO_GOAL) {
|
||||
@ -85,9 +85,9 @@ public class SegmentedCalculator {
|
||||
}
|
||||
}
|
||||
|
||||
private PathCalculationResult segment(Optional<IPath> previous) {
|
||||
BetterBlockPos segmentStart = previous.map(IPath::getDest).orElse(start); // <-- e p i c
|
||||
AbstractNodeCostSearch search = new AStarPathFinder(segmentStart.x, segmentStart.y, segmentStart.z, goal, new Favoring(previous.orElse(null), context), context); // this is on another thread, so cannot include mob avoidances.
|
||||
private PathCalculationResult segment(IPath previous) {
|
||||
BetterBlockPos segmentStart = previous != null ? previous.getDest() : start;
|
||||
AbstractNodeCostSearch search = new AStarPathFinder(segmentStart.x, segmentStart.y, segmentStart.z, goal, new Favoring(previous, context), context); // this is on another thread, so cannot include mob avoidances.
|
||||
return search.calculate(Baritone.settings().primaryTimeoutMS.value, Baritone.settings().failureTimeoutMS.value); // use normal time settings, not the plan ahead settings, so as to not overwhelm the computer
|
||||
}
|
||||
|
||||
|
@ -50,14 +50,14 @@ public class OpenSetsTest {
|
||||
return testSizes;
|
||||
}
|
||||
|
||||
private static void removeAndTest(int amount, IOpenSet[] test, Optional<Collection<PathNode>> mustContain) {
|
||||
private static void removeAndTest(int amount, IOpenSet[] test, Collection<PathNode> mustContain) {
|
||||
double[][] results = new double[test.length][amount];
|
||||
for (int i = 0; i < test.length; i++) {
|
||||
long before = System.nanoTime() / 1000000L;
|
||||
for (int j = 0; j < amount; j++) {
|
||||
PathNode pn = test[i].removeLowest();
|
||||
if (mustContain.isPresent() && !mustContain.get().contains(pn)) {
|
||||
throw new IllegalStateException(mustContain.get() + " " + pn);
|
||||
if (mustContain != null && !mustContain.contains(pn)) {
|
||||
throw new IllegalStateException(mustContain + " " + pn);
|
||||
}
|
||||
results[i][j] = pn.combinedCost;
|
||||
}
|
||||
@ -131,7 +131,7 @@ public class OpenSetsTest {
|
||||
|
||||
System.out.println("Removal round 1");
|
||||
// remove a quarter of the nodes and verify that they are indeed the size/4 lowest ones
|
||||
removeAndTest(size / 4, test, Optional.of(lowestQuarter));
|
||||
removeAndTest(size / 4, test, lowestQuarter);
|
||||
|
||||
// none of them should be empty (sanity check)
|
||||
for (IOpenSet set : test) {
|
||||
@ -160,7 +160,7 @@ public class OpenSetsTest {
|
||||
|
||||
System.out.println("Removal round 2");
|
||||
// remove the remaining 3/4
|
||||
removeAndTest(size - size / 4, test, Optional.empty());
|
||||
removeAndTest(size - size / 4, test, null);
|
||||
|
||||
// every set should now be empty
|
||||
for (IOpenSet set : test) {
|
||||
|
Loading…
Reference in New Issue
Block a user