From d357a48710de35d650c1fefc8f5d0ab18614eb90 Mon Sep 17 00:00:00 2001 From: Howard Stark Date: Mon, 6 Aug 2018 16:07:54 -0700 Subject: [PATCH] Add cost-only MovementFall --- .../movement/movements/MovementFall.java | 60 +++++++------------ 1 file changed, 20 insertions(+), 40 deletions(-) diff --git a/src/main/java/baritone/bot/pathing/movement/movements/MovementFall.java b/src/main/java/baritone/bot/pathing/movement/movements/MovementFall.java index 21abea0ee..a01241e25 100644 --- a/src/main/java/baritone/bot/pathing/movement/movements/MovementFall.java +++ b/src/main/java/baritone/bot/pathing/movement/movements/MovementFall.java @@ -1,61 +1,41 @@ package baritone.bot.pathing.movement.movements; -import baritone.bot.InputOverrideHandler; +import baritone.bot.pathing.movement.ActionCosts; 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 MovementFall extends Movement { - public MovementFall(BlockPos start) { - super(start, start.down(), new BlockPos[]{start.down()}, new BlockPos[0]); + + private static BlockPos[] buildPositionsToBreak(BlockPos src, BlockPos dest) { + BlockPos[] toBreak; + int diffX = dest.getX() - src.getX(); + int diffZ = dest.getZ() - src.getZ(); + int diffY = dest.getY() - src.getY(); + toBreak = new BlockPos[diffY + 1]; + for(int i = 0; i < toBreak.length; i++ ) { + toBreak[i] = new BlockPos(dest.getX() - diffX, dest.getY() + (toBreak.length - 1) - i, dest.getZ() - diffZ); + } + return toBreak; } - int numTicks = 0; - @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: - if (playerFeet().equals(dest)) { - state.setStatus(MovementState.MovementStatus.SUCCESS); - return state; - } - if (numTicks++ < 10) { - return state; - } - Rotation rotationToBlock = Utils.calcRotationFromVec3d(playerHead(), Utils.calcCenterFromCoords(positionsToBreak[0], world())); - return state.setTarget(new MovementState.MovementTarget(rotationToBlock)).setInput(InputOverrideHandler.Input.MOVE_FORWARD, true); - default: - return state; - } + protected MovementFall(BlockPos src, BlockPos dest) { + super(src, dest, MovementFall.buildPositionsToBreak(src, dest), new BlockPos[]{dest.down()}); } @Override protected double calculateCost(ToolSet ts) { - if (!MovementHelper.canWalkOn(dest.down(), BlockStateInterface.get(dest.down()))) { + if(!MovementHelper.canWalkOn(positionsToPlace[0], BlockStateInterface.get(positionsToPlace[0]))) { return COST_INF; } - Block td = BlockStateInterface.get(dest).getBlock(); - boolean ladder = td instanceof BlockLadder || td instanceof BlockVine; - if (ladder) { - return LADDER_DOWN_ONE_COST; - } else { - return FALL_N_BLOCKS_COST[1] + getTotalHardnessOfBlocksToBreak(ts); + double placeBucketCost = 0.0; + if(!BlockStateInterface.isWater(dest)) { + placeBucketCost = ActionCosts.PLACE_ONE_BLOCK_COST; } + return WALK_OFF_BLOCK_COST + FALL_N_BLOCKS_COST[positionsToBreak.length - 1] + MovementHelper.getTotalHardnessOfBlocksToBreak(ts, positionsToBreak) + placeBucketCost; } + }