baritone/src/main/java/baritone/pathing/goals/GoalComposite.java

74 lines
2.0 KiB
Java
Raw Normal View History

2018-08-08 03:16:53 +00:00
/*
* This file is part of Baritone.
*
* Baritone is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
2018-08-08 03:16:53 +00:00
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Baritone is distributed in the hope that it will be useful,
2018-08-08 03:16:53 +00:00
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
2018-08-08 03:16:53 +00:00
*
* You should have received a copy of the GNU Lesser General Public License
2018-08-08 03:16:53 +00:00
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/
2018-08-22 20:15:56 +00:00
package baritone.pathing.goals;
2018-08-02 03:13:48 +00:00
2018-09-17 00:49:19 +00:00
import net.minecraft.util.math.BlockPos;
2018-08-02 03:13:48 +00:00
import java.util.Arrays;
import java.util.Collection;
/**
* 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
*
2018-08-02 03:13:48 +00:00
* @author avecowa
*/
public class GoalComposite implements Goal {
2018-08-02 04:22:21 +00:00
/**
* An array of goals that any one of must be satisfied
*/
2018-09-17 00:49:19 +00:00
private 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) {
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);
}
public Goal[] goals() {
return goals;
}
2018-08-02 03:13:48 +00:00
}