From 54da0d24a394ec2d89dc5a4b1820ea969d6fa055 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Wed, 1 May 2019 11:16:24 -0700 Subject: [PATCH] dont mine blocks that update falling blocks, fixes #395 --- src/api/java/baritone/api/Settings.java | 9 +++++++- .../pathing/movement/MovementHelper.java | 22 +++++++++++++------ 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index bb6038b6..a2de8b40 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -160,7 +160,7 @@ public final class Settings { /** * Blocks that Baritone is not allowed to break */ - public final Setting> blocksToAvoidBreaking = new Setting<>(new ArrayList<>(Arrays.asList( + public final Setting> blocksToAvoidBreaking = new Setting<>(new ArrayList<>(Arrays.asList( // TODO can this be a HashSet or ImmutableSet? Blocks.CRAFTING_TABLE, Blocks.FURNACE, Blocks.LIT_FURNACE, @@ -168,6 +168,13 @@ public final class Settings { Blocks.TRAPPED_CHEST ))); + /** + * If this setting is true, Baritone will never break a block that is adjacent to an unsupported falling block. + *

+ * I.E. it will never trigger cascading sand / gravel falls + */ + public final Setting avoidUpdatingFallingBlocks = new Setting<>(true); + /** * Enables some more advanced vine features. They're honestly just gimmicks and won't ever be needed in real * pathing scenarios. And they can cause Baritone to get trapped indefinitely in a strange scenario. diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 6a0b07f0..d8f6a2f7 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -51,19 +51,27 @@ public interface MovementHelper extends ActionCosts, Helper { return b == Blocks.ICE // ice becomes water, and water can mess up the path || b instanceof BlockSilverfish // obvious reasons // call context.get directly with x,y,z. no need to make 5 new BlockPos for no reason - || avoidAdjacentBreaking(bsi, x, y + 1, z) - || avoidAdjacentBreaking(bsi, x + 1, y, z) - || avoidAdjacentBreaking(bsi, x - 1, y, z) - || avoidAdjacentBreaking(bsi, x, y, z + 1) - || avoidAdjacentBreaking(bsi, x, y, z - 1); + || avoidAdjacentBreaking(bsi, x, y + 1, z, true) + || avoidAdjacentBreaking(bsi, x + 1, y, z, false) + || avoidAdjacentBreaking(bsi, x - 1, y, z, false) + || avoidAdjacentBreaking(bsi, x, y, z + 1, false) + || avoidAdjacentBreaking(bsi, x, y, z - 1, false); } - static boolean avoidAdjacentBreaking(BlockStateInterface bsi, int x, int y, int z) { + static boolean avoidAdjacentBreaking(BlockStateInterface bsi, int x, int y, int z, boolean directlyAbove) { // returns true if you should avoid breaking a block that's adjacent to this one (e.g. lava that will start flowing if you give it a path) // this is only called for north, south, east, west, and up. this is NOT called for down. // we assume that it's ALWAYS okay to break the block thats ABOVE liquid IBlockState state = bsi.get0(x, y, z); - return state.getBlock() instanceof BlockLiquid; + Block block = state.getBlock(); + if (!directlyAbove // it is fine to mine a block that has a falling block directly above, this (the cost of breaking the stacked fallings) is included in cost calculations + // therefore if directlyAbove is true, we will actually ignore if this is falling + && block instanceof BlockFalling // obviously, this check is only valid for falling blocks + && Baritone.settings().avoidUpdatingFallingBlocks.value // and if the setting is enabled + && BlockFalling.canFallThrough(bsi.get0(x, y - 1, z))) { // and if it would fall (i.e. it's unsupported) + return true; // dont break a block that is adjacent to unsupported gravel because it can cause really weird stuff + } + return block instanceof BlockLiquid; } static boolean canWalkThrough(IPlayerContext ctx, BetterBlockPos pos) {