Merge pull request #3755 from wagyourtail/allowbreakanaywaymine

allowBreakAnyway should let mining happen
This commit is contained in:
leijurv 2022-12-24 00:07:00 -08:00 committed by GitHub
commit 42dc5b14b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -103,11 +103,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
return null; return null;
} }
} }
if (!Baritone.settings().allowBreak.value) {
logDirect("Unable to mine when allowBreak is false!");
cancel();
return null;
}
updateLoucaSystem(); updateLoucaSystem();
int mineGoalUpdateInterval = Baritone.settings().mineGoalUpdateInterval.value; int mineGoalUpdateInterval = Baritone.settings().mineGoalUpdateInterval.value;
List<BlockPos> curr = new ArrayList<>(knownOreLocations); List<BlockPos> curr = new ArrayList<>(knownOreLocations);
@ -116,7 +112,10 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
Baritone.getExecutor().execute(() -> rescan(curr, context)); Baritone.getExecutor().execute(() -> rescan(curr, context));
} }
if (Baritone.settings().legitMine.value) { if (Baritone.settings().legitMine.value) {
addNearby(); if (!addNearby()) {
cancel();
return null;
}
} }
Optional<BlockPos> shaft = curr.stream() Optional<BlockPos> shaft = curr.stream()
.filter(pos -> pos.getX() == ctx.playerFeet().getX() && pos.getZ() == ctx.playerFeet().getZ()) .filter(pos -> pos.getX() == ctx.playerFeet().getX() && pos.getZ() == ctx.playerFeet().getZ())
@ -177,6 +176,11 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
} }
private PathingCommand updateGoal() { private PathingCommand updateGoal() {
BlockOptionalMetaLookup filter = filterFilter();
if (filter == null) {
return null;
}
boolean legit = Baritone.settings().legitMine.value; boolean legit = Baritone.settings().legitMine.value;
List<BlockPos> locs = knownOreLocations; List<BlockPos> locs = knownOreLocations;
if (!locs.isEmpty()) { if (!locs.isEmpty()) {
@ -221,6 +225,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
} }
private void rescan(List<BlockPos> already, CalculationContext context) { private void rescan(List<BlockPos> already, CalculationContext context) {
BlockOptionalMetaLookup filter = filterFilter();
if (filter == null) { if (filter == null) {
return; return;
} }
@ -370,11 +375,18 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
return prune(ctx, locs, filter, max, blacklist, dropped); return prune(ctx, locs, filter, max, blacklist, dropped);
} }
private void addNearby() { private boolean addNearby() {
List<BlockPos> dropped = droppedItemsScan(); List<BlockPos> dropped = droppedItemsScan();
knownOreLocations.addAll(dropped); knownOreLocations.addAll(dropped);
BlockPos playerFeet = ctx.playerFeet(); BlockPos playerFeet = ctx.playerFeet();
BlockStateInterface bsi = new BlockStateInterface(ctx); BlockStateInterface bsi = new BlockStateInterface(ctx);
BlockOptionalMetaLookup filter = filterFilter();
if (filter == null) {
return false;
}
int searchDist = 10; int searchDist = 10;
double fakedBlockReachDistance = 20; // at least 10 * sqrt(3) with some extra space to account for positioning within the block 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++) { for (int x = playerFeet.getX() - searchDist; x <= playerFeet.getX() + searchDist; x++) {
@ -392,6 +404,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
} }
} }
knownOreLocations = prune(new CalculationContext(baritone), knownOreLocations, filter, ORE_LOCATIONS_COUNT, blacklist, dropped); knownOreLocations = prune(new CalculationContext(baritone), knownOreLocations, filter, ORE_LOCATIONS_COUNT, blacklist, dropped);
return true;
} }
private static List<BlockPos> prune(CalculationContext ctx, List<BlockPos> locs2, BlockOptionalMetaLookup filter, int max, List<BlockPos> blacklist, List<BlockPos> dropped) { private static List<BlockPos> prune(CalculationContext ctx, List<BlockPos> locs2, BlockOptionalMetaLookup filter, int max, List<BlockPos> blacklist, List<BlockPos> dropped) {
@ -467,10 +480,8 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
@Override @Override
public void mine(int quantity, BlockOptionalMetaLookup filter) { public void mine(int quantity, BlockOptionalMetaLookup filter) {
this.filter = filter; this.filter = filter;
if (filter != null && !Baritone.settings().allowBreak.value) { if (this.filterFilter() == null) {
logDirect("Unable to mine when allowBreak is false!"); this.filter = null;
this.mine(quantity, (BlockOptionalMetaLookup) null);
return;
} }
this.desiredQuantity = quantity; this.desiredQuantity = quantity;
this.knownOreLocations = new ArrayList<>(); this.knownOreLocations = new ArrayList<>();
@ -482,4 +493,22 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
rescan(new ArrayList<>(), new CalculationContext(baritone)); 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;
}
} }