more robust path destination verification
This commit is contained in:
parent
a38da64c49
commit
001070d406
@ -28,5 +28,6 @@ public enum PathEvent {
|
|||||||
AT_GOAL,
|
AT_GOAL,
|
||||||
PATH_FINISHED_NEXT_STILL_CALCULATING,
|
PATH_FINISHED_NEXT_STILL_CALCULATING,
|
||||||
NEXT_CALC_FAILED,
|
NEXT_CALC_FAILED,
|
||||||
DISCARD_NEXT
|
DISCARD_NEXT,
|
||||||
|
CANCELED;
|
||||||
}
|
}
|
||||||
|
@ -24,9 +24,16 @@ public final class TickEvent {
|
|||||||
private final EventState state;
|
private final EventState state;
|
||||||
private final Type type;
|
private final Type type;
|
||||||
|
|
||||||
|
private static int count;
|
||||||
|
|
||||||
public TickEvent(EventState state, Type type) {
|
public TickEvent(EventState state, Type type) {
|
||||||
this.state = state;
|
this.state = state;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCount() {
|
||||||
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Type getType() {
|
public Type getType() {
|
||||||
|
@ -17,8 +17,9 @@
|
|||||||
|
|
||||||
package baritone.behavior;
|
package baritone.behavior;
|
||||||
|
|
||||||
import baritone.api.event.events.PathEvent;
|
|
||||||
import baritone.api.behavior.Behavior;
|
import baritone.api.behavior.Behavior;
|
||||||
|
import baritone.api.event.events.PathEvent;
|
||||||
|
import baritone.api.event.events.TickEvent;
|
||||||
import baritone.cache.CachedChunk;
|
import baritone.cache.CachedChunk;
|
||||||
import baritone.cache.ChunkPacker;
|
import baritone.cache.ChunkPacker;
|
||||||
import baritone.cache.WorldProvider;
|
import baritone.cache.WorldProvider;
|
||||||
@ -26,16 +27,14 @@ import baritone.cache.WorldScanner;
|
|||||||
import baritone.pathing.goals.Goal;
|
import baritone.pathing.goals.Goal;
|
||||||
import baritone.pathing.goals.GoalComposite;
|
import baritone.pathing.goals.GoalComposite;
|
||||||
import baritone.pathing.goals.GoalTwoBlocks;
|
import baritone.pathing.goals.GoalTwoBlocks;
|
||||||
|
import baritone.pathing.path.IPath;
|
||||||
import baritone.utils.BlockStateInterface;
|
import baritone.utils.BlockStateInterface;
|
||||||
import baritone.utils.Helper;
|
import baritone.utils.Helper;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
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.Arrays;
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -52,6 +51,31 @@ public final class MineBehavior extends Behavior implements Helper {
|
|||||||
|
|
||||||
private List<Block> mining;
|
private List<Block> mining;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTick(TickEvent event) {
|
||||||
|
if (mining == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (event.getCount() % 5 == 0) {
|
||||||
|
updateGoal();
|
||||||
|
}
|
||||||
|
Optional<IPath> path = PathingBehavior.INSTANCE.getPath();
|
||||||
|
if (!path.isPresent()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Goal currentGoal = PathingBehavior.INSTANCE.getGoal();
|
||||||
|
if (currentGoal == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Goal intended = path.get().getGoal();
|
||||||
|
BlockPos end = path.get().getDest();
|
||||||
|
if (intended.isInGoal(end) && !currentGoal.isInGoal(end)) {
|
||||||
|
// this path used to end in the goal
|
||||||
|
// but the goal has changed, so there's no reason to continue...
|
||||||
|
PathingBehavior.INSTANCE.cancel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPathEvent(PathEvent event) {
|
public void onPathEvent(PathEvent event) {
|
||||||
updateGoal();
|
updateGoal();
|
||||||
@ -113,7 +137,7 @@ public final class MineBehavior extends Behavior implements Helper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void cancel() {
|
public void cancel() {
|
||||||
PathingBehavior.INSTANCE.cancel();
|
|
||||||
mine((String[]) null);
|
mine((String[]) null);
|
||||||
|
PathingBehavior.INSTANCE.cancel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -103,7 +103,7 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper {
|
|||||||
if (goal.isInGoal(currentNodePos)) {
|
if (goal.isInGoal(currentNodePos)) {
|
||||||
currentlyRunning = null;
|
currentlyRunning = null;
|
||||||
logDebug("Took " + (System.nanoTime() / 1000000L - startTime) + "ms, " + numMovementsConsidered + " movements considered");
|
logDebug("Took " + (System.nanoTime() / 1000000L - startTime) + "ms, " + numMovementsConsidered + " movements considered");
|
||||||
return Optional.of(new Path(startNode, currentNode, numNodes));
|
return Optional.of(new Path(startNode, currentNode, numNodes, goal));
|
||||||
}
|
}
|
||||||
Movement[] possibleMovements = getConnectedPositions(currentNodePos, calcContext);//movement that we could take that start at currentNodePos, in random order
|
Movement[] possibleMovements = getConnectedPositions(currentNodePos, calcContext);//movement that we could take that start at currentNodePos, in random order
|
||||||
shuffle(possibleMovements);
|
shuffle(possibleMovements);
|
||||||
@ -199,7 +199,7 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper {
|
|||||||
}
|
}
|
||||||
System.out.println("Path goes for " + Math.sqrt(dist) + " blocks");
|
System.out.println("Path goes for " + Math.sqrt(dist) + " blocks");
|
||||||
currentlyRunning = null;
|
currentlyRunning = null;
|
||||||
return Optional.of(new Path(startNode, bestSoFar[i], numNodes));
|
return Optional.of(new Path(startNode, bestSoFar[i], numNodes, goal));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
logDebug("Even with a cost coefficient of " + COEFFICIENTS[COEFFICIENTS.length - 1] + ", I couldn't get more than " + Math.sqrt(bestDist) + " blocks");
|
logDebug("Even with a cost coefficient of " + COEFFICIENTS[COEFFICIENTS.length - 1] + ", I couldn't get more than " + Math.sqrt(bestDist) + " blocks");
|
||||||
|
@ -140,7 +140,7 @@ public abstract class AbstractNodeCostSearch implements IPathFinder {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<IPath> pathToMostRecentNodeConsidered() {
|
public Optional<IPath> pathToMostRecentNodeConsidered() {
|
||||||
return Optional.ofNullable(mostRecentConsidered).map(node -> new Path(startNode, node, 0));
|
return Optional.ofNullable(mostRecentConsidered).map(node -> new Path(startNode, node, 0, goal));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -153,7 +153,7 @@ public abstract class AbstractNodeCostSearch implements IPathFinder {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (getDistFromStartSq(bestSoFar[i]) > MIN_DIST_PATH * MIN_DIST_PATH) { // square the comparison since distFromStartSq is squared
|
if (getDistFromStartSq(bestSoFar[i]) > MIN_DIST_PATH * MIN_DIST_PATH) { // square the comparison since distFromStartSq is squared
|
||||||
return Optional.of(new Path(startNode, bestSoFar[i], 0));
|
return Optional.of(new Path(startNode, bestSoFar[i], 0, goal));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// instead of returning bestSoFar[0], be less misleading
|
// instead of returning bestSoFar[0], be less misleading
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
package baritone.pathing.calc;
|
package baritone.pathing.calc;
|
||||||
|
|
||||||
|
import baritone.pathing.goals.Goal;
|
||||||
import baritone.pathing.movement.Movement;
|
import baritone.pathing.movement.Movement;
|
||||||
import baritone.pathing.path.IPath;
|
import baritone.pathing.path.IPath;
|
||||||
import baritone.utils.pathing.BetterBlockPos;
|
import baritone.utils.pathing.BetterBlockPos;
|
||||||
@ -52,19 +53,27 @@ class Path implements IPath {
|
|||||||
|
|
||||||
final List<Movement> movements;
|
final List<Movement> movements;
|
||||||
|
|
||||||
|
final Goal goal;
|
||||||
|
|
||||||
private final int numNodes;
|
private final int numNodes;
|
||||||
|
|
||||||
private volatile boolean verified;
|
private volatile boolean verified;
|
||||||
|
|
||||||
Path(PathNode start, PathNode end, int numNodes) {
|
Path(PathNode start, PathNode end, int numNodes, Goal goal) {
|
||||||
this.start = start.pos;
|
this.start = start.pos;
|
||||||
this.end = end.pos;
|
this.end = end.pos;
|
||||||
this.numNodes = numNodes;
|
this.numNodes = numNodes;
|
||||||
this.path = new ArrayList<>();
|
this.path = new ArrayList<>();
|
||||||
this.movements = new ArrayList<>();
|
this.movements = new ArrayList<>();
|
||||||
|
this.goal = goal;
|
||||||
assemblePath(start, end);
|
assemblePath(start, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Goal getGoal() {
|
||||||
|
return goal;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assembles this path given the start and end nodes.
|
* Assembles this path given the start and end nodes.
|
||||||
*
|
*
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
package baritone.pathing.path;
|
package baritone.pathing.path;
|
||||||
|
|
||||||
|
import baritone.pathing.goals.Goal;
|
||||||
import baritone.pathing.movement.Movement;
|
import baritone.pathing.movement.Movement;
|
||||||
import baritone.utils.pathing.BetterBlockPos;
|
import baritone.utils.pathing.BetterBlockPos;
|
||||||
|
|
||||||
@ -31,10 +32,18 @@ public class CutoffPath implements IPath {
|
|||||||
|
|
||||||
private final int numNodes;
|
private final int numNodes;
|
||||||
|
|
||||||
|
final Goal goal;
|
||||||
|
|
||||||
public CutoffPath(IPath prev, int lastPositionToInclude) {
|
public CutoffPath(IPath prev, int lastPositionToInclude) {
|
||||||
path = prev.positions().subList(0, lastPositionToInclude + 1);
|
path = prev.positions().subList(0, lastPositionToInclude + 1);
|
||||||
movements = prev.movements().subList(0, lastPositionToInclude + 1);
|
movements = prev.movements().subList(0, lastPositionToInclude + 1);
|
||||||
numNodes = prev.getNumNodesConsidered();
|
numNodes = prev.getNumNodesConsidered();
|
||||||
|
goal = prev.getGoal();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Goal getGoal() {
|
||||||
|
return goal;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -64,6 +64,13 @@ public interface IPath extends Helper {
|
|||||||
return positions().size();
|
return positions().size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* What goal was this path calculated towards?
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Goal getGoal();
|
||||||
|
|
||||||
default Tuple<Double, BlockPos> closestPathPos(double x, double y, double z) {
|
default Tuple<Double, BlockPos> closestPathPos(double x, double y, double z) {
|
||||||
double best = -1;
|
double best = -1;
|
||||||
BlockPos bestPos = null;
|
BlockPos bestPos = null;
|
||||||
|
@ -120,9 +120,9 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (msg.toLowerCase().equals("cancel")) {
|
if (msg.toLowerCase().equals("cancel")) {
|
||||||
PathingBehavior.INSTANCE.cancel();
|
|
||||||
FollowBehavior.INSTANCE.cancel();
|
|
||||||
MineBehavior.INSTANCE.cancel();
|
MineBehavior.INSTANCE.cancel();
|
||||||
|
FollowBehavior.INSTANCE.cancel();
|
||||||
|
PathingBehavior.INSTANCE.cancel();
|
||||||
event.cancel();
|
event.cancel();
|
||||||
logDirect("ok canceled");
|
logDirect("ok canceled");
|
||||||
return;
|
return;
|
||||||
|
Loading…
Reference in New Issue
Block a user