From 774b906d192bdcb62fc262d2c3f3ce9426852ec2 Mon Sep 17 00:00:00 2001 From: Brady Date: Wed, 1 Aug 2018 21:27:11 -0700 Subject: [PATCH] Change ActionCosts to be an interface --- .../bot/pathing/actions/ActionCosts.java | 29 +++++++++---------- .../java/baritone/bot/pathing/goals/Goal.java | 10 ++----- .../baritone/bot/pathing/goals/GoalBlock.java | 7 ++--- .../bot/pathing/goals/GoalGetToBlock.java | 6 ++-- .../baritone/bot/pathing/goals/GoalXZ.java | 3 +- 5 files changed, 22 insertions(+), 33 deletions(-) diff --git a/src/main/java/baritone/bot/pathing/actions/ActionCosts.java b/src/main/java/baritone/bot/pathing/actions/ActionCosts.java index dde2bc39..6086aca4 100644 --- a/src/main/java/baritone/bot/pathing/actions/ActionCosts.java +++ b/src/main/java/baritone/bot/pathing/actions/ActionCosts.java @@ -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; } diff --git a/src/main/java/baritone/bot/pathing/goals/Goal.java b/src/main/java/baritone/bot/pathing/goals/Goal.java index 0c7b4be9..8122daa9 100644 --- a/src/main/java/baritone/bot/pathing/goals/Goal.java +++ b/src/main/java/baritone/bot/pathing/goals/Goal.java @@ -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(); } diff --git a/src/main/java/baritone/bot/pathing/goals/GoalBlock.java b/src/main/java/baritone/bot/pathing/goals/GoalBlock.java index dd3f60d0..f7f19b0c 100644 --- a/src/main/java/baritone/bot/pathing/goals/GoalBlock.java +++ b/src/main/java/baritone/bot/pathing/goals/GoalBlock.java @@ -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()