Merge branch 'master' of github.com:cabaletta/baritone

This commit is contained in:
Leijurv 2018-08-08 17:04:06 -07:00
commit a6b5d423d5
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
7 changed files with 73 additions and 21 deletions

View File

@ -26,7 +26,20 @@ import net.minecraft.util.math.BlockPos;
*/ */
public class GoalBlock implements Goal { public class GoalBlock implements Goal {
private final int x, y, z; /**
* The X block position of this goal
*/
private final int x;
/**
* The Y block position of this goal
*/
private final int y;
/**
* The Z block position of this goal
*/
private final int z;
public GoalBlock(BlockPos pos) { public GoalBlock(BlockPos pos) {
this(pos.getX(), pos.getY(), pos.getZ()); this(pos.getX(), pos.getY(), pos.getZ());
@ -44,10 +57,14 @@ public class GoalBlock implements Goal {
} }
/** /**
* The range over which to begin considering Y coordinate in the heuristic * The min range value over which to begin considering Y coordinate in the heuristic
*/ */
static final double MIN = 20; private static final double MIN = 20;
static final double MAX = 150;
/**
* The max range value over which to begin considering Y coordinate in the heuristic
*/
private static final double MAX = 150;
@Override @Override
public double heuristic(BlockPos pos) { public double heuristic(BlockPos pos) {
@ -62,6 +79,13 @@ public class GoalBlock implements Goal {
return "Goal{x=" + x + ",y=" + y + ",z=" + z + "}"; return "Goal{x=" + x + ",y=" + y + ",z=" + z + "}";
} }
/**
* @return The position of this goal as a {@link BlockPos}
*/
public BlockPos getGoalPos() {
return new BlockPos(x, y, z);
}
public static double calculate(double xDiff, double yDiff, double zDiff) { public static double calculate(double xDiff, double yDiff, double zDiff) {
double pythaDist = Math.sqrt(xDiff * xDiff + zDiff * zDiff); double pythaDist = Math.sqrt(xDiff * xDiff + zDiff * zDiff);
double heuristic = 0; double heuristic = 0;
@ -83,8 +107,4 @@ public class GoalBlock implements Goal {
heuristic += GoalXZ.calculate(xDiff, zDiff, pythaDist); heuristic += GoalXZ.calculate(xDiff, zDiff, pythaDist);
return heuristic; return heuristic;
} }
public BlockPos getGoalPos() {
return new BlockPos(x, y, z);
}
} }

View File

@ -25,10 +25,14 @@ import net.minecraft.util.math.BlockPos;
* A composite of many goals, any one of which satisfies the composite. * 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 * 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 * would result in it pathing to the easiest oak log to get to
*
* @author avecowa * @author avecowa
*/ */
public class GoalComposite implements Goal { public class GoalComposite implements Goal {
/**
* An array of goals that any one of must be satisfied
*/
public final Goal[] goals; public final Goal[] goals;
public GoalComposite(Goal... goals) { public GoalComposite(Goal... goals) {

View File

@ -21,8 +21,8 @@ import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
/** /**
* Don't get into the block, but get directly adjacent to it. * Don't get into the block, but get directly adjacent to it. Useful for chests.
* Useful for chests. *
* @author avecowa * @author avecowa
*/ */
public class GoalGetToBlock extends GoalComposite { public class GoalGetToBlock extends GoalComposite {

View File

@ -21,7 +21,7 @@ import java.util.Arrays;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
/** /**
* Useful for automated combat (etreating specifically) * Useful for automated combat (retreating specifically)
* @author leijurv * @author leijurv
*/ */
public class GoalRunAway implements Goal { public class GoalRunAway implements Goal {

View File

@ -20,13 +20,27 @@ package baritone.bot.pathing.goals;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
/** /**
* Useful if the goal is just to mine a block. * Useful if the goal is just to mine a block. This goal will be satisfied if the specified
* This goal gets either the player's feet or head into the desired block. * {@link BlockPos} is at to or above the specified position for this goal.
*
* @author leijurv * @author leijurv
*/ */
public class GoalTwoBlocks implements Goal { public class GoalTwoBlocks implements Goal {
final int x, y, z; /**
* The X block position of this goal
*/
private final int x;
/**
* The Y block position of this goal
*/
private final int y;
/**
* The Z block position of this goal
*/
private final int z;
public GoalTwoBlocks(BlockPos pos) { public GoalTwoBlocks(BlockPos pos) {
this(pos.getX(), pos.getY(), pos.getZ()); this(pos.getX(), pos.getY(), pos.getZ());

View File

@ -25,12 +25,23 @@ import net.minecraft.util.math.BlockPos;
*/ */
public class GoalXZ implements Goal { public class GoalXZ implements Goal {
final int x, z; private static final double SQRT_2 = Math.sqrt(2);
/**
* The X block position of this goal
*/
private final int x;
/**
* The Z block position of this goal
*/
private final int z;
public GoalXZ(int x, int z) { public GoalXZ(int x, int z) {
this.x = x; this.x = x;
this.z = z; this.z = z;
} }
@Override @Override
public boolean isInGoal(BlockPos pos) { public boolean isInGoal(BlockPos pos) {
return pos.getX() == x && pos.getZ() == z; return pos.getX() == x && pos.getZ() == z;
@ -61,8 +72,6 @@ public class GoalXZ implements Goal {
} }
*/ */
static final double sq = Math.sqrt(2);
public static double calculate(double xDiff, double zDiff, double pythaDist) { public static double calculate(double xDiff, double zDiff, double pythaDist) {
//This is a combination of pythagorean and manhattan distance //This is a combination of pythagorean and manhattan distance
//It takes into account the fact that pathing can either walk diagonally or forwards //It takes into account the fact that pathing can either walk diagonally or forwards
@ -80,7 +89,7 @@ public class GoalXZ implements Goal {
straight = x - z; straight = x - z;
diagonal = z; diagonal = z;
} }
diagonal *= sq; diagonal *= SQRT_2;
return (diagonal + straight) * WALK_ONE_BLOCK_COST; return (diagonal + straight) * WALK_ONE_BLOCK_COST;
} }

View File

@ -21,11 +21,15 @@ import net.minecraft.util.math.BlockPos;
/** /**
* Useful for mining (getting to diamond / iron level) * Useful for mining (getting to diamond / iron level)
*
* @author leijurv * @author leijurv
*/ */
public class GoalYLevel implements Goal { public class GoalYLevel implements Goal {
final int level; /**
* The target Y level
*/
private final int level;
public GoalYLevel(int level) { public GoalYLevel(int level) {
this.level = level; this.level = level;
@ -38,8 +42,9 @@ public class GoalYLevel implements Goal {
@Override @Override
public double heuristic(BlockPos pos) { public double heuristic(BlockPos pos) {
return 20 * Math.abs(pos.getY() - level);//the number 20 was chosen somewhat randomly. // The number 20 was chosen somewhat randomly.
//TODO fix that // TODO fix that ^
return 20 * Math.abs(pos.getY() - level);
} }
@Override @Override