Merge branch 'comms' into calc-request

This commit is contained in:
Leijurv 2018-11-23 13:13:35 -08:00
commit 85a6ec022e
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
7 changed files with 19 additions and 27 deletions

View File

@ -247,7 +247,9 @@ public class Settings {
public Setting<Integer> movementTimeoutTicks = new Setting<>(100);
/**
* Pathing ends after this amount of time, if a path has been found
* Pathing ends after this amount of time, but only if a path has been found
* <p>
* If no valid path (length above the minimum) has been found, pathing continues up until the failure timeout
*/
public Setting<Long> primaryTimeoutMS = new Setting<>(500L);
@ -257,7 +259,9 @@ public class Settings {
public Setting<Long> failureTimeoutMS = new Setting<>(2000L);
/**
* Planning ahead while executing a segment ends after this amount of time, if a path has been found
* Planning ahead while executing a segment ends after this amount of time, but only if a path has been found
* <p>
* If no valid path (length above the minimum) has been found, pathing continues up until the failure timeout
*/
public Setting<Long> planAheadPrimaryTimeoutMS = new Setting<>(4000L);

View File

@ -17,10 +17,7 @@
package baritone.api.pathing.goals;
import net.minecraft.util.math.BlockPos;
import java.util.Arrays;
import java.util.Collection;
/**
* A composite of many goals, any one of which satisfies the composite.
@ -40,14 +37,6 @@ public class GoalComposite implements Goal {
this.goals = goals;
}
public GoalComposite(BlockPos... blocks) {
this(Arrays.asList(blocks));
}
public GoalComposite(Collection<BlockPos> blocks) {
this(blocks.stream().map(GoalBlock::new).toArray(Goal[]::new));
}
@Override
public boolean isInGoal(int x, int y, int z) {
for (Goal goal : goals) {

View File

@ -48,10 +48,7 @@ public class GoalGetToBlock implements Goal, IGoalRenderPos {
int xDiff = x - this.x;
int yDiff = y - this.y;
int zDiff = z - this.z;
if (yDiff < 0) {
yDiff++;
}
return Math.abs(xDiff) + Math.abs(yDiff) + Math.abs(zDiff) <= 1;
return Math.abs(xDiff) + Math.abs(yDiff < 0 ? yDiff + 1 : yDiff) + Math.abs(zDiff) <= 1;
}
@Override
@ -59,7 +56,7 @@ public class GoalGetToBlock implements Goal, IGoalRenderPos {
int xDiff = x - this.x;
int yDiff = y - this.y;
int zDiff = z - this.z;
return GoalBlock.calculate(xDiff, yDiff, zDiff);
return GoalBlock.calculate(xDiff, yDiff < 0 ? yDiff + 1 : yDiff, zDiff);
}
@Override

View File

@ -63,10 +63,7 @@ public class GoalTwoBlocks implements Goal, IGoalRenderPos {
int xDiff = x - this.x;
int yDiff = y - this.y;
int zDiff = z - this.z;
if (yDiff < 0) {
yDiff++;
}
return GoalBlock.calculate(xDiff, yDiff, zDiff);
return GoalBlock.calculate(xDiff, yDiff < 0 ? yDiff + 1 : yDiff, zDiff);
}
@Override

View File

@ -92,7 +92,8 @@ public final class ChunkPacker {
for (int z = 0; z < 16; z++) {
// @formatter:off
https://www.ibm.com/developerworks/library/j-perry-writing-good-java-code/index.html
https:
//www.ibm.com/developerworks/library/j-perry-writing-good-java-code/index.html
// @formatter:on
for (int x = 0; x < 16; x++) {
for (int y = 255; y >= 0; y--) {
@ -124,7 +125,7 @@ public final class ChunkPacker {
private static PathingBlockType getPathingBlockType(IBlockState state) {
Block block = state.getBlock();
if (block.equals(Blocks.WATER) && !MovementHelper.isFlowing(state)) {
if (block == Blocks.WATER && !MovementHelper.isFlowing(state)) {
// only water source blocks are plausibly usable, flowing water should be avoid
return PathingBlockType.WATER;
}

View File

@ -88,7 +88,7 @@ public abstract class AbstractNodeCostSearch implements IPathFinder {
if (isFinished) {
throw new IllegalStateException("Path Finder is currently in use, and cannot be reused!");
}
this.cancelRequested = false;
cancelRequested = false;
try {
IPath path = calculate0(primaryTimeout, failureTimeout).map(IPath::postProcess).orElse(null);
isFinished = true;

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
}
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(() -> {
Optional<IPath> result;
try {
@ -81,7 +81,11 @@ public class SegmentedCalculator {
ex.printStackTrace();
result = Optional.empty();
}
onCompletion.accept(result);
if (result.isPresent()) {
onCompletion.accept(result.get());
} else {
onFailure.run();
}
});
}
}