Change ActionCosts to be an interface
This commit is contained in:
		| @@ -1,16 +1,15 @@ | ||||
| package baritone.bot.pathing.actions; | ||||
|  | ||||
| public final class ActionCosts { | ||||
|     private ActionCosts() {} | ||||
| public interface ActionCosts { | ||||
|  | ||||
|     //These costs are measured roughly in ticks btw | ||||
|     public static final double WALK_ONE_BLOCK_COST = 20 / 4.317; | ||||
|     public static final double WALK_ONE_IN_WATER_COST = 20 / 2.2; | ||||
|     public static final double JUMP_ONE_BLOCK_COST = 5.72854;//see below calculation for fall. 1.25 blocks | ||||
|     public static final double LADDER_UP_ONE_COST = 20 / 2.35; | ||||
|     public static final double LADDER_DOWN_ONE_COST = 20 / 3; | ||||
|     public static final double SNEAK_ONE_BLOCK_COST = 20 / 1.3; | ||||
|     public static final double SPRINT_ONE_BLOCK_COST = 20 / 5.612; | ||||
|     double WALK_ONE_BLOCK_COST = 20 / 4.317; | ||||
|     double WALK_ONE_IN_WATER_COST = 20 / 2.2; | ||||
|     double JUMP_ONE_BLOCK_COST = 5.72854;//see below calculation for fall. 1.25 blocks | ||||
|     double LADDER_UP_ONE_COST = 20 / 2.35; | ||||
|     double LADDER_DOWN_ONE_COST = 20 / 3; | ||||
|     double SNEAK_ONE_BLOCK_COST = 20 / 1.3; | ||||
|     double SPRINT_ONE_BLOCK_COST = 20 / 5.612; | ||||
|     /** | ||||
|      * Doesn't include walking forwards, just the falling | ||||
|      * | ||||
| @@ -20,20 +19,20 @@ public final class ActionCosts { | ||||
|      * | ||||
|      * Solved in mathematica | ||||
|      */ | ||||
|     public static final double FALL_ONE_BLOCK_COST = 5.11354; | ||||
|     public static final double FALL_TWO_BLOCK_COST = 7.28283; | ||||
|     public static final double FALL_THREE_BLOCK_COST = 8.96862; | ||||
|     double FALL_ONE_BLOCK_COST = 5.11354; | ||||
|     double FALL_TWO_BLOCK_COST = 7.28283; | ||||
|     double FALL_THREE_BLOCK_COST = 8.96862; | ||||
|     /** | ||||
|      * It doesn't actually take ten ticks to place a block, this cost is so high | ||||
|      * because we want to generally conserve blocks which might be limited | ||||
|      */ | ||||
|     public static final double PLACE_ONE_BLOCK_COST = 20; | ||||
|     double PLACE_ONE_BLOCK_COST = 20; | ||||
|     /** | ||||
|      * Add this to the cost of breaking any block. The cost of breaking any | ||||
|      * block is calculated as the number of ticks that block takes to break with | ||||
|      * the tools you have. You add this because there's always a little overhead | ||||
|      * (e.g. looking at the block) | ||||
|      */ | ||||
|     public static final double BREAK_ONE_BLOCK_ADD = 4; | ||||
|     public static final double COST_INF = 1000000; | ||||
|     double BREAK_ONE_BLOCK_ADD = 4; | ||||
|     double COST_INF = 1000000; | ||||
| } | ||||
|   | ||||
| @@ -5,13 +5,14 @@ | ||||
|  */ | ||||
| package baritone.bot.pathing.goals; | ||||
|  | ||||
| import baritone.bot.pathing.actions.ActionCosts; | ||||
| import net.minecraft.util.math.BlockPos; | ||||
|  | ||||
| /** | ||||
|  * An abstract Goal for pathing, can be anything from a specific block to just a Y coordinate. | ||||
|  * @author leijurv | ||||
|  */ | ||||
| public interface Goal { | ||||
| public interface Goal extends ActionCosts { | ||||
|  | ||||
|     /** | ||||
|      * Returns whether or not the specified position | ||||
| @@ -29,11 +30,4 @@ public interface Goal { | ||||
|      * @return The estimate number of ticks to satisfy the goal | ||||
|      */ | ||||
|     double heuristic(BlockPos pos); | ||||
|  | ||||
|     /** | ||||
|      * Summarize the goal | ||||
|      * @return | ||||
|      */ | ||||
|     @Override | ||||
|     String toString(); | ||||
| } | ||||
|   | ||||
| @@ -5,7 +5,6 @@ | ||||
|  */ | ||||
| package baritone.bot.pathing.goals; | ||||
|  | ||||
| import baritone.bot.pathing.actions.ActionCosts; | ||||
| import net.minecraft.util.math.BlockPos; | ||||
|  | ||||
| /** | ||||
| @@ -52,14 +51,14 @@ public class GoalBlock implements Goal { | ||||
|     public static double calculate(double xDiff, double yDiff, double zDiff) { | ||||
|         double pythaDist = Math.sqrt(xDiff * xDiff + zDiff * zDiff); | ||||
|         double heuristic = 0; | ||||
|         double baseline = (ActionCosts.PLACE_ONE_BLOCK_COST + ActionCosts.FALL_ONE_BLOCK_COST) * 32; | ||||
|         double baseline = (PLACE_ONE_BLOCK_COST + 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. | ||||
|             //as we get closer, slowly reintroduce the Y coordinate as a heuristic cost | ||||
|             double multiplier = pythaDist < MIN ? 1 : 1 - (pythaDist - MIN) / (MAX - MIN); | ||||
|             if (yDiff < 0) {//pos.getY()-this.y<0 therefore pos.getY()<this.y, so target is above current | ||||
|                 heuristic -= yDiff * (ActionCosts.PLACE_ONE_BLOCK_COST * 0.7 + ActionCosts.JUMP_ONE_BLOCK_COST);//target above current | ||||
|                 heuristic -= yDiff * (PLACE_ONE_BLOCK_COST * 0.7 + JUMP_ONE_BLOCK_COST);//target above current | ||||
|             } else { | ||||
|                 heuristic += yDiff * (10 + ActionCosts.FALL_ONE_BLOCK_COST);//target below current | ||||
|                 heuristic += yDiff * (10 + FALL_ONE_BLOCK_COST);//target below current | ||||
|             } | ||||
|             heuristic *= multiplier; | ||||
|             heuristic += (1 - multiplier) * baseline; | ||||
|   | ||||
| @@ -15,13 +15,11 @@ import net.minecraft.util.math.BlockPos; | ||||
|  */ | ||||
| public class GoalGetToBlock extends GoalComposite { | ||||
|  | ||||
|     public static BlockPos goalPos; | ||||
|  | ||||
|     public GoalGetToBlock(BlockPos pos) { | ||||
|         super(ajacentBlocks(goalPos = pos)); | ||||
|         super(adjacentBlocks(pos)); | ||||
|     } | ||||
|  | ||||
|     public static BlockPos[] ajacentBlocks(BlockPos pos) { | ||||
|     private static BlockPos[] adjacentBlocks(BlockPos pos) { | ||||
|         BlockPos[] sides = new BlockPos[6]; | ||||
|         for (int i = 0; i < 6; i++) { | ||||
|             sides[i] = pos.offset(EnumFacing.values()[i]); | ||||
|   | ||||
| @@ -5,7 +5,6 @@ | ||||
|  */ | ||||
| package baritone.bot.pathing.goals; | ||||
|  | ||||
| import baritone.bot.pathing.actions.ActionCosts; | ||||
| import net.minecraft.util.math.BlockPos; | ||||
|  | ||||
| /** | ||||
| @@ -70,7 +69,7 @@ public class GoalXZ implements Goal { | ||||
|             diagonal = z; | ||||
|         } | ||||
|         diagonal *= sq; | ||||
|         return (diagonal + straight) * ActionCosts.WALK_ONE_BLOCK_COST; | ||||
|         return (diagonal + straight) * WALK_ONE_BLOCK_COST; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|   | ||||
		Reference in New Issue
	
	Block a user