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

73 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
import net.minecraft.util.math.BlockPos;
import java.util.Arrays;
2018-08-02 03:13:48 +00:00
/**
* Useful for automated combat (retreating specifically)
*
2018-08-02 03:13:48 +00:00
* @author leijurv
*/
public class GoalRunAway implements Goal {
2018-08-02 04:22:21 +00:00
2018-09-17 00:49:19 +00:00
private final BlockPos[] from;
2018-08-02 04:22:21 +00:00
2018-09-17 00:49:19 +00:00
private final double distanceSq;
2018-08-02 04:22:21 +00:00
2018-08-02 03:13:48 +00:00
public GoalRunAway(double distance, BlockPos... from) {
if (from.length == 0) {
throw new IllegalArgumentException();
}
this.from = from;
this.distanceSq = distance * distance;
}
2018-08-02 04:22:21 +00:00
2018-08-02 03:13:48 +00:00
@Override
public boolean isInGoal(BlockPos pos) {
for (BlockPos p : from) {
int diffX = pos.getX() - p.getX();
int diffZ = pos.getZ() - p.getZ();
double distSq = diffX * diffX + diffZ * diffZ;
if (distSq < distanceSq) {
return false;
}
}
return true;
}
2018-08-02 04:22:21 +00:00
2018-08-02 03:13:48 +00:00
@Override
public double heuristic(BlockPos pos) {//mostly copied from GoalBlock
double min = Double.MAX_VALUE;
for (BlockPos p : from) {
double h = GoalXZ.calculate(p.getX() - pos.getX(), p.getZ() - pos.getZ());
if (h < min) {
min = h;
}
}
return -min;
}
2018-08-02 04:22:21 +00:00
2018-08-02 03:13:48 +00:00
@Override
public String toString() {
return "GoalRunAwayFrom" + Arrays.asList(from);
2018-08-02 03:13:48 +00:00
}
}