From bac07ce1006b9a123bc188d2ad4ce2d685be3bcf Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 3 Sep 2018 09:15:18 -0700 Subject: [PATCH 01/10] slabs --- src/main/java/baritone/chunk/ChunkPacker.java | 15 ++++---- .../baritone/pathing/movement/Movement.java | 20 +--------- .../pathing/movement/MovementHelper.java | 7 +++- .../movement/movements/MovementAscend.java | 37 +++++++++++++++++-- .../movement/movements/MovementDescend.java | 12 +++--- .../movement/movements/MovementDiagonal.java | 6 ++- .../movement/movements/MovementDownward.java | 5 +-- .../movement/movements/MovementFall.java | 6 +++ .../movement/movements/MovementPillar.java | 18 ++++++--- .../movement/movements/MovementTraverse.java | 9 +++-- src/main/java/baritone/utils/Helper.java | 8 ++-- 11 files changed, 91 insertions(+), 52 deletions(-) diff --git a/src/main/java/baritone/chunk/ChunkPacker.java b/src/main/java/baritone/chunk/ChunkPacker.java index fef3c0a5..e52f6a54 100644 --- a/src/main/java/baritone/chunk/ChunkPacker.java +++ b/src/main/java/baritone/chunk/ChunkPacker.java @@ -20,10 +20,7 @@ package baritone.chunk; import baritone.pathing.movement.MovementHelper; import baritone.utils.Helper; import baritone.utils.pathing.PathingBlockType; -import net.minecraft.block.Block; -import net.minecraft.block.BlockDoublePlant; -import net.minecraft.block.BlockFlower; -import net.minecraft.block.BlockTallGrass; +import net.minecraft.block.*; import net.minecraft.block.state.IBlockState; import net.minecraft.init.Blocks; import net.minecraft.util.ResourceLocation; @@ -50,10 +47,11 @@ public final class ChunkPacker implements Helper { for (int z = 0; z < 16; z++) { for (int x = 0; x < 16; x++) { int index = CachedChunk.getPositionIndex(x, y, z); - Block block = chunk.getBlockState(x, y, z).getBlock(); - boolean[] bits = getPathingBlockType(block).getBits(); + IBlockState state = chunk.getBlockState(x, y, z); + boolean[] bits = getPathingBlockType(state).getBits(); bitSet.set(index, bits[0]); bitSet.set(index + 1, bits[1]); + Block block = state.getBlock(); if (CachedChunk.BLOCKS_TO_KEEP_TRACK_OF.contains(block)) { String name = blockToString(block); specialBlocks.computeIfAbsent(name, b -> new ArrayList<>()).add(new BlockPos(x, y, z)); @@ -103,13 +101,14 @@ public final class ChunkPacker implements Helper { return Block.getBlockFromName(name); } - private static PathingBlockType getPathingBlockType(Block block) { + private static PathingBlockType getPathingBlockType(IBlockState state) { + Block block = state.getBlock(); if (block.equals(Blocks.WATER)) { // only water source blocks are plausibly usable, flowing water should be avoid return PathingBlockType.WATER; } - if (MovementHelper.avoidWalkingInto(block) || block.equals(Blocks.FLOWING_WATER)) { + if (MovementHelper.avoidWalkingInto(block) || block.equals(Blocks.FLOWING_WATER) || (block instanceof BlockSlab && state.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.BOTTOM)) { return PathingBlockType.AVOID; } // We used to do an AABB check here diff --git a/src/main/java/baritone/pathing/movement/Movement.java b/src/main/java/baritone/pathing/movement/Movement.java index 715bfd68..9d2f5869 100644 --- a/src/main/java/baritone/pathing/movement/Movement.java +++ b/src/main/java/baritone/pathing/movement/Movement.java @@ -21,13 +21,7 @@ import baritone.Baritone; import baritone.behavior.impl.LookBehavior; import baritone.behavior.impl.LookBehaviorUtils; import baritone.pathing.movement.MovementState.MovementStatus; -import baritone.pathing.movement.movements.MovementDownward; -import baritone.pathing.movement.movements.MovementPillar; -import baritone.pathing.movement.movements.MovementTraverse; import baritone.utils.*; -import net.minecraft.block.Block; -import net.minecraft.block.BlockLadder; -import net.minecraft.block.BlockVine; import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.RayTraceResult; @@ -78,21 +72,11 @@ public abstract class Movement implements Helper, MovementHelper { if (cost == null) { if (context == null) context = new CalculationContext(); - cost = calculateCost0(context); + cost = calculateCost(context); } return cost; } - private double calculateCost0(CalculationContext context) { - if (!(this instanceof MovementPillar) && !(this instanceof MovementTraverse) && !(this instanceof MovementDownward)) { - Block fromDown = BlockStateInterface.get(src.down()).getBlock(); - if (fromDown instanceof BlockLadder || fromDown instanceof BlockVine) { - return COST_INF; - } - } - return calculateCost(context); - } - protected abstract double calculateCost(CalculationContext context); public double recalculateCost() { @@ -101,7 +85,7 @@ public abstract class Movement implements Helper, MovementHelper { } public double calculateCostWithoutCaching() { - return calculateCost0(new CalculationContext()); + return calculateCost(new CalculationContext()); } /** diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 909c21a7..3b5aa748 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -186,6 +186,9 @@ public interface MovementHelper extends ActionCosts, Helper { */ static boolean canWalkOn(BlockPos pos, IBlockState state) { Block block = state.getBlock(); + if (block == Blocks.AIR) { + return false; + } if (block instanceof BlockLadder || (Baritone.settings().allowVines.get() && block instanceof BlockVine)) { // TODO reconsider this return true; } @@ -198,8 +201,8 @@ public interface MovementHelper extends ActionCosts, Helper { if (Blocks.ENDER_CHEST.equals(block) || Blocks.CHEST.equals(block)) { return true; } - if (block instanceof BlockAir) { - return false; + if (block instanceof BlockSlab) { + return true; } if (BlockStateInterface.isWater(block)) { if (BlockStateInterface.isFlowing(state)) { diff --git a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java index a50dfba8..bc94ca48 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java @@ -28,6 +28,7 @@ import baritone.utils.InputOverrideHandler; import baritone.utils.Utils; import net.minecraft.block.Block; import net.minecraft.block.BlockFalling; +import net.minecraft.block.BlockSlab; import net.minecraft.block.state.IBlockState; import net.minecraft.client.Minecraft; import net.minecraft.init.Blocks; @@ -53,7 +54,31 @@ public class MovementAscend extends Movement { @Override protected double calculateCost(CalculationContext context) { + IBlockState srcDown = BlockStateInterface.get(src.down()); + if (srcDown.getBlock() == Blocks.LADDER || srcDown.getBlock() == Blocks.VINE) { + return COST_INF; + } + // we can jump from soul sand, but not from a bottom slab + // the only thing we can ascend onto from a bottom slab is another bottom slab + boolean jumpingFromBottomSlab = false; + if (srcDown.getBlock() instanceof BlockSlab) { + BlockSlab jumpingFrom = (BlockSlab) srcDown.getBlock(); + if (!jumpingFrom.isDouble()) { + jumpingFromBottomSlab = srcDown.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.BOTTOM; + } + } IBlockState toPlace = BlockStateInterface.get(positionToPlace); + boolean jumpingToBottomSlab = false; + if (toPlace.getBlock() instanceof BlockSlab) { + BlockSlab jumpingTo = (BlockSlab) toPlace.getBlock(); + if (!jumpingTo.isDouble() && toPlace.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.BOTTOM) { + jumpingToBottomSlab = true; + } else if (jumpingFromBottomSlab) { + return COST_INF; + } + } else if (jumpingFromBottomSlab) { + return COST_INF; + } if (!MovementHelper.canWalkOn(positionToPlace, toPlace)) { if (!context.hasThrowaway()) { return COST_INF; @@ -96,9 +121,11 @@ public class MovementAscend extends Movement { // it's possible srcUp is AIR from the start, and srcUp2 is falling // and in that scenario, when we arrive and break srcUp2, that lets srcUp3 fall on us and suffocate us } - // TODO maybe change behavior if src.down() is soul sand? double walk = WALK_ONE_BLOCK_COST; - if (toPlace.getBlock().equals(Blocks.SOUL_SAND)) { + if (jumpingToBottomSlab && !jumpingFromBottomSlab) { + return walk + getTotalHardnessOfBlocksToBreak(context); // we don't hit space we just walk into the slab + } + if (!jumpingToBottomSlab && toPlace.getBlock().equals(Blocks.SOUL_SAND)) { walk *= WALK_ONE_OVER_SOUL_SAND_COST / WALK_ONE_BLOCK_COST; } // we hit space immediately on entering this action @@ -123,7 +150,8 @@ public class MovementAscend extends Movement { return state.setStatus(MovementStatus.SUCCESS); } - if (!MovementHelper.canWalkOn(positionToPlace)) { + IBlockState jumpingOnto = BlockStateInterface.get(positionToPlace); + if (!MovementHelper.canWalkOn(positionToPlace, jumpingOnto)) { for (int i = 0; i < 4; i++) { BlockPos anAgainst = positionToPlace.offset(HORIZONTALS[i]); if (anAgainst.equals(src)) { @@ -161,6 +189,9 @@ public class MovementAscend extends Movement { return state.setStatus(MovementStatus.UNREACHABLE); } MovementHelper.moveTowards(state, dest); + if (jumpingOnto.getBlock() instanceof BlockSlab && !((BlockSlab) jumpingOnto.getBlock()).isDouble() && jumpingOnto.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.BOTTOM && !(BlockStateInterface.get(src.down()).getBlock() instanceof BlockSlab)) { + return state; // don't jump while walking from a non slab into a bottom slab + } if (headBonkClear()) { return state.setInput(InputOverrideHandler.Input.JUMP, true); diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDescend.java b/src/main/java/baritone/pathing/movement/movements/MovementDescend.java index 7a07abb1..8ab66af1 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDescend.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDescend.java @@ -25,8 +25,6 @@ import baritone.pathing.movement.MovementState.MovementStatus; import baritone.utils.BlockStateInterface; import baritone.utils.InputOverrideHandler; import net.minecraft.block.Block; -import net.minecraft.block.BlockLadder; -import net.minecraft.block.BlockVine; import net.minecraft.init.Blocks; import net.minecraft.util.math.BlockPos; @@ -44,18 +42,22 @@ public class MovementDescend extends Movement { @Override protected double calculateCost(CalculationContext context) { + Block fromDown = BlockStateInterface.get(src.down()).getBlock(); + if (fromDown == Blocks.LADDER || fromDown == Blocks.VINE) { + return COST_INF; + } if (!MovementHelper.canWalkOn(positionToPlace)) { return COST_INF; } Block tmp1 = BlockStateInterface.get(dest).getBlock(); - if (tmp1 instanceof BlockLadder || tmp1 instanceof BlockVine) { + if (tmp1 == Blocks.LADDER || tmp1 == Blocks.VINE) { return COST_INF; } // 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) double walk = WALK_OFF_BLOCK_COST; - if (BlockStateInterface.get(src.down()).getBlock().equals(Blocks.SOUL_SAND)) { + if (fromDown == Blocks.SOUL_SAND) { // use this ratio to apply the soul sand speed penalty to our 0.8 block distance - walk *= WALK_ONE_OVER_SOUL_SAND_COST / WALK_ONE_BLOCK_COST; + walk = WALK_ONE_OVER_SOUL_SAND_COST; } return walk + Math.max(FALL_N_BLOCKS_COST[1], CENTER_AFTER_FALL_COST) + getTotalHardnessOfBlocksToBreak(context); } diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java index 1ce5537f..2bf8bdf1 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java @@ -75,6 +75,10 @@ public class MovementDiagonal extends Movement { @Override protected double calculateCost(CalculationContext context) { + Block fromDown = BlockStateInterface.get(src.down()).getBlock(); + if (fromDown == Blocks.LADDER || fromDown == Blocks.VINE) { + return COST_INF; + } if (!MovementHelper.canWalkThrough(positionsToBreak[4]) || !MovementHelper.canWalkThrough(positionsToBreak[5])) { return COST_INF; } @@ -88,7 +92,7 @@ public class MovementDiagonal extends Movement { if (destWalkOn.getBlock().equals(Blocks.SOUL_SAND)) { multiplier += (WALK_ONE_OVER_SOUL_SAND_COST - WALK_ONE_BLOCK_COST) / 2; } - if (BlockStateInterface.get(src.down()).getBlock().equals(Blocks.SOUL_SAND)) { + if (fromDown == Blocks.SOUL_SAND) { multiplier += (WALK_ONE_OVER_SOUL_SAND_COST - WALK_ONE_BLOCK_COST) / 2; } Block cuttingOver1 = BlockStateInterface.get(positionsToBreak[2].down()).getBlock(); diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDownward.java b/src/main/java/baritone/pathing/movement/movements/MovementDownward.java index ece2c8f5..13555399 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDownward.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDownward.java @@ -23,9 +23,8 @@ import baritone.pathing.movement.MovementHelper; import baritone.pathing.movement.MovementState; import baritone.utils.BlockStateInterface; import net.minecraft.block.Block; -import net.minecraft.block.BlockLadder; -import net.minecraft.block.BlockVine; import net.minecraft.block.state.IBlockState; +import net.minecraft.init.Blocks; import net.minecraft.util.math.BlockPos; public class MovementDownward extends Movement { @@ -49,7 +48,7 @@ public class MovementDownward extends Movement { } IBlockState d = BlockStateInterface.get(dest); Block td = d.getBlock(); - boolean ladder = td instanceof BlockLadder || td instanceof BlockVine; + boolean ladder = td == Blocks.LADDER || td == Blocks.VINE; if (ladder) { return LADDER_DOWN_ONE_COST; } else { diff --git a/src/main/java/baritone/pathing/movement/movements/MovementFall.java b/src/main/java/baritone/pathing/movement/movements/MovementFall.java index ee019c98..95509574 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementFall.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementFall.java @@ -25,7 +25,9 @@ import baritone.pathing.movement.MovementState; import baritone.pathing.movement.MovementState.MovementStatus; import baritone.pathing.movement.MovementState.MovementTarget; import baritone.utils.*; +import net.minecraft.block.Block; import net.minecraft.block.BlockFalling; +import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; import net.minecraft.util.math.BlockPos; @@ -43,6 +45,10 @@ public class MovementFall extends Movement { @Override protected double calculateCost(CalculationContext context) { + Block fromDown = BlockStateInterface.get(src.down()).getBlock(); + if (fromDown == Blocks.LADDER || fromDown == Blocks.VINE) { + return COST_INF; + } if (!MovementHelper.canWalkOn(dest.down())) { return COST_INF; } diff --git a/src/main/java/baritone/pathing/movement/movements/MovementPillar.java b/src/main/java/baritone/pathing/movement/movements/MovementPillar.java index d7ff3016..fecd79ec 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementPillar.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementPillar.java @@ -47,11 +47,16 @@ public class MovementPillar extends Movement { protected double calculateCost(CalculationContext context) { Block fromDown = BlockStateInterface.get(src).getBlock(); boolean ladder = fromDown instanceof BlockLadder || fromDown instanceof BlockVine; - Block fromDownDown = BlockStateInterface.get(src.down()).getBlock(); + IBlockState fromDownDown = BlockStateInterface.get(src.down()); if (!ladder) { - if (fromDownDown instanceof BlockLadder || fromDownDown instanceof BlockVine) { + if (fromDownDown.getBlock() instanceof BlockLadder || fromDownDown.getBlock() instanceof BlockVine) { return COST_INF; } + if (fromDownDown.getBlock() instanceof BlockSlab) { + if (!((BlockSlab) fromDownDown.getBlock()).isDouble() && fromDownDown.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.BOTTOM) { + return COST_INF; // can't pillar up from a bottom slab onto a non ladder + } + } } if (!context.hasThrowaway() && !ladder) { return COST_INF; @@ -87,7 +92,7 @@ public class MovementPillar extends Movement { //} } } - if (fromDown instanceof BlockLiquid || fromDownDown instanceof BlockLiquid) {//can't pillar on water or in water + if (fromDown instanceof BlockLiquid || fromDownDown.getBlock() instanceof BlockLiquid) {//can't pillar on water or in water return COST_INF; } if (ladder) { @@ -142,9 +147,12 @@ public class MovementPillar extends Movement { return state.setStatus(MovementState.MovementStatus.UNREACHABLE); } - if (playerFeet().equals(against.up()) || playerFeet().equals(dest)) + if (playerFeet().equals(against.up()) || playerFeet().equals(dest)) { return state.setStatus(MovementState.MovementStatus.SUCCESS); - + } + if (fromDown.getBlock() instanceof BlockSlab && !((BlockSlab) fromDown.getBlock()).isDouble() && fromDown.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.BOTTOM) { + state.setInput(InputOverrideHandler.Input.JUMP, true); + } /* if (thePlayer.getPosition0().getX() != from.getX() || thePlayer.getPosition0().getZ() != from.getZ()) { Baritone.moveTowardsBlock(from); diff --git a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java index a959455b..af0b7b27 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java @@ -85,7 +85,7 @@ public class MovementTraverse extends Movement { return WC + hardness1 + hardness2; } else {//this is a bridge, so we need to place a block Block srcDown = BlockStateInterface.get(src.down()).getBlock(); - if (srcDown instanceof BlockLadder || srcDown instanceof BlockVine) { + if (srcDown == Blocks.LADDER || srcDown == Blocks.VINE) { return COST_INF; } if (destOn.getBlock().equals(Blocks.AIR) || MovementHelper.isReplacable(positionToPlace, destOn)) { @@ -107,8 +107,8 @@ public class MovementTraverse extends Movement { return WC + context.placeBlockCost() + getTotalHardnessOfBlocksToBreak(context); } } - if (Blocks.SOUL_SAND.equals(srcDown)) { - return COST_INF; // can't sneak and backplace against soul sand =/ + if (srcDown == Blocks.SOUL_SAND || (srcDown instanceof BlockSlab && !((BlockSlab) srcDown).isDouble())) { + return COST_INF; // can't sneak and backplace against soul sand or half slabs =/ } WC = WC * SNEAK_ONE_BLOCK_COST / WALK_ONE_BLOCK_COST;//since we are placing, we are sneaking return WC + context.placeBlockCost() + getTotalHardnessOfBlocksToBreak(context); @@ -206,7 +206,8 @@ public class MovementTraverse extends Movement { return state.setStatus(MovementState.MovementStatus.UNREACHABLE); } state.setInput(InputOverrideHandler.Input.SNEAK, true); - if (BlockStateInterface.get(playerFeet().down()).getBlock().equals(Blocks.SOUL_SAND)) { // see issue #118 + Block standingOn = BlockStateInterface.get(playerFeet().down()).getBlock(); + if (standingOn.equals(Blocks.SOUL_SAND) || standingOn instanceof BlockSlab) { // see issue #118 double dist = Math.max(Math.abs(dest.getX() + 0.5 - player().posX), Math.abs(dest.getZ() + 0.5 - player().posZ)); if (dist < 0.85) { // 0.5 + 0.3 + epsilon MovementHelper.moveTowards(state, dest); diff --git a/src/main/java/baritone/utils/Helper.java b/src/main/java/baritone/utils/Helper.java index c973b1ca..63fc6df7 100755 --- a/src/main/java/baritone/utils/Helper.java +++ b/src/main/java/baritone/utils/Helper.java @@ -18,6 +18,7 @@ package baritone.utils; import baritone.Baritone; +import net.minecraft.block.BlockSlab; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.multiplayer.WorldClient; @@ -47,10 +48,11 @@ public interface Helper { default BlockPos playerFeet() { // TODO find a better way to deal with soul sand!!!!! - return new BlockPos(player().posX, player().posY + 0.1251, player().posZ); - /*if (BlockStateInterface.get(feet).getBlock().equals(Blocks.SOUL_SAND) && player().posY > feet.getY() + 0.874999) { + BlockPos feet = new BlockPos(player().posX, player().posY + 0.1251, player().posZ); + if (BlockStateInterface.get(feet).getBlock() instanceof BlockSlab) { return feet.up(); - }*/ + } + return feet; } default Vec3d playerFeetAsVec() { From 16f88aa858c2f7d6a4f2c26f4b6a631be04d1875 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 3 Sep 2018 09:18:30 -0700 Subject: [PATCH 02/10] setting --- src/main/java/baritone/Settings.java | 6 ++++++ src/main/java/baritone/pathing/movement/MovementHelper.java | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/src/main/java/baritone/Settings.java b/src/main/java/baritone/Settings.java index 78c2d4b3..2e6f0e39 100644 --- a/src/main/java/baritone/Settings.java +++ b/src/main/java/baritone/Settings.java @@ -77,6 +77,12 @@ public class Settings { */ public Setting allowVines = new Setting<>(false); + /** + * Slab behavior is complicated, disable this for higher path reliability. Leave enabled if you have bottom slabs + * everywhere in your base. + */ + public Setting allowWalkOnBottomSlab = new Setting<>(true); + /** * This is the big A* setting. * As long as your cost heuristic is an *underestimate*, it's guaranteed to find you the best path. diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 3b5aa748..5561f365 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -202,6 +202,12 @@ public interface MovementHelper extends ActionCosts, Helper { return true; } if (block instanceof BlockSlab) { + if (!Baritone.settings().allowWalkOnBottomSlab.get()) { + if (((BlockSlab) block).isDouble()) { + return true; + } + return state.getValue(BlockSlab.HALF) != BlockSlab.EnumBlockHalf.BOTTOM; + } return true; } if (BlockStateInterface.isWater(block)) { From d328438cf2266097ed3a707af30428073b967b53 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 3 Sep 2018 09:21:26 -0700 Subject: [PATCH 03/10] no falling onto half slab --- .../pathing/movement/movements/MovementFall.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/baritone/pathing/movement/movements/MovementFall.java b/src/main/java/baritone/pathing/movement/movements/MovementFall.java index 95509574..0cb9780a 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementFall.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementFall.java @@ -27,6 +27,8 @@ import baritone.pathing.movement.MovementState.MovementTarget; import baritone.utils.*; import net.minecraft.block.Block; import net.minecraft.block.BlockFalling; +import net.minecraft.block.BlockSlab; +import net.minecraft.block.state.IBlockState; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; @@ -49,9 +51,15 @@ public class MovementFall extends Movement { if (fromDown == Blocks.LADDER || fromDown == Blocks.VINE) { return COST_INF; } - if (!MovementHelper.canWalkOn(dest.down())) { + IBlockState fallOnto = BlockStateInterface.get(dest.down()); + if (!MovementHelper.canWalkOn(dest.down(), fallOnto)) { return COST_INF; } + if (fallOnto.getBlock() instanceof BlockSlab) { + if (!((BlockSlab) fallOnto.getBlock()).isDouble() && fallOnto.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.BOTTOM) { + return COST_INF; // falling onto a half slab is really glitchy, and can cause more fall damage than we'd expect + } + } double placeBucketCost = 0.0; if (!BlockStateInterface.isWater(dest) && src.getY() - dest.getY() > context.maxFallHeightNoWater()) { if (!context.hasWaterBucket()) { From 7473e34602a32324714d3d603007b5d78043e040 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 3 Sep 2018 09:24:44 -0700 Subject: [PATCH 04/10] check for top or double slab --- .../pathing/movement/movements/MovementAscend.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java index bc94ca48..46162806 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java @@ -189,8 +189,11 @@ public class MovementAscend extends Movement { return state.setStatus(MovementStatus.UNREACHABLE); } MovementHelper.moveTowards(state, dest); - if (jumpingOnto.getBlock() instanceof BlockSlab && !((BlockSlab) jumpingOnto.getBlock()).isDouble() && jumpingOnto.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.BOTTOM && !(BlockStateInterface.get(src.down()).getBlock() instanceof BlockSlab)) { - return state; // don't jump while walking from a non slab into a bottom slab + if (jumpingOnto.getBlock() instanceof BlockSlab && !((BlockSlab) jumpingOnto.getBlock()).isDouble() && jumpingOnto.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.BOTTOM) { + IBlockState from = BlockStateInterface.get(src.down()); + if (!(from.getBlock() instanceof BlockSlab) || ((BlockSlab) from.getBlock()).isDouble() || from.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.TOP) { + return state; // don't jump while walking from a non double slab into a bottom slab + } } if (headBonkClear()) { From 4b2f98ccfd16b29c3d431a91d7f68cf029f165e1 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 3 Sep 2018 09:50:26 -0700 Subject: [PATCH 05/10] consolidate and simplify into MovementHelper.isBottomSlab --- src/main/java/baritone/chunk/ChunkPacker.java | 7 +++-- .../pathing/movement/MovementHelper.java | 10 +++++++ .../movement/movements/MovementAscend.java | 29 +++++-------------- .../movement/movements/MovementFall.java | 7 ++--- .../movement/movements/MovementPillar.java | 2 +- 5 files changed, 25 insertions(+), 30 deletions(-) diff --git a/src/main/java/baritone/chunk/ChunkPacker.java b/src/main/java/baritone/chunk/ChunkPacker.java index e52f6a54..82a36709 100644 --- a/src/main/java/baritone/chunk/ChunkPacker.java +++ b/src/main/java/baritone/chunk/ChunkPacker.java @@ -20,7 +20,10 @@ package baritone.chunk; import baritone.pathing.movement.MovementHelper; import baritone.utils.Helper; import baritone.utils.pathing.PathingBlockType; -import net.minecraft.block.*; +import net.minecraft.block.Block; +import net.minecraft.block.BlockDoublePlant; +import net.minecraft.block.BlockFlower; +import net.minecraft.block.BlockTallGrass; import net.minecraft.block.state.IBlockState; import net.minecraft.init.Blocks; import net.minecraft.util.ResourceLocation; @@ -108,7 +111,7 @@ public final class ChunkPacker implements Helper { return PathingBlockType.WATER; } - if (MovementHelper.avoidWalkingInto(block) || block.equals(Blocks.FLOWING_WATER) || (block instanceof BlockSlab && state.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.BOTTOM)) { + if (MovementHelper.avoidWalkingInto(block) || block.equals(Blocks.FLOWING_WATER) || MovementHelper.isBottomSlab(state)) { return PathingBlockType.AVOID; } // We used to do an AABB check here diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 5561f365..3e019745 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -270,6 +270,16 @@ public interface MovementHelper extends ActionCosts, Helper { return 0; // we won't actually mine it, so don't check fallings above } + static boolean isBottomSlab(IBlockState state) { + return state.getBlock() instanceof BlockSlab + && !((BlockSlab) state.getBlock()).isDouble() + && state.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.BOTTOM; + } + + static boolean isBottomSlab(BlockPos pos) { + return isBottomSlab(BlockStateInterface.get(pos)); + } + /** * The entity the player is currently looking at * diff --git a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java index 46162806..d666ff6a 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java @@ -28,7 +28,6 @@ import baritone.utils.InputOverrideHandler; import baritone.utils.Utils; import net.minecraft.block.Block; import net.minecraft.block.BlockFalling; -import net.minecraft.block.BlockSlab; import net.minecraft.block.state.IBlockState; import net.minecraft.client.Minecraft; import net.minecraft.init.Blocks; @@ -59,25 +58,12 @@ public class MovementAscend extends Movement { return COST_INF; } // we can jump from soul sand, but not from a bottom slab - // the only thing we can ascend onto from a bottom slab is another bottom slab - boolean jumpingFromBottomSlab = false; - if (srcDown.getBlock() instanceof BlockSlab) { - BlockSlab jumpingFrom = (BlockSlab) srcDown.getBlock(); - if (!jumpingFrom.isDouble()) { - jumpingFromBottomSlab = srcDown.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.BOTTOM; - } - } + boolean jumpingFromBottomSlab = MovementHelper.isBottomSlab(srcDown); IBlockState toPlace = BlockStateInterface.get(positionToPlace); - boolean jumpingToBottomSlab = false; - if (toPlace.getBlock() instanceof BlockSlab) { - BlockSlab jumpingTo = (BlockSlab) toPlace.getBlock(); - if (!jumpingTo.isDouble() && toPlace.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.BOTTOM) { - jumpingToBottomSlab = true; - } else if (jumpingFromBottomSlab) { - return COST_INF; - } - } else if (jumpingFromBottomSlab) { - return COST_INF; + boolean jumpingToBottomSlab = MovementHelper.isBottomSlab(toPlace); + + if (jumpingFromBottomSlab && !jumpingToBottomSlab) { + return COST_INF;// the only thing we can ascend onto from a bottom slab is another bottom slab } if (!MovementHelper.canWalkOn(positionToPlace, toPlace)) { if (!context.hasThrowaway()) { @@ -189,9 +175,8 @@ public class MovementAscend extends Movement { return state.setStatus(MovementStatus.UNREACHABLE); } MovementHelper.moveTowards(state, dest); - if (jumpingOnto.getBlock() instanceof BlockSlab && !((BlockSlab) jumpingOnto.getBlock()).isDouble() && jumpingOnto.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.BOTTOM) { - IBlockState from = BlockStateInterface.get(src.down()); - if (!(from.getBlock() instanceof BlockSlab) || ((BlockSlab) from.getBlock()).isDouble() || from.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.TOP) { + if (MovementHelper.isBottomSlab(jumpingOnto)) { + if (!MovementHelper.isBottomSlab(src.down())) { return state; // don't jump while walking from a non double slab into a bottom slab } } diff --git a/src/main/java/baritone/pathing/movement/movements/MovementFall.java b/src/main/java/baritone/pathing/movement/movements/MovementFall.java index 0cb9780a..e82640d2 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementFall.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementFall.java @@ -27,7 +27,6 @@ import baritone.pathing.movement.MovementState.MovementTarget; import baritone.utils.*; import net.minecraft.block.Block; import net.minecraft.block.BlockFalling; -import net.minecraft.block.BlockSlab; import net.minecraft.block.state.IBlockState; import net.minecraft.init.Blocks; import net.minecraft.init.Items; @@ -55,10 +54,8 @@ public class MovementFall extends Movement { if (!MovementHelper.canWalkOn(dest.down(), fallOnto)) { return COST_INF; } - if (fallOnto.getBlock() instanceof BlockSlab) { - if (!((BlockSlab) fallOnto.getBlock()).isDouble() && fallOnto.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.BOTTOM) { - return COST_INF; // falling onto a half slab is really glitchy, and can cause more fall damage than we'd expect - } + if (MovementHelper.isBottomSlab(fallOnto)) { + return COST_INF; // falling onto a half slab is really glitchy, and can cause more fall damage than we'd expect } double placeBucketCost = 0.0; if (!BlockStateInterface.isWater(dest) && src.getY() - dest.getY() > context.maxFallHeightNoWater()) { diff --git a/src/main/java/baritone/pathing/movement/movements/MovementPillar.java b/src/main/java/baritone/pathing/movement/movements/MovementPillar.java index fecd79ec..481553fa 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementPillar.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementPillar.java @@ -150,7 +150,7 @@ public class MovementPillar extends Movement { if (playerFeet().equals(against.up()) || playerFeet().equals(dest)) { return state.setStatus(MovementState.MovementStatus.SUCCESS); } - if (fromDown.getBlock() instanceof BlockSlab && !((BlockSlab) fromDown.getBlock()).isDouble() && fromDown.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.BOTTOM) { + if (MovementHelper.isBottomSlab(src.down())) { state.setInput(InputOverrideHandler.Input.JUMP, true); } /* From bfd41f94734ddf02f0b52be39ccafae96c4949d4 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 3 Sep 2018 11:27:59 -0700 Subject: [PATCH 06/10] stairs --- src/main/java/baritone/pathing/movement/MovementHelper.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 3e019745..80026c6f 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -210,6 +210,9 @@ public interface MovementHelper extends ActionCosts, Helper { } return true; } + if (block instanceof BlockStairs) { + return true; + } if (BlockStateInterface.isWater(block)) { if (BlockStateInterface.isFlowing(state)) { return false; From 6eb293c97a37f098d67af874e0b428d06d660e8a Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 3 Sep 2018 11:33:02 -0700 Subject: [PATCH 07/10] update documentation --- FEATURES.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/FEATURES.md b/FEATURES.md index 8147fc22..436aefc8 100644 --- a/FEATURES.md +++ b/FEATURES.md @@ -5,7 +5,8 @@ - **Block placing** Baritone considers placing blocks as part of its path. This includes sneak-back-placing, pillaring, etc. It has a configurable penalty of placing a block (set to 1 second by default), to conserve its resources. The list of acceptable throwaway blocks is also configurable, and is cobble, dirt, or netherrack by default. - **Falling** Baritone will fall up to 3 blocks onto solid ground (configurable, if you have Feather Falling and/or don't mind taking a little damage). If you have a water bucket on your hotbar, it will fall up to 23 blocks and place the bucket beneath it. It will fall an unlimited distance into existing still water. - **Vines and ladders** Baritone understands how to climb and descend vines and ladders. There is experimental support for more advanced maneuvers, like strafing to a different ladder / vine column in midair (off by default, setting named `allowVines`). -- **Fence gates and doors** +- **Opening fence gates and doors** +- **Slabs and stairs** - **Falling blocks** Baritone understands the costs of breaking blocks with falling blocks on top, and includes all of their break costs. Additionally, since it avoids breaking any blocks touching a liquid, it won't break the bottom of a gravel stack below a lava lake (anymore). - **Avoiding dangerous blocks** Obviously, it knows not to walk through fire or on magma, not to corner over lava (that deals some damage), not to break any blocks touching a liquid (it might drown), etc. @@ -35,9 +36,7 @@ And finally `GoalComposite`. `GoalComposite` is a list of other goals, any one o # Future features Things it doesn't have yet - Trapdoors -- Slabs (double, top, and bottom) - Sprint jumping in a 1x2 corridor -- Stairs See issues for more. From dd1a20a04792f0fb1c5d5669fce3bd23142da151 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 3 Sep 2018 16:14:14 -0700 Subject: [PATCH 08/10] final makes things faster --- src/main/java/baritone/utils/pathing/BetterBlockPos.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/utils/pathing/BetterBlockPos.java b/src/main/java/baritone/utils/pathing/BetterBlockPos.java index 6e4fc599..ec8891f4 100644 --- a/src/main/java/baritone/utils/pathing/BetterBlockPos.java +++ b/src/main/java/baritone/utils/pathing/BetterBlockPos.java @@ -26,7 +26,7 @@ import net.minecraft.util.math.Vec3i; * * @author leijurv */ -public class BetterBlockPos extends BlockPos { +public final class BetterBlockPos extends BlockPos { public final int x; public final int y; public final int z; From 07a9829865c47501de76fabac43ffabb7877c2c1 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 3 Sep 2018 16:24:43 -0700 Subject: [PATCH 09/10] accurate debug --- src/main/java/baritone/pathing/calc/AStarPathFinder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/pathing/calc/AStarPathFinder.java b/src/main/java/baritone/pathing/calc/AStarPathFinder.java index fa8b5076..73442998 100644 --- a/src/main/java/baritone/pathing/calc/AStarPathFinder.java +++ b/src/main/java/baritone/pathing/calc/AStarPathFinder.java @@ -200,7 +200,7 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper { return Optional.of(new Path(startNode, bestSoFar[i], numNodes)); } } - displayChatMessageRaw("Even with a cost coefficient of " + COEFFICIENTS[COEFFICIENTS.length - 1] + ", I couldn't get more than " + bestDist + " blocks"); + displayChatMessageRaw("Even with a cost coefficient of " + COEFFICIENTS[COEFFICIENTS.length - 1] + ", I couldn't get more than " + Math.sqrt(bestDist) + " blocks"); displayChatMessageRaw("No path found =("); currentlyRunning = null; return Optional.empty(); From 3fd1063e3c43e5fdeaf2028cb5e9af1478dd0f7b Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 4 Sep 2018 10:06:48 -0700 Subject: [PATCH 10/10] cache on block not blockstate --- src/main/java/baritone/utils/ToolSet.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/baritone/utils/ToolSet.java b/src/main/java/baritone/utils/ToolSet.java index 415d8ebd..a5684280 100644 --- a/src/main/java/baritone/utils/ToolSet.java +++ b/src/main/java/baritone/utils/ToolSet.java @@ -72,10 +72,10 @@ public class ToolSet implements Helper { private Map slotCache = new HashMap<>(); /** - * A cache mapping a {@link IBlockState} to how long it will take to break + * A cache mapping a {@link Block} to how long it will take to break * with this toolset, given the optimum tool is used. */ - private Map breakStrengthCache = new HashMap<>(); + private Map breakStrengthCache = new HashMap<>(); /** * Create a toolset from the current player's inventory (but don't calculate any hardness values just yet) @@ -146,7 +146,7 @@ public class ToolSet implements Helper { * @return how long it would take in ticks */ public double getStrVsBlock(IBlockState state, BlockPos pos) { - return this.breakStrengthCache.computeIfAbsent(state, s -> calculateStrVsBlock(s, pos)); + return this.breakStrengthCache.computeIfAbsent(state.getBlock(), b -> calculateStrVsBlock(state, pos)); } /**