2018-08-02 15:07:10 +00:00
package baritone.bot.pathing.calc ;
2018-08-01 15:34:35 +00:00
2018-08-02 15:07:10 +00:00
import baritone.bot.pathing.goals.Goal ;
2018-08-03 13:55:17 +00:00
import baritone.bot.pathing.movement.Movement ;
2018-08-01 15:34:35 +00:00
import net.minecraft.util.math.BlockPos ;
2018-08-02 15:07:10 +00:00
import java.util.Objects ;
2018-08-01 15:34:35 +00:00
/ * *
2018-08-02 15:07:10 +00:00
* A node in the path , containing the cost and steps to get to it .
2018-08-01 15:34:35 +00:00
*
* @author leijurv
* /
2018-08-02 15:07:10 +00:00
class PathNode {
2018-08-03 16:52:25 +00:00
/ * *
* The position of this node
* /
2018-08-01 15:34:35 +00:00
final BlockPos pos ;
2018-08-03 16:52:25 +00:00
/ * *
* The goal it ' s going towards
* /
2018-08-01 15:34:35 +00:00
final Goal goal ;
2018-08-03 03:48:21 +00:00
2018-08-03 16:52:25 +00:00
/ * *
* Cached , should always be equal to goal . heuristic ( pos )
* /
2018-08-01 15:34:35 +00:00
final double estimatedCostToGoal ;
2018-08-02 15:07:10 +00:00
2018-08-03 16:52:25 +00:00
/ * *
* Total cost of getting from start to here
* Mutable and changed by PathFinder
* /
2018-08-02 15:07:10 +00:00
double cost ;
2018-08-03 03:48:21 +00:00
2018-08-03 16:52:25 +00:00
/ * *
* Should always be equal to estimatedCosttoGoal + cost
* Mutable and changed by PathFinder
* /
2018-08-03 15:45:11 +00:00
public double combinedCost ;
2018-08-03 16:52:25 +00:00
/ * *
* In the graph search , what previous node contributed to the cost
* Mutable and changed by PathFinder
* /
2018-08-02 15:07:10 +00:00
PathNode previous ;
2018-08-03 03:48:21 +00:00
2018-08-03 16:52:25 +00:00
/ * *
* In the graph search , what previous movement ( edge ) was taken to get to here
* Mutable and changed by PathFinder
* /
2018-08-02 22:35:36 +00:00
Movement previousMovement ;
2018-08-02 15:07:10 +00:00
/ * *
* Is this a member of the open set in A * ? ( only used during pathfinding )
2018-08-03 16:50:09 +00:00
* Instead of doing a costly member check in the open set , cache membership in each node individually too .
2018-08-02 15:07:10 +00:00
* /
2018-08-01 15:34:35 +00:00
boolean isOpen ;
2018-08-03 03:48:21 +00:00
2018-08-02 15:07:10 +00:00
public PathNode ( BlockPos pos , Goal goal ) {
2018-08-01 15:34:35 +00:00
this . pos = pos ;
this . previous = null ;
this . cost = Short . MAX_VALUE ;
this . goal = goal ;
this . estimatedCostToGoal = goal . heuristic ( pos ) ;
2018-08-02 22:35:36 +00:00
this . previousMovement = null ;
2018-08-01 15:34:35 +00:00
this . isOpen = false ;
}
2018-08-02 15:07:10 +00:00
2018-08-03 03:48:21 +00:00
/ * *
* TODO : Possibly reimplement hashCode and equals . They are necessary for this class to function but they could be done better
*
* @return The hash code value for this { @link PathNode }
* /
2018-08-01 15:34:35 +00:00
@Override
2018-08-03 03:48:21 +00:00
public int hashCode ( ) {
2018-08-01 15:34:35 +00:00
int hash = 3241 ;
hash = 3457689 * hash + this . pos . getX ( ) ;
hash = 8734625 * hash + this . pos . getY ( ) ;
hash = 2873465 * hash + this . pos . getZ ( ) ;
2018-08-03 03:48:21 +00:00
// Don't call goal.hashCode(). this calls objects hashcode to verify that the actual goal objects are == identical, which is important for node caching
hash = 3241543 * hash + Objects . hashCode ( this . goal ) ;
2018-08-01 15:34:35 +00:00
return hash ;
}
2018-08-02 15:07:10 +00:00
2018-08-01 15:34:35 +00:00
@Override
2018-08-03 03:48:21 +00:00
public boolean equals ( Object obj ) {
if ( obj = = null | | ! ( obj instanceof PathNode ) )
2018-08-01 15:34:35 +00:00
return false ;
2018-08-03 03:48:21 +00:00
2018-08-02 15:07:10 +00:00
final PathNode other = ( PathNode ) obj ;
2018-08-03 03:48:21 +00:00
return Objects . equals ( this . pos , other . pos ) & & Objects . equals ( this . goal , other . goal ) ;
2018-08-01 15:34:35 +00:00
}
}