From 24cbb5e149216f9af593ee7624413787a35864c8 Mon Sep 17 00:00:00 2001 From: Howard Stark Date: Mon, 6 Aug 2018 17:34:49 -0700 Subject: [PATCH] Fix location of method --- .../bot/pathing/movement/Movement.java | 56 ++++++++++++++++--- .../bot/pathing/movement/MovementHelper.java | 40 ------------- .../movement/movements/MovementAscend.java | 4 +- .../movement/movements/MovementDescend.java | 3 +- .../movement/movements/MovementDownward.java | 2 +- .../movement/movements/MovementFall.java | 8 ++- .../movement/movements/MovementTraverse.java | 6 +- 7 files changed, 63 insertions(+), 56 deletions(-) diff --git a/src/main/java/baritone/bot/pathing/movement/Movement.java b/src/main/java/baritone/bot/pathing/movement/Movement.java index 80440574..33bab0bc 100644 --- a/src/main/java/baritone/bot/pathing/movement/Movement.java +++ b/src/main/java/baritone/bot/pathing/movement/Movement.java @@ -131,6 +131,47 @@ public abstract class Movement implements Helper, MovementHelper { currentState.setStatus(MovementStatus.CANCELED); } + + public double getTotalHardnessOfBlocksToBreak(ToolSet ts) { + /* + double sum = 0; + HashSet toBreak = new HashSet(); + for (BlockPos positionsToBreak1 : positionsToBreak) { + toBreak.add(positionsToBreak1); + if (this instanceof ActionFall) {//if we are digging straight down, assume we have already broken the sand above us + continue; + } + BlockPos tmp = positionsToBreak1.up(); + while (canFall(tmp)) { + toBreak.add(tmp); + tmp = tmp.up(); + } + } + for (BlockPos pos : toBreak) { + sum += getHardness(ts, Baritone.get(pos), pos); + if (sum >= COST_INF) { + return COST_INF; + } + } + if (!Baritone.allowBreakOrPlace || !Baritone.hasThrowaway) { + for (int i = 0; i < blocksToPlace.length; i++) { + if (!canWalkOn(positionsToPlace[i])) { + return COST_INF; + } + } + }*/ + //^ the above implementation properly deals with falling blocks, TODO integrate + double sum = 0; + for (BlockPos pos : positionsToBreak) { + sum += MovementHelper.getMiningDurationTicks(ts, BlockStateInterface.get(pos), pos); + if (sum >= COST_INF) { + return COST_INF; + } + } + return sum; + } + + /** * Calculate latest movement state. * Gets called once a tick. @@ -154,9 +195,9 @@ public abstract class Movement implements Helper, MovementHelper { return toBreakCached; } ArrayList result = new ArrayList<>(); - for (BlockPos positionsToBreak1 : positionsToBreak) { - if (!MovementHelper.canWalkThrough(positionsToBreak1, BlockStateInterface.get(positionsToBreak1))) { - result.add(positionsToBreak1); + for (BlockPos positionToBreak : positionsToBreak) { + if (!MovementHelper.canWalkThrough(positionToBreak, BlockStateInterface.get(positionToBreak))) { + result.add(positionToBreak); } } toBreakCached = result; @@ -168,9 +209,9 @@ public abstract class Movement implements Helper, MovementHelper { return toPlaceCached; } ArrayList result = new ArrayList<>(); - for (BlockPos positionsToPlace1 : positionsToPlace) { - if (!MovementHelper.canWalkOn(positionsToPlace1)) { - result.add(positionsToPlace1); + for (BlockPos positionToBreak : positionsToPlace) { + if (!MovementHelper.canWalkOn(positionToBreak)) { + result.add(positionToBreak); } } toPlaceCached = result; @@ -178,6 +219,7 @@ public abstract class Movement implements Helper, MovementHelper { } protected void moveTowards(BlockPos pos) { - currentState.setTarget(new MovementState.MovementTarget(new Rotation(Utils.calcRotationFromVec3d(playerHead(), Utils.calcCenterFromCoords(pos, world()), playerRotations()).getFirst(), player().rotationPitch))).setInput(InputOverrideHandler.Input.MOVE_FORWARD, true); + currentState.setTarget(new MovementState.MovementTarget(new Rotation(Utils.calcRotationFromVec3d(playerHead(), Utils.calcCenterFromCoords(pos, world()), playerRotations()).getFirst(), player().rotationPitch))) + .setInput(InputOverrideHandler.Input.MOVE_FORWARD, true); } } diff --git a/src/main/java/baritone/bot/pathing/movement/MovementHelper.java b/src/main/java/baritone/bot/pathing/movement/MovementHelper.java index a1ce18b0..7834c13d 100644 --- a/src/main/java/baritone/bot/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/bot/pathing/movement/MovementHelper.java @@ -98,46 +98,6 @@ public interface MovementHelper extends ActionCosts, Helper { return BlockStateInterface.get(pos).getBlock() instanceof BlockFalling; } - static double getTotalHardnessOfBlocksToBreak(ToolSet ts, BlockPos[] positionsToBreak) { - /* - double sum = 0; - HashSet toBreak = new HashSet(); - for (BlockPos positionsToBreak1 : positionsToBreak) { - toBreak.add(positionsToBreak1); - if (this instanceof ActionFall) {//if we are digging straight down, assume we have already broken the sand above us - continue; - } - BlockPos tmp = positionsToBreak1.up(); - while (canFall(tmp)) { - toBreak.add(tmp); - tmp = tmp.up(); - } - } - for (BlockPos pos : toBreak) { - sum += getHardness(ts, Baritone.get(pos), pos); - if (sum >= COST_INF) { - return COST_INF; - } - } - if (!Baritone.allowBreakOrPlace || !Baritone.hasThrowaway) { - for (int i = 0; i < blocksToPlace.length; i++) { - if (!canWalkOn(positionsToPlace[i])) { - return COST_INF; - } - } - }*/ - //^ the above implementation properly deals with falling blocks, TODO integrate - double sum = 0; - for (BlockPos pos : positionsToBreak) { - sum += getMiningDurationTicks(ts, BlockStateInterface.get(pos), pos); - if (sum >= COST_INF) { - return COST_INF; - } - } - return sum; - } - - static double getMiningDurationTicks(ToolSet ts, IBlockState block, BlockPos position) { if (!block.equals(Blocks.AIR) && !canWalkThrough(position, block)) { if (avoidBreaking(position)) { diff --git a/src/main/java/baritone/bot/pathing/movement/movements/MovementAscend.java b/src/main/java/baritone/bot/pathing/movement/movements/MovementAscend.java index 7337878e..abc67642 100644 --- a/src/main/java/baritone/bot/pathing/movement/movements/MovementAscend.java +++ b/src/main/java/baritone/bot/pathing/movement/movements/MovementAscend.java @@ -50,7 +50,7 @@ public class MovementAscend extends Movement { } for (BlockPos against1 : against) { if (BlockStateInterface.get(against1).isBlockNormalCube()) { - return JUMP_ONE_BLOCK_COST + WALK_ONE_BLOCK_COST + PLACE_ONE_BLOCK_COST + MovementHelper.getTotalHardnessOfBlocksToBreak(ts, positionsToBreak); + return JUMP_ONE_BLOCK_COST + WALK_ONE_BLOCK_COST + PLACE_ONE_BLOCK_COST + getTotalHardnessOfBlocksToBreak(ts ); } } return COST_INF; @@ -58,7 +58,7 @@ public class MovementAscend extends Movement { if (BlockStateInterface.get(src.up(3)).getBlock() instanceof BlockFalling) {//it would fall on us and possibly suffocate us return COST_INF; } - return WALK_ONE_BLOCK_COST / 2 + Math.max(JUMP_ONE_BLOCK_COST, WALK_ONE_BLOCK_COST / 2) + MovementHelper.getTotalHardnessOfBlocksToBreak(ts, positionsToBreak);//we walk half the block to get to the edge, then we walk the other half while simultaneously jumping (math.max because of how it's in parallel) + return WALK_ONE_BLOCK_COST / 2 + Math.max(JUMP_ONE_BLOCK_COST, WALK_ONE_BLOCK_COST / 2) + getTotalHardnessOfBlocksToBreak(ts);//we walk half the block to get to the edge, then we walk the other half while simultaneously jumping (math.max because of how it's in parallel) } @Override diff --git a/src/main/java/baritone/bot/pathing/movement/movements/MovementDescend.java b/src/main/java/baritone/bot/pathing/movement/movements/MovementDescend.java index 0dd09040..5d7b7110 100644 --- a/src/main/java/baritone/bot/pathing/movement/movements/MovementDescend.java +++ b/src/main/java/baritone/bot/pathing/movement/movements/MovementDescend.java @@ -25,13 +25,12 @@ public class MovementDescend extends Movement { 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) + MovementHelper.getTotalHardnessOfBlocksToBreak(ts, positionsToBreak);//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) + 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: diff --git a/src/main/java/baritone/bot/pathing/movement/movements/MovementDownward.java b/src/main/java/baritone/bot/pathing/movement/movements/MovementDownward.java index 43b4315c..b6db7468 100644 --- a/src/main/java/baritone/bot/pathing/movement/movements/MovementDownward.java +++ b/src/main/java/baritone/bot/pathing/movement/movements/MovementDownward.java @@ -52,7 +52,7 @@ public class MovementDownward extends Movement { if (ladder) { return LADDER_DOWN_ONE_COST; } else { - return FALL_N_BLOCKS_COST[1] + MovementHelper.getTotalHardnessOfBlocksToBreak(ts, positionsToBreak); + return FALL_N_BLOCKS_COST[1] + getTotalHardnessOfBlocksToBreak(ts); } } } 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 06b3f893..d820c4c7 100644 --- a/src/main/java/baritone/bot/pathing/movement/movements/MovementFall.java +++ b/src/main/java/baritone/bot/pathing/movement/movements/MovementFall.java @@ -12,6 +12,9 @@ import baritone.bot.utils.BlockStateInterface; import baritone.bot.utils.Rotation; import baritone.bot.utils.ToolSet; import baritone.bot.utils.Utils; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemBucket; +import net.minecraft.item.ItemStack; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; @@ -43,7 +46,7 @@ public class MovementFall extends Movement { if(!BlockStateInterface.isWater(dest) && src.getY() - dest.getY() > 3) { placeBucketCost = ActionCosts.PLACE_ONE_BLOCK_COST; } - return WALK_OFF_BLOCK_COST + FALL_N_BLOCKS_COST[positionsToBreak.length - 1] + MovementHelper.getTotalHardnessOfBlocksToBreak(ts, positionsToBreak) + placeBucketCost; + return WALK_OFF_BLOCK_COST + FALL_N_BLOCKS_COST[positionsToBreak.length - 1] + getTotalHardnessOfBlocksToBreak(ts) + placeBucketCost; } @Override @@ -58,6 +61,9 @@ public class MovementFall extends Movement { state.setStatus(MovementStatus.RUNNING); case RUNNING: BlockPos playerFeet = playerFeet(); + if(src.getY() - dest.getY() > 3 && !BlockStateInterface.isWater(dest) && !player().inventory.hasItemStack(new ItemStack(new ItemBucket(Blocks.WATER)))) { + return state.setStatus(MovementStatus.UNREACHABLE); + } if(playerFeet.equals(dest) && (player().posY - playerFeet.getY() < 0.01 || BlockStateInterface.isWater(dest))) return state.setStatus(MovementStatus.SUCCESS); Vec3d destCenter = Utils.calcCenterFromCoords(dest, world()); diff --git a/src/main/java/baritone/bot/pathing/movement/movements/MovementTraverse.java b/src/main/java/baritone/bot/pathing/movement/movements/MovementTraverse.java index bf314d7f..664915c0 100644 --- a/src/main/java/baritone/bot/pathing/movement/movements/MovementTraverse.java +++ b/src/main/java/baritone/bot/pathing/movement/movements/MovementTraverse.java @@ -58,7 +58,7 @@ public class MovementTraverse extends Movement { //double hardness1 = blocksToBreak[0].getBlockHardness(Minecraft.getMinecraft().world, positionsToBreak[0]); //double hardness2 = blocksToBreak[1].getBlockHardness(Minecraft.getMinecraft().world, positionsToBreak[1]); //Out.log("Can't walk through " + blocksToBreak[0] + " (hardness" + hardness1 + ") or " + blocksToBreak[1] + " (hardness " + hardness2 + ")"); - return WC + MovementHelper.getTotalHardnessOfBlocksToBreak(ts, positionsToBreak); + return WC + getTotalHardnessOfBlocksToBreak(ts); } else {//this is a bridge, so we need to place a block //return 1000000; Block f = BlockStateInterface.get(src.down()).getBlock(); @@ -69,11 +69,11 @@ public class MovementTraverse extends Movement { if (pp0.getBlock().equals(Blocks.AIR) || (!BlockStateInterface.isWater(pp0.getBlock()) && pp0.getBlock().isReplaceable(Minecraft.getMinecraft().world, positionsToPlace[0]))) { for (BlockPos against1 : against) { if (BlockStateInterface.get(against1).isBlockNormalCube()) { - return WC + PLACE_ONE_BLOCK_COST + MovementHelper.getTotalHardnessOfBlocksToBreak(ts, positionsToBreak); + return WC + PLACE_ONE_BLOCK_COST + getTotalHardnessOfBlocksToBreak(ts); } } WC = WC * SNEAK_ONE_BLOCK_COST / WALK_ONE_BLOCK_COST;//since we are placing, we are sneaking - return WC + PLACE_ONE_BLOCK_COST + MovementHelper.getTotalHardnessOfBlocksToBreak(ts, positionsToBreak); + return WC + PLACE_ONE_BLOCK_COST + getTotalHardnessOfBlocksToBreak(ts); } return COST_INF; //Out.log("Can't walk on " + Baritone.get(positionsToPlace[0]).getBlock());