36 lines
852 B
Java
36 lines
852 B
Java
package xyz.nodrop.farmingtools.client.pathfinding;
|
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
/**
|
|
* Single node in the A* search graph.
|
|
* Comparable by f = g + h so it can be used directly in a PriorityQueue.
|
|
*/
|
|
public class PathNode implements Comparable<PathNode> {
|
|
|
|
public final BlockPos pos;
|
|
public final PathNode parent;
|
|
|
|
/** Cost from start to this node. */
|
|
public final double g;
|
|
|
|
/** Heuristic cost estimate from this node to goal. */
|
|
public final double h;
|
|
|
|
public PathNode(BlockPos pos, PathNode parent, double g, double h) {
|
|
this.pos = pos;
|
|
this.parent = parent;
|
|
this.g = g;
|
|
this.h = h;
|
|
}
|
|
|
|
public double f() {
|
|
return g + h;
|
|
}
|
|
|
|
@Override
|
|
public int compareTo(PathNode other) {
|
|
return Double.compare(this.f(), other.f());
|
|
}
|
|
}
|