From 703c3b766b2a1e1539b6a68386ba6ccd93b60d11 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 6 Aug 2018 19:48:09 -0700 Subject: [PATCH] water drop works --- .../bot/behavior/impl/PathingBehavior.java | 4 +- .../bot/pathing/calc/AStarPathFinder.java | 27 +++++++------ .../bot/pathing/movement/MovementHelper.java | 9 ++++- .../movement/movements/MovementFall.java | 38 +++++++++++++++++++ .../movement/movements/MovementTraverse.java | 2 +- 5 files changed, 61 insertions(+), 19 deletions(-) diff --git a/src/main/java/baritone/bot/behavior/impl/PathingBehavior.java b/src/main/java/baritone/bot/behavior/impl/PathingBehavior.java index 2e4da52f..9be45c95 100644 --- a/src/main/java/baritone/bot/behavior/impl/PathingBehavior.java +++ b/src/main/java/baritone/bot/behavior/impl/PathingBehavior.java @@ -161,8 +161,8 @@ public class PathingBehavior extends Behavior { }); }); long end = System.currentTimeMillis(); - if (end - start > 0) - System.out.println("Frame took " + (split - start) + " " + (end - split)); + // if (end - start > 0) + // System.out.println("Frame took " + (split - start) + " " + (end - split)); } public void drawPath(IPath path, EntityPlayerSP player, float partialTicks, Color color) { diff --git a/src/main/java/baritone/bot/pathing/calc/AStarPathFinder.java b/src/main/java/baritone/bot/pathing/calc/AStarPathFinder.java index 2423865e..f62b5a71 100644 --- a/src/main/java/baritone/bot/pathing/calc/AStarPathFinder.java +++ b/src/main/java/baritone/bot/pathing/calc/AStarPathFinder.java @@ -5,10 +5,14 @@ import baritone.bot.pathing.calc.openset.IOpenSet; import baritone.bot.pathing.goals.Goal; import baritone.bot.pathing.movement.ActionCosts; import baritone.bot.pathing.movement.Movement; -import baritone.bot.pathing.movement.movements.*; +import baritone.bot.pathing.movement.movements.MovementAscend; +import baritone.bot.pathing.movement.movements.MovementDownward; +import baritone.bot.pathing.movement.movements.MovementFall; +import baritone.bot.pathing.movement.movements.MovementTraverse; import baritone.bot.pathing.path.IPath; import baritone.bot.utils.ToolSet; import net.minecraft.client.Minecraft; +import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; import net.minecraft.world.chunk.EmptyChunk; @@ -74,6 +78,9 @@ public class AStarPathFinder extends AbstractNodeCostSearch { //long constructEnd = System.nanoTime(); //System.out.println(constructEnd - constructStart); for (Movement movementToGetToNeighbor : possibleMovements) { + if (movementToGetToNeighbor == null) { + continue; + } if (Minecraft.getMinecraft().world.getChunk(movementToGetToNeighbor.getDest()) instanceof EmptyChunk) { numEmptyChunk++; continue; @@ -147,7 +154,7 @@ public class AStarPathFinder extends AbstractNodeCostSearch { int x = pos.getX(); int y = pos.getY(); int z = pos.getZ(); - Movement[] movements = new Movement[21]; + Movement[] movements = new Movement[13]; 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)); @@ -156,19 +163,11 @@ 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)); + movements[8] = MovementFall.generateMovementFallOrDescend(pos, EnumFacing.NORTH); + movements[9] = MovementFall.generateMovementFallOrDescend(pos, EnumFacing.SOUTH); + movements[10] = MovementFall.generateMovementFallOrDescend(pos, EnumFacing.EAST); + movements[11] = MovementFall.generateMovementFallOrDescend(pos, EnumFacing.WEST); movements[12] = new MovementDownward(pos); - movements[13] = new MovementFall(pos, new BlockPos(x, y - 2, z - 1)); - movements[14] = new MovementFall(pos, new BlockPos(x, y - 2, z + 1)); - movements[15] = new MovementFall(pos, new BlockPos(x - 1, y - 2, z)); - movements[16] = new MovementFall(pos, new BlockPos(x + 1, y - 2, z)); - movements[17] = new MovementFall(pos, new BlockPos(x, y - 3, z - 1)); - movements[18] = new MovementFall(pos, new BlockPos(x, y - 3, z + 1)); - movements[19] = new MovementFall(pos, new BlockPos(x - 1, y - 3, z)); - movements[20] = new MovementFall(pos, new BlockPos(x + 1, y - 3, z)); /*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/MovementHelper.java b/src/main/java/baritone/bot/pathing/movement/MovementHelper.java index 435d3a7f..700aee7c 100644 --- a/src/main/java/baritone/bot/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/bot/pathing/movement/MovementHelper.java @@ -80,8 +80,8 @@ public interface MovementHelper extends ActionCosts, Helper { * * @return */ - static boolean canWalkOn(BlockPos pos) { - IBlockState state = BlockStateInterface.get(pos); + static boolean canWalkOn(BlockPos pos, IBlockState state) { + Block block = state.getBlock(); if (block instanceof BlockLadder || block instanceof BlockVine) { return true; @@ -95,6 +95,11 @@ public interface MovementHelper extends ActionCosts, Helper { return state.isBlockNormalCube() && !BlockStateInterface.isLava(block); } + static boolean canWalkOn(BlockPos pos) { + IBlockState state = BlockStateInterface.get(pos); + return canWalkOn(pos, state); + } + static boolean canFall(BlockPos pos) { return BlockStateInterface.get(pos).getBlock() instanceof BlockFalling; } 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 6606abe1..d8a7d59a 100644 --- a/src/main/java/baritone/bot/pathing/movement/movements/MovementFall.java +++ b/src/main/java/baritone/bot/pathing/movement/movements/MovementFall.java @@ -12,9 +12,12 @@ import baritone.bot.utils.BlockStateInterface; import baritone.bot.utils.Rotation; import baritone.bot.utils.ToolSet; import baritone.bot.utils.Utils; +import net.minecraft.block.BlockAir; +import net.minecraft.block.state.IBlockState; import net.minecraft.init.Blocks; import net.minecraft.item.ItemBucket; import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; @@ -37,6 +40,41 @@ public class MovementFall extends Movement { super(src, dest, MovementFall.buildPositionsToBreak(src, dest), new BlockPos[]{dest.down()}); } + public static Movement generateMovementFallOrDescend(BlockPos pos, EnumFacing direction) { + BlockPos dest = pos.offset(direction); + BlockPos destUp = dest.up(); + BlockPos destDown = dest.down(); + for (int i = 0; i < 4; i++) { + if (!(BlockStateInterface.get(destUp.down(i)).getBlock() instanceof BlockAir)) { + //if any of these four aren't air, that means that a fall N isn't possible + //so try a movementdescend + + //if all four of them are air, a movementdescend isn't possible anyway + return new MovementDescend(pos, destDown); + } + } + // we're clear for a fall 2 + // let's see how far we can fall + for (int fallHeight = 3; true; fallHeight++) { + BlockPos onto = dest.down(fallHeight); + if (onto.getY() <= 0) { + break; + } + IBlockState fallOn = BlockStateInterface.get(onto); + if (fallOn.getBlock() instanceof BlockAir) { + continue; + } + if (BlockStateInterface.isWater(fallOn.getBlock())) { + return new MovementFall(pos, onto); + } + if (MovementHelper.canWalkOn(onto)) { + return new MovementFall(pos, onto); + } + break; + } + return null; + } + @Override protected double calculateCost(ToolSet ts) { if (!MovementHelper.canWalkOn(positionsToPlace[0])) { 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 99333161..94fa47ae 100644 --- a/src/main/java/baritone/bot/pathing/movement/movements/MovementTraverse.java +++ b/src/main/java/baritone/bot/pathing/movement/movements/MovementTraverse.java @@ -141,7 +141,7 @@ public class MovementTraverse extends Movement { //Out.gui("Wrong. " + side + " " + LookBehaviorUtils.getSelectedBlock().get().offset(side) + " " + positionsToPlace[0], Out.Mode.Debug); } } - displayChatMessageRaw("Trying to look at " + against1 + ", actually looking at" + LookBehaviorUtils.getSelectedBlock()); + System.out.println("Trying to look at " + against1 + ", actually looking at" + LookBehaviorUtils.getSelectedBlock()); return state; } }