2018-08-02 03:13:48 +00:00
|
|
|
/*
|
|
|
|
* To change this license header, choose License Headers in Project Properties.
|
|
|
|
* To change this template file, choose Tools | Templates
|
|
|
|
* and open the template in the editor.
|
|
|
|
*/
|
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) {
|
|
|
|
goals = new Goal[blocks.length];
|
|
|
|
for (int i = 0; i < blocks.length; i++) {
|
|
|
|
goals[i] = new GoalBlock(blocks[i]);
|
|
|
|
}
|
|
|
|
}
|
2018-08-02 04:22:21 +00:00
|
|
|
|
2018-08-02 03:13:48 +00:00
|
|
|
public GoalComposite(Collection<BlockPos> blocks) {
|
|
|
|
goals = new Goal[blocks.size()];
|
|
|
|
int i = 0;
|
|
|
|
for (BlockPos pos : blocks) {
|
|
|
|
goals[i] = new GoalBlock(pos);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
2018-08-02 04:22:21 +00:00
|
|
|
|
2018-08-02 03:13:48 +00:00
|
|
|
public Goal[] goals() {
|
|
|
|
return goals;
|
|
|
|
}
|
2018-08-02 04:22:21 +00:00
|
|
|
|
2018-08-02 03:13:48 +00:00
|
|
|
@Override
|
|
|
|
public boolean isInGoal(BlockPos pos) {
|
|
|
|
for (Goal g : goals) {
|
|
|
|
if (g.isInGoal(pos)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
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);
|
|
|
|
}
|
|
|
|
}
|