From e09127eadf3efe6aee9afd56183c902181737c57 Mon Sep 17 00:00:00 2001 From: Wagyourtail Date: Sat, 10 Dec 2022 16:35:51 -0700 Subject: [PATCH 1/3] allowBreakAnyway should let mining happen --- .../java/baritone/process/MineProcess.java | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/main/java/baritone/process/MineProcess.java b/src/main/java/baritone/process/MineProcess.java index 1ec47cd9..08a6791b 100644 --- a/src/main/java/baritone/process/MineProcess.java +++ b/src/main/java/baritone/process/MineProcess.java @@ -102,10 +102,17 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro return null; } } + if (!Baritone.settings().allowBreak.value) { - logDirect("Unable to mine when allowBreak is false!"); - cancel(); - return null; + this.filter = new BlockOptionalMetaLookup(filter.blocks() + .stream() + .filter(e -> Baritone.settings().allowBreakAnyway.value.contains(e.getBlock())) + .toArray(BlockOptionalMeta[]::new)); + if (this.filter.blocks().isEmpty()) { + logDirect("Unable to mine when allowBreak is false!"); + cancel(); + return null; + } } updateLoucaSystem(); int mineGoalUpdateInterval = Baritone.settings().mineGoalUpdateInterval.value; @@ -467,9 +474,15 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro public void mine(int quantity, BlockOptionalMetaLookup filter) { this.filter = filter; if (filter != null && !Baritone.settings().allowBreak.value) { - logDirect("Unable to mine when allowBreak is false!"); - this.mine(quantity, (BlockOptionalMetaLookup) null); - return; + this.filter = new BlockOptionalMetaLookup(filter.blocks() + .stream() + .filter(e -> Baritone.settings().allowBreakAnyway.value.contains(e.getBlock())) + .toArray(BlockOptionalMeta[]::new)); + if (this.filter.blocks().isEmpty()) { + logDirect("Unable to mine when allowBreak is false!"); + this.mine(quantity, (BlockOptionalMetaLookup) null); + return; + } } this.desiredQuantity = quantity; this.knownOreLocations = new ArrayList<>(); From 85087ce04a9130a92059732ca7046be3d39c9f29 Mon Sep 17 00:00:00 2001 From: Wagyourtail Date: Sat, 10 Dec 2022 19:25:57 -0700 Subject: [PATCH 2/3] smarter filter filtering --- .../java/baritone/process/MineProcess.java | 59 +++++++++++-------- 1 file changed, 36 insertions(+), 23 deletions(-) diff --git a/src/main/java/baritone/process/MineProcess.java b/src/main/java/baritone/process/MineProcess.java index 08a6791b..7666ec7c 100644 --- a/src/main/java/baritone/process/MineProcess.java +++ b/src/main/java/baritone/process/MineProcess.java @@ -103,17 +103,6 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro } } - if (!Baritone.settings().allowBreak.value) { - this.filter = new BlockOptionalMetaLookup(filter.blocks() - .stream() - .filter(e -> Baritone.settings().allowBreakAnyway.value.contains(e.getBlock())) - .toArray(BlockOptionalMeta[]::new)); - if (this.filter.blocks().isEmpty()) { - logDirect("Unable to mine when allowBreak is false!"); - cancel(); - return null; - } - } updateLoucaSystem(); int mineGoalUpdateInterval = Baritone.settings().mineGoalUpdateInterval.value; List curr = new ArrayList<>(knownOreLocations); @@ -122,7 +111,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro Baritone.getExecutor().execute(() -> rescan(curr, context)); } if (Baritone.settings().legitMine.value) { - addNearby(); + if (!addNearby()) return null; } Optional shaft = curr.stream() .filter(pos -> pos.getX() == ctx.playerFeet().getX() && pos.getZ() == ctx.playerFeet().getZ()) @@ -183,6 +172,11 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro } private PathingCommand updateGoal() { + BlockOptionalMetaLookup filter = filterFilter(); + if (filter == null) { + return null; + } + boolean legit = Baritone.settings().legitMine.value; List locs = knownOreLocations; if (!locs.isEmpty()) { @@ -227,6 +221,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro } private void rescan(List already, CalculationContext context) { + BlockOptionalMetaLookup filter = filterFilter(); if (filter == null) { return; } @@ -376,11 +371,18 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro return prune(ctx, locs, filter, max, blacklist, dropped); } - private void addNearby() { + private boolean addNearby() { List dropped = droppedItemsScan(); knownOreLocations.addAll(dropped); BlockPos playerFeet = ctx.playerFeet(); BlockStateInterface bsi = new BlockStateInterface(ctx); + + + BlockOptionalMetaLookup filter = filterFilter(); + if (filter == null) { + return false; + } + int searchDist = 10; double fakedBlockReachDistance = 20; // at least 10 * sqrt(3) with some extra space to account for positioning within the block for (int x = playerFeet.getX() - searchDist; x <= playerFeet.getX() + searchDist; x++) { @@ -398,6 +400,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro } } knownOreLocations = prune(new CalculationContext(baritone), knownOreLocations, filter, ORE_LOCATIONS_COUNT, blacklist, dropped); + return true; } private static List prune(CalculationContext ctx, List locs2, BlockOptionalMetaLookup filter, int max, List blacklist, List dropped) { @@ -473,16 +476,8 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro @Override public void mine(int quantity, BlockOptionalMetaLookup filter) { this.filter = filter; - if (filter != null && !Baritone.settings().allowBreak.value) { - this.filter = new BlockOptionalMetaLookup(filter.blocks() - .stream() - .filter(e -> Baritone.settings().allowBreakAnyway.value.contains(e.getBlock())) - .toArray(BlockOptionalMeta[]::new)); - if (this.filter.blocks().isEmpty()) { - logDirect("Unable to mine when allowBreak is false!"); - this.mine(quantity, (BlockOptionalMetaLookup) null); - return; - } + if (this.filterFilter() == null) { + this.filter = null; } this.desiredQuantity = quantity; this.knownOreLocations = new ArrayList<>(); @@ -494,4 +489,22 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro rescan(new ArrayList<>(), new CalculationContext(baritone)); } } + + private BlockOptionalMetaLookup filterFilter() { + if (this.filter == null) { + return null; + } + if (!Baritone.settings().allowBreak.value) { + BlockOptionalMetaLookup f = new BlockOptionalMetaLookup(this.filter.blocks() + .stream() + .filter(e -> Baritone.settings().allowBreakAnyway.value.contains(e.getBlock())) + .toArray(BlockOptionalMeta[]::new)); + if (f.blocks().isEmpty()) { + logDirect("Unable to mine when allowBreak is false and target block is not in allowBreakAnyway!"); + return null; + } + return f; + } + return filter; + } } From ea1914a24816ae57daa925132cafce4f7007edc8 Mon Sep 17 00:00:00 2001 From: Wagyourtail Date: Sat, 10 Dec 2022 20:12:51 -0700 Subject: [PATCH 3/3] missed a spot --- src/main/java/baritone/process/MineProcess.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/baritone/process/MineProcess.java b/src/main/java/baritone/process/MineProcess.java index 7666ec7c..395e99d9 100644 --- a/src/main/java/baritone/process/MineProcess.java +++ b/src/main/java/baritone/process/MineProcess.java @@ -111,7 +111,10 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro Baritone.getExecutor().execute(() -> rescan(curr, context)); } if (Baritone.settings().legitMine.value) { - if (!addNearby()) return null; + if (!addNearby()) { + cancel(); + return null; + } } Optional shaft = curr.stream() .filter(pos -> pos.getX() == ctx.playerFeet().getX() && pos.getZ() == ctx.playerFeet().getZ())