From fb61b47fb2f858e833888bab16fe4e604f7873a5 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Fri, 17 Aug 2018 16:46:02 -0700 Subject: [PATCH] see costs to all possible movements from current location --- .../bot/pathing/calc/AStarPathFinder.java | 2 +- .../bot/pathing/movement/MovementHelper.java | 7 ++++- .../bot/utils/ExampleBaritoneControl.java | 26 ++++++++++++++++++- .../bot/utils/pathing/BetterBlockPos.java | 4 +++ 4 files changed, 36 insertions(+), 3 deletions(-) diff --git a/src/main/java/baritone/bot/pathing/calc/AStarPathFinder.java b/src/main/java/baritone/bot/pathing/calc/AStarPathFinder.java index 62d9dc54..186bd940 100644 --- a/src/main/java/baritone/bot/pathing/calc/AStarPathFinder.java +++ b/src/main/java/baritone/bot/pathing/calc/AStarPathFinder.java @@ -208,7 +208,7 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper { } - private static Movement[] getConnectedPositions(BetterBlockPos pos, CalculationContext calcContext) { + public static Movement[] getConnectedPositions(BetterBlockPos pos, CalculationContext calcContext) { int x = pos.getX(); int y = pos.getY(); int z = pos.getZ(); diff --git a/src/main/java/baritone/bot/pathing/movement/MovementHelper.java b/src/main/java/baritone/bot/pathing/movement/MovementHelper.java index 738b055c..2587261d 100644 --- a/src/main/java/baritone/bot/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/bot/pathing/movement/MovementHelper.java @@ -138,11 +138,16 @@ public interface MovementHelper extends ActionCosts, Helper { * @return */ static boolean canWalkOn(BlockPos pos, IBlockState state) { - Block block = state.getBlock(); if (block instanceof BlockLadder || block instanceof BlockVine) { // TODO reconsider this return true; } + if (block instanceof BlockGlass || block instanceof BlockStainedGlass) { + return true; + } + if (Blocks.FARMLAND.equals(block) || Blocks.GRASS_PATH.equals(block)) { + return true; + } if (block instanceof BlockAir) { return false; } diff --git a/src/main/java/baritone/bot/utils/ExampleBaritoneControl.java b/src/main/java/baritone/bot/utils/ExampleBaritoneControl.java index ca385646..2473fd80 100644 --- a/src/main/java/baritone/bot/utils/ExampleBaritoneControl.java +++ b/src/main/java/baritone/bot/utils/ExampleBaritoneControl.java @@ -22,12 +22,20 @@ import baritone.bot.Settings; import baritone.bot.behavior.Behavior; import baritone.bot.behavior.impl.PathingBehavior; import baritone.bot.event.events.ChatEvent; +import baritone.bot.pathing.calc.AStarPathFinder; import baritone.bot.pathing.goals.Goal; import baritone.bot.pathing.goals.GoalBlock; import baritone.bot.pathing.goals.GoalXZ; import baritone.bot.pathing.goals.GoalYLevel; +import baritone.bot.pathing.movement.ActionCosts; +import baritone.bot.pathing.movement.CalculationContext; +import baritone.bot.pathing.movement.Movement; +import baritone.bot.utils.pathing.BetterBlockPos; import net.minecraft.util.math.BlockPos; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Comparator; import java.util.List; public class ExampleBaritoneControl extends Behavior { @@ -102,9 +110,25 @@ public class ExampleBaritoneControl extends Behavior { event.cancel(); return; } + if (msg.toLowerCase().equals("costs")) { + Movement[] movements = AStarPathFinder.getConnectedPositions(new BetterBlockPos(playerFeet()), new CalculationContext()); + ArrayList moves = new ArrayList<>(Arrays.asList(movements)); + moves.sort(Comparator.comparingDouble(movement -> movement.getCost(new CalculationContext()))); + for (Movement move : moves) { + String[] parts = move.getClass().toString().split("\\."); + double cost = move.getCost(new CalculationContext()); + String strCost = cost + ""; + if (cost >= ActionCosts.COST_INF) { + strCost = "IMPOSSIBLE"; + } + displayChatMessageRaw(parts[parts.length - 1] + " " + move.getDest().getX() + "," + move.getDest().getY() + "," + move.getDest().getZ() + " " + strCost); + } + event.cancel(); + return; + } List> toggleable = Baritone.settings().getByValueType(Boolean.class); for (Settings.Setting setting : toggleable) { - if (msg.toLowerCase().equals(setting.getName().toLowerCase())) { + if (msg.equalsIgnoreCase(setting.getName())) { setting.value ^= true; event.cancel(); displayChatMessageRaw("Toggled " + setting.getName() + " to " + setting.value); diff --git a/src/main/java/baritone/bot/utils/pathing/BetterBlockPos.java b/src/main/java/baritone/bot/utils/pathing/BetterBlockPos.java index 0f1ece1e..0bdae99c 100644 --- a/src/main/java/baritone/bot/utils/pathing/BetterBlockPos.java +++ b/src/main/java/baritone/bot/utils/pathing/BetterBlockPos.java @@ -55,6 +55,10 @@ public class BetterBlockPos extends BlockPos { this.hashCode = hash; } + public BetterBlockPos(BlockPos pos) { + this(pos.getX(), pos.getY(), pos.getZ()); + } + @Override public int hashCode() { return hashCode;