From 0ac5cd9b4ef1511fdbdf65d9b9450177a079862d Mon Sep 17 00:00:00 2001 From: Howard Stark Date: Wed, 1 Aug 2018 23:32:03 -0400 Subject: [PATCH] Fix namespacing --- .../baritone/pathfinding/goals/Goal.java | 31 -------- .../baritone/pathfinding/goals/GoalBlock.java | 77 ------------------- .../pathfinding/goals/GoalComposite.java | 59 -------------- .../pathfinding/goals/GoalGetToBlock.java | 35 --------- .../pathfinding/goals/GoalRunAway.java | 52 ------------- .../pathfinding/goals/GoalTwoBlocks.java | 42 ---------- .../baritone/pathfinding/goals/GoalXZ.java | 68 ---------------- .../pathfinding/goals/GoalYLevel.java | 32 -------- 8 files changed, 396 deletions(-) delete mode 100644 src/main/resources/baritone/pathfinding/goals/Goal.java delete mode 100644 src/main/resources/baritone/pathfinding/goals/GoalBlock.java delete mode 100644 src/main/resources/baritone/pathfinding/goals/GoalComposite.java delete mode 100644 src/main/resources/baritone/pathfinding/goals/GoalGetToBlock.java delete mode 100644 src/main/resources/baritone/pathfinding/goals/GoalRunAway.java delete mode 100644 src/main/resources/baritone/pathfinding/goals/GoalTwoBlocks.java delete mode 100644 src/main/resources/baritone/pathfinding/goals/GoalXZ.java delete mode 100644 src/main/resources/baritone/pathfinding/goals/GoalYLevel.java diff --git a/src/main/resources/baritone/pathfinding/goals/Goal.java b/src/main/resources/baritone/pathfinding/goals/Goal.java deleted file mode 100644 index c9f0f02c..00000000 --- a/src/main/resources/baritone/pathfinding/goals/Goal.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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. - */ -package baritone.pathfinding.goals; - -import net.minecraft.util.math.BlockPos; - -/** - * - * @author leijurv - */ -public interface Goal { - /** - * Does this position satisfy the goal? - * - * @param pos - * @return - */ - public boolean isInGoal(BlockPos pos); - /** - * Estimate the number of ticks it will take to get to the goal - * - * @param pos - * @return - */ - public double heuristic(BlockPos pos); - @Override - public String toString(); -} diff --git a/src/main/resources/baritone/pathfinding/goals/GoalBlock.java b/src/main/resources/baritone/pathfinding/goals/GoalBlock.java deleted file mode 100644 index 4949f522..00000000 --- a/src/main/resources/baritone/pathfinding/goals/GoalBlock.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * 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. - */ -package baritone.pathfinding.goals; - -import baritone.Baritone; -import baritone.pathfinding.actions.Action; -import net.minecraft.util.math.BlockPos; - -/** - * - * @author leijurv - */ -public class GoalBlock implements Goal { - - final int x, y, z; - - public GoalBlock() { - this(Baritone.playerFeet); - } - - public GoalBlock(BlockPos pos) { - this(pos.getX(), pos.getY(), pos.getZ()); - } - - public GoalBlock(int x, int y, int z) { - this.x = x; - this.y = y; - this.z = z; - } - - public BlockPos pos() { - return new BlockPos(x, y, z); - } - - @Override - public boolean isInGoal(BlockPos pos) { - return pos.getX() == this.x && pos.getY() == this.y && pos.getZ() == this.z; - } - static final double MIN = 20; - static final double MAX = 150; - - @Override - public double heuristic(BlockPos pos) { - double xDiff = pos.getX() - this.x; - double yDiff = pos.getY() - this.y; - double zDiff = pos.getZ() - this.z; - return calculate(xDiff, yDiff, zDiff); - } - - public static double calculate(double xDiff, double yDiff, double zDiff) { - double pythaDist = Math.sqrt(xDiff * xDiff + zDiff * zDiff); - double heuristic = 0; - double baseline = (Action.PLACE_ONE_BLOCK_COST + Action.FALL_ONE_BLOCK_COST) * 32; - if (pythaDist < MAX) {//if we are more than MAX away, ignore the Y coordinate. It really doesn't matter how far away your Y coordinate is if you X coordinate is 1000 blocks away. - double multiplier = pythaDist < MIN ? 1 : 1 - (pythaDist - MIN) / (MAX - MIN); - if (yDiff < 0) {//pos.getY()-this.y<0 therefore pos.getY() blocks) { - goals = new Goal[blocks.size()]; - int i = 0; - for (BlockPos pos : blocks) { - goals[i] = new GoalBlock(pos); - i++; - } - } - public Goal[] goals() { - return goals; - } - @Override - public boolean isInGoal(BlockPos pos) { - for (Goal g : goals) { - if (g.isInGoal(pos)) { - return true; - } - } - return false; - } - @Override - public double heuristic(BlockPos pos) { - double min = Double.MAX_VALUE; - for (Goal g : goals) { - min = Math.min(min, g.heuristic(pos)); - } - return min; - } - @Override - public String toString() { - return "GoalComposite" + Arrays.toString(goals); - } -} diff --git a/src/main/resources/baritone/pathfinding/goals/GoalGetToBlock.java b/src/main/resources/baritone/pathfinding/goals/GoalGetToBlock.java deleted file mode 100644 index 5a0bc16a..00000000 --- a/src/main/resources/baritone/pathfinding/goals/GoalGetToBlock.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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. - */ -package baritone.pathfinding.goals; - -import baritone.Baritone; -import net.minecraft.util.EnumFacing; -import net.minecraft.util.math.BlockPos; - -/** - * - * @author avecowa - */ -public class GoalGetToBlock extends GoalComposite { - - public static BlockPos goalPos; - - public GoalGetToBlock(BlockPos pos) { - super(ajacentBlocks(goalPos = pos)); - } - - public GoalGetToBlock() { - this(Baritone.playerFeet); - } - - public static BlockPos[] ajacentBlocks(BlockPos pos) { - BlockPos[] sides = new BlockPos[6]; - for (int i = 0; i < 6; i++) { - sides[i] = pos.offset(EnumFacing.values()[i]); - } - return sides; - } -} diff --git a/src/main/resources/baritone/pathfinding/goals/GoalRunAway.java b/src/main/resources/baritone/pathfinding/goals/GoalRunAway.java deleted file mode 100644 index bc3191c2..00000000 --- a/src/main/resources/baritone/pathfinding/goals/GoalRunAway.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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. - */ -package baritone.pathfinding.goals; - -import java.util.Arrays; -import net.minecraft.util.math.BlockPos; - -/** - * - * @author leijurv - */ -public class GoalRunAway implements Goal { - public final BlockPos[] from; - final double distanceSq; - public GoalRunAway(double distance, BlockPos... from) { - if (from.length == 0) { - throw new IllegalArgumentException(); - } - this.from = from; - this.distanceSq = distance * distance; - } - @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; - } - @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; - } - @Override - public String toString() { - return "GoalRunAwayFrom[" + Arrays.asList(from) + "]"; - } -} diff --git a/src/main/resources/baritone/pathfinding/goals/GoalTwoBlocks.java b/src/main/resources/baritone/pathfinding/goals/GoalTwoBlocks.java deleted file mode 100644 index 5ba5a363..00000000 --- a/src/main/resources/baritone/pathfinding/goals/GoalTwoBlocks.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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. - */ -package baritone.pathfinding.goals; - -import net.minecraft.util.math.BlockPos; - -/** - * - * @author leijurv - */ -public class GoalTwoBlocks implements Goal { - final int x, y, z; - public GoalTwoBlocks(BlockPos pos) { - this(pos.getX(), pos.getY(), pos.getZ()); - } - public GoalTwoBlocks(int x, int y, int z) { - this.x = x; - this.y = y; - this.z = z; - } - @Override - public boolean isInGoal(BlockPos pos) { - return pos.getX() == this.x && (pos.getY() == this.y || pos.getY() == this.y - 1) && pos.getZ() == this.z; - } - @Override - public double heuristic(BlockPos pos) { - double xDiff = pos.getX() - this.x; - double yDiff = pos.getY() - this.y; - if (yDiff < 0) { - yDiff++; - } - double zDiff = pos.getZ() - this.z; - return GoalBlock.calculate(xDiff, yDiff, zDiff); - } - @Override - public String toString() { - return "GoalTwoBlocks{x=" + x + ",y=" + y + ",z=" + z + "}"; - } -} diff --git a/src/main/resources/baritone/pathfinding/goals/GoalXZ.java b/src/main/resources/baritone/pathfinding/goals/GoalXZ.java deleted file mode 100644 index 50df69f8..00000000 --- a/src/main/resources/baritone/pathfinding/goals/GoalXZ.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * 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. - */ -package baritone.pathfinding.goals; - -import baritone.pathfinding.actions.Action; -import net.minecraft.util.math.BlockPos; - -/** - * - * @author leijurv - */ -public class GoalXZ implements Goal { - final int x; - final int z; - public GoalXZ(int x, int z) { - this.x = x; - this.z = z; - } - @Override - public boolean isInGoal(BlockPos pos) { - return pos.getX() == x && pos.getZ() == z; - } - @Override - public double heuristic(BlockPos pos) {//mostly copied from GoalBlock - double xDiff = pos.getX() - this.x; - double zDiff = pos.getZ() - this.z; - return calculate(xDiff, zDiff); - } - public static double calculate(double xDiff, double zDiff) { - return calculate(xDiff, zDiff, 0); - } - /* - public static double calculate(double xDiff, double zDiff) { - double pythaDist = Math.sqrt(xDiff * xDiff + zDiff * zDiff); - return calculate(xDiff, zDiff, pythaDist); - } - public static double calculateOld(double xDiff, double zDiff, double pythaDist) { - double heuristic = 0; - heuristic += Math.abs(xDiff) * Action.WALK_ONE_BLOCK_COST * 1.1;//overestimate - heuristic += Math.abs(zDiff) * Action.WALK_ONE_BLOCK_COST * 1.1; - heuristic += pythaDist / 10 * Action.WALK_ONE_BLOCK_COST; - return heuristic; - } - */ - static final double sq = Math.sqrt(2); - public static double calculate(double xDiff, double zDiff, double pythaDist) { - double x = Math.abs(xDiff); - double z = Math.abs(zDiff); - double straight; - double diagonal; - if (x < z) { - straight = z - x; - diagonal = x; - } else { - straight = x - z; - diagonal = z; - } - diagonal *= sq; - return (diagonal + straight) * Action.WALK_ONE_BLOCK_COST; - } - @Override - public String toString() { - return "Goal{x=" + x + ",z=" + z + "}"; - } -} diff --git a/src/main/resources/baritone/pathfinding/goals/GoalYLevel.java b/src/main/resources/baritone/pathfinding/goals/GoalYLevel.java deleted file mode 100644 index 31d484da..00000000 --- a/src/main/resources/baritone/pathfinding/goals/GoalYLevel.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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. - */ -package baritone.pathfinding.goals; - -import net.minecraft.util.math.BlockPos; - -/** - * - * @author leijurv - */ -public class GoalYLevel implements Goal { - final int level; - public GoalYLevel(int level) { - this.level = level; - } - @Override - public boolean isInGoal(BlockPos pos) { - return pos.getY() == level; - } - @Override - public double heuristic(BlockPos pos) { - return 20 * Math.abs(pos.getY() - level);//the number 20 was chosen somewhat randomly. - //TODO fix that - } - @Override - public String toString() { - return "Goal{y=" + level + "}"; - } -}