add a method to get the heuristic at the goal
this alows the ETA to work with goals not ending with a heuristic of 0 GoalComposite, GoalRunAway and GoalNear are still missing
This commit is contained in:
parent
10e3a5afc4
commit
45dc8b949d
@ -54,4 +54,18 @@ public interface Goal {
|
|||||||
default double heuristic(BlockPos pos) {
|
default double heuristic(BlockPos pos) {
|
||||||
return heuristic(pos.getX(), pos.getY(), pos.getZ());
|
return heuristic(pos.getX(), pos.getY(), pos.getZ());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the heuristic at the goal.
|
||||||
|
* i.e. {@code heuristic() == heuristic(x,y,z)}
|
||||||
|
* when {@code isInGoal(x,y,z) == true}
|
||||||
|
* This is needed by {@code PathingBehavior#estimatedTicksToGoal} because
|
||||||
|
* some Goals actually do not have a heuristic of 0 when that condition is met
|
||||||
|
*
|
||||||
|
* @return The estimate number of ticks to satisfy the goal when the goal
|
||||||
|
* is already satisfied
|
||||||
|
*/
|
||||||
|
default double heuristic() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,6 +45,11 @@ public class GoalInverted implements Goal {
|
|||||||
return -origin.heuristic(x, y, z);
|
return -origin.heuristic(x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double heuristic() {
|
||||||
|
return Double.NEGATIVE_INFINITY;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return String.format("GoalInverted{%s}", origin.toString());
|
return String.format("GoalInverted{%s}", origin.toString());
|
||||||
|
@ -64,6 +64,11 @@ public class GoalStrictDirection implements Goal {
|
|||||||
return heuristic;
|
return heuristic;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double heuristic() {
|
||||||
|
return Double.NEGATIVE_INFINITY;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return String.format(
|
return String.format(
|
||||||
|
@ -387,7 +387,7 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
|
|||||||
if (current == start) {//can't check above because current and start can be equal even if currentPos and startPosition are not
|
if (current == start) {//can't check above because current and start can be equal even if currentPos and startPosition are not
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
double eta = Math.abs(current) * ticksElapsedSoFar / Math.abs(start - current);
|
double eta = Math.abs(current - goal.heuristic()) * ticksElapsedSoFar / Math.abs(start - current);
|
||||||
return Optional.of(eta);
|
return Optional.of(eta);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user