From 0f37e214aa0e5bf2025c7ca9d688245eda599b7c Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 6 Aug 2018 08:27:50 -0700 Subject: [PATCH] MovementDescend --- .../bot/pathing/calc/AStarPathFinder.java | 7 ++- .../movement/movements/MovementDescend.java | 58 +++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 src/main/java/baritone/bot/pathing/movement/movements/MovementDescend.java diff --git a/src/main/java/baritone/bot/pathing/calc/AStarPathFinder.java b/src/main/java/baritone/bot/pathing/calc/AStarPathFinder.java index 9bafd1a6..6ee0d244 100644 --- a/src/main/java/baritone/bot/pathing/calc/AStarPathFinder.java +++ b/src/main/java/baritone/bot/pathing/calc/AStarPathFinder.java @@ -6,6 +6,7 @@ import baritone.bot.pathing.goals.Goal; import baritone.bot.pathing.movement.ActionCosts; import baritone.bot.pathing.movement.Movement; import baritone.bot.pathing.movement.movements.MovementAscend; +import baritone.bot.pathing.movement.movements.MovementDescend; import baritone.bot.pathing.movement.movements.MovementTraverse; import baritone.bot.pathing.path.IPath; import baritone.bot.utils.ToolSet; @@ -142,7 +143,7 @@ public class AStarPathFinder extends AbstractNodeCostSearch { int x = pos.getX(); int y = pos.getY(); int z = pos.getZ(); - Movement[] movements = new Movement[8]; + Movement[] movements = new Movement[12]; movements[0] = new MovementTraverse(pos, new BlockPos(x + 1, y, z)); movements[1] = new MovementTraverse(pos, new BlockPos(x - 1, y, z)); movements[2] = new MovementTraverse(pos, new BlockPos(x, y, z + 1)); @@ -151,6 +152,10 @@ public class AStarPathFinder extends AbstractNodeCostSearch { movements[5] = new MovementAscend(pos, new BlockPos(x - 1, y + 1, z)); movements[6] = new MovementAscend(pos, new BlockPos(x, y + 1, z + 1)); movements[7] = new MovementAscend(pos, new BlockPos(x, y + 1, z - 1)); + movements[8] = new MovementDescend(pos, new BlockPos(x + 1, y - 1, z)); + movements[9] = new MovementDescend(pos, new BlockPos(x - 1, y - 1, z)); + movements[10] = new MovementDescend(pos, new BlockPos(x, y - 1, z + 1)); + movements[11] = new MovementDescend(pos, new BlockPos(x, y - 1, z - 1)); /*Action[] actions = new Action[26]; actions[0] = new ActionPillar(pos); actions[1] = new ActionBridge(pos, new BlockPos(x + 1, y, z)); diff --git a/src/main/java/baritone/bot/pathing/movement/movements/MovementDescend.java b/src/main/java/baritone/bot/pathing/movement/movements/MovementDescend.java new file mode 100644 index 00000000..db5f6d25 --- /dev/null +++ b/src/main/java/baritone/bot/pathing/movement/movements/MovementDescend.java @@ -0,0 +1,58 @@ +package baritone.bot.pathing.movement.movements; + +import baritone.bot.InputOverrideHandler; +import baritone.bot.pathing.movement.Movement; +import baritone.bot.pathing.movement.MovementHelper; +import baritone.bot.pathing.movement.MovementState; +import baritone.bot.utils.BlockStateInterface; +import baritone.bot.utils.Rotation; +import baritone.bot.utils.ToolSet; +import baritone.bot.utils.Utils; +import net.minecraft.block.Block; +import net.minecraft.block.BlockLadder; +import net.minecraft.block.BlockVine; +import net.minecraft.util.math.BlockPos; + +public class MovementDescend extends Movement { + public MovementDescend(BlockPos start, BlockPos end) { + super(start, end, new BlockPos[]{end.up(2), end.up(), end}, new BlockPos[]{end.down()}); + } + + @Override + protected double calculateCost(ToolSet ts) { + if (!MovementHelper.canWalkOn(positionsToPlace[0], BlockStateInterface.get(positionsToPlace[0]))) { + return COST_INF; + } + Block tmp1 = BlockStateInterface.get(dest).getBlock(); + if (tmp1 instanceof BlockLadder || tmp1 instanceof BlockVine) { + return COST_INF; + } + return WALK_ONE_BLOCK_COST * 0.8 + Math.max(FALL_N_BLOCKS_COST[1], WALK_ONE_BLOCK_COST * 0.2) + getTotalHardnessOfBlocksToBreak(ts);//we walk half the block plus 0.3 to get to the edge, then we walk the other 0.2 while simultaneously falling (math.max because of how it's in parallel) + } + + @Override + public MovementState updateState(MovementState state) { + super.updateState(state); + System.out.println("Ticking with state " + state.getStatus()); + switch (state.getStatus()) { + case PREPPING: + case UNREACHABLE: + case FAILED: + return state; + case WAITING: + case RUNNING: + BlockPos playerFeet = playerFeet(); + + if (playerFeet.equals(dest) && player().posY - playerFeet.getY() < 0.01) { + // Wait until we're actually on the ground before saying we're done because sometimes we continue to fall if the next action starts immediately + state.setStatus(MovementState.MovementStatus.SUCCESS); + return state; + } + Rotation rotationToBlock = Utils.calcRotationFromVec3d(playerHead(), Utils.calcCenterFromCoords(positionsToBreak[1], world())); + return state.setTarget(new MovementState.MovementTarget(rotationToBlock)).setInput(InputOverrideHandler.Input.MOVE_FORWARD, true); + default: + return state; + } + } + +}