2018-08-02 03:30:12 +00:00
|
|
|
package baritone.bot.pathing.goals;
|
2018-08-02 03:13:48 +00:00
|
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.Collection;
|
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A composite of many goals, any one of which satisfies the composite.
|
|
|
|
* For example, a GoalComposite of block goals for every oak log in loaded chunks
|
|
|
|
* would result in it pathing to the easiest oak log to get to
|
|
|
|
* @author avecowa
|
|
|
|
*/
|
|
|
|
public class GoalComposite implements Goal {
|
2018-08-02 04:22:21 +00:00
|
|
|
|
2018-08-02 03:13:48 +00:00
|
|
|
public final Goal[] goals;
|
2018-08-02 04:22:21 +00:00
|
|
|
|
2018-08-02 03:13:48 +00:00
|
|
|
public GoalComposite(Goal... goals) {
|
|
|
|
this.goals = goals;
|
|
|
|
}
|
2018-08-02 04:22:21 +00:00
|
|
|
|
2018-08-02 03:13:48 +00:00
|
|
|
public GoalComposite(BlockPos... blocks) {
|
2018-08-02 04:50:48 +00:00
|
|
|
this(Arrays.asList(blocks));
|
2018-08-02 03:13:48 +00:00
|
|
|
}
|
2018-08-02 04:22:21 +00:00
|
|
|
|
2018-08-02 03:13:48 +00:00
|
|
|
public GoalComposite(Collection<BlockPos> blocks) {
|
2018-08-02 04:50:48 +00:00
|
|
|
this(blocks.stream().map(GoalBlock::new).toArray(Goal[]::new));
|
2018-08-02 03:13:48 +00:00
|
|
|
}
|
2018-08-02 04:22:21 +00:00
|
|
|
|
2018-08-02 03:13:48 +00:00
|
|
|
@Override
|
|
|
|
public boolean isInGoal(BlockPos pos) {
|
2018-08-02 07:31:55 +00:00
|
|
|
return Arrays.stream(this.goals).anyMatch(goal -> goal.isInGoal(pos));
|
2018-08-02 03:13:48 +00:00
|
|
|
}
|
2018-08-02 04:22:21 +00:00
|
|
|
|
2018-08-02 03:13:48 +00:00
|
|
|
@Override
|
|
|
|
public double heuristic(BlockPos pos) {
|
|
|
|
double min = Double.MAX_VALUE;
|
|
|
|
for (Goal g : goals) {
|
|
|
|
min = Math.min(min, g.heuristic(pos)); // whichever is closest
|
|
|
|
}
|
|
|
|
return min;
|
|
|
|
}
|
2018-08-02 04:22:21 +00:00
|
|
|
|
2018-08-02 03:13:48 +00:00
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
return "GoalComposite" + Arrays.toString(goals);
|
|
|
|
}
|
2018-08-02 07:31:55 +00:00
|
|
|
|
|
|
|
public Goal[] goals() {
|
|
|
|
return goals;
|
|
|
|
}
|
2018-08-02 03:13:48 +00:00
|
|
|
}
|