dont mine blocks that update falling blocks, fixes #395

This commit is contained in:
Leijurv 2019-05-01 11:16:24 -07:00
parent 58ebd5f9a6
commit 54da0d24a3
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
2 changed files with 23 additions and 8 deletions

View File

@ -160,7 +160,7 @@ public final class Settings {
/** /**
* Blocks that Baritone is not allowed to break * Blocks that Baritone is not allowed to break
*/ */
public final Setting<List<Block>> blocksToAvoidBreaking = new Setting<>(new ArrayList<>(Arrays.asList( public final Setting<List<Block>> blocksToAvoidBreaking = new Setting<>(new ArrayList<>(Arrays.asList( // TODO can this be a HashSet or ImmutableSet?
Blocks.CRAFTING_TABLE, Blocks.CRAFTING_TABLE,
Blocks.FURNACE, Blocks.FURNACE,
Blocks.LIT_FURNACE, Blocks.LIT_FURNACE,
@ -168,6 +168,13 @@ public final class Settings {
Blocks.TRAPPED_CHEST Blocks.TRAPPED_CHEST
))); )));
/**
* If this setting is true, Baritone will never break a block that is adjacent to an unsupported falling block.
* <p>
* I.E. it will never trigger cascading sand / gravel falls
*/
public final Setting<Boolean> avoidUpdatingFallingBlocks = new Setting<>(true);
/** /**
* Enables some more advanced vine features. They're honestly just gimmicks and won't ever be needed in real * 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. * pathing scenarios. And they can cause Baritone to get trapped indefinitely in a strange scenario.

View File

@ -51,19 +51,27 @@ public interface MovementHelper extends ActionCosts, Helper {
return b == Blocks.ICE // ice becomes water, and water can mess up the path return b == Blocks.ICE // ice becomes water, and water can mess up the path
|| b instanceof BlockSilverfish // obvious reasons || b instanceof BlockSilverfish // obvious reasons
// call context.get directly with x,y,z. no need to make 5 new BlockPos for no reason // 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, y + 1, z, true)
|| avoidAdjacentBreaking(bsi, x + 1, y, z) || avoidAdjacentBreaking(bsi, x + 1, y, z, false)
|| avoidAdjacentBreaking(bsi, x - 1, y, z) || avoidAdjacentBreaking(bsi, x - 1, y, z, false)
|| avoidAdjacentBreaking(bsi, x, y, z + 1) || avoidAdjacentBreaking(bsi, x, y, z + 1, false)
|| avoidAdjacentBreaking(bsi, x, y, z - 1); || 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) // 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. // 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 // we assume that it's ALWAYS okay to break the block thats ABOVE liquid
IBlockState state = bsi.get0(x, y, z); 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) { static boolean canWalkThrough(IPlayerContext ctx, BetterBlockPos pos) {