[+] Read seed server cache when scanning

This commit is contained in:
Hykilpikonna
2020-02-19 21:09:47 -05:00
parent 24a3034514
commit b38d2c9680
+46 -32
View File
@@ -36,11 +36,13 @@ import net.minecraft.entity.Entity;
import net.minecraft.entity.item.ItemEntity; import net.minecraft.entity.item.ItemEntity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import org.hydev.hyritone.Hyritone;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
import static baritone.Baritone.settings;
import static baritone.api.pathing.movement.ActionCosts.COST_INF; import static baritone.api.pathing.movement.ActionCosts.COST_INF;
import static java.util.stream.Collectors.toList;
/** /**
* Mine blocks of a certain type * Mine blocks of a certain type
@@ -83,7 +85,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
} }
} }
if (calcFailed) { if (calcFailed) {
if (!knownOreLocations.isEmpty() && Baritone.settings().blacklistClosestOnFailure.value) { if (!knownOreLocations.isEmpty() && settings().blacklistClosestOnFailure.value) {
logDirect("Unable to find any path to " + filter + ", blacklisting presumably unreachable closest instance..."); logDirect("Unable to find any path to " + filter + ", blacklisting presumably unreachable closest instance...");
knownOreLocations.stream().min(Comparator.comparingDouble(ctx.playerFeet()::distanceSq)).ifPresent(blacklist::add); knownOreLocations.stream().min(Comparator.comparingDouble(ctx.playerFeet()::distanceSq)).ifPresent(blacklist::add);
knownOreLocations.removeIf(blacklist::contains); knownOreLocations.removeIf(blacklist::contains);
@@ -93,19 +95,19 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
return null; return null;
} }
} }
if (!Baritone.settings().allowBreak.value) { if (!settings().allowBreak.value) {
logDirect("Unable to mine when allowBreak is false!"); logDirect("Unable to mine when allowBreak is false!");
cancel(); cancel();
return null; return null;
} }
updateLoucaSystem(); updateLoucaSystem();
int mineGoalUpdateInterval = Baritone.settings().mineGoalUpdateInterval.value; int mineGoalUpdateInterval = settings().mineGoalUpdateInterval.value;
List<BlockPos> curr = new ArrayList<>(knownOreLocations); List<BlockPos> curr = new ArrayList<>(knownOreLocations);
if (mineGoalUpdateInterval != 0 && tickCount++ % mineGoalUpdateInterval == 0) { // big brain if (mineGoalUpdateInterval != 0 && tickCount++ % mineGoalUpdateInterval == 0) { // big brain
CalculationContext context = new CalculationContext(baritone, true); CalculationContext context = new CalculationContext(baritone, true);
Baritone.getExecutor().execute(() -> rescan(curr, context)); Baritone.getExecutor().execute(() -> rescan(curr, context));
} }
if (Baritone.settings().legitMine.value) { if (settings().legitMine.value) {
addNearby(); addNearby();
} }
Optional<BlockPos> shaft = curr.stream() Optional<BlockPos> shaft = curr.stream()
@@ -144,7 +146,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
Map<BlockPos, Long> copy = new HashMap<>(anticipatedDrops); Map<BlockPos, Long> copy = new HashMap<>(anticipatedDrops);
ctx.getSelectedBlock().ifPresent(pos -> { ctx.getSelectedBlock().ifPresent(pos -> {
if (knownOreLocations.contains(pos)) { if (knownOreLocations.contains(pos)) {
copy.put(pos, System.currentTimeMillis() + Baritone.settings().mineDropLoiterDurationMSThanksLouca.value); copy.put(pos, System.currentTimeMillis() + settings().mineDropLoiterDurationMSThanksLouca.value);
} }
}); });
// elaborate dance to avoid concurrentmodificationexcepption since rescan thread reads this // elaborate dance to avoid concurrentmodificationexcepption since rescan thread reads this
@@ -168,7 +170,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
} }
private PathingCommand updateGoal() { private PathingCommand updateGoal() {
boolean legit = Baritone.settings().legitMine.value; boolean legit = settings().legitMine.value;
List<BlockPos> locs = knownOreLocations; List<BlockPos> locs = knownOreLocations;
if (!locs.isEmpty()) { if (!locs.isEmpty()) {
CalculationContext context = new CalculationContext(baritone); CalculationContext context = new CalculationContext(baritone);
@@ -183,7 +185,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
return null; return null;
} }
// only in non-Xray mode (aka legit mode) do we do this // only in non-Xray mode (aka legit mode) do we do this
int y = Baritone.settings().legitMineYLevel.value; int y = settings().legitMineYLevel.value;
if (branchPoint == null) { if (branchPoint == null) {
/*if (!baritone.getPathingBehavior().isPathing() && playerFeet().y == y) { /*if (!baritone.getPathingBehavior().isPathing() && playerFeet().y == y) {
// cool, path is over and we are at desired y // cool, path is over and we are at desired y
@@ -211,7 +213,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
if (filter == null) { if (filter == null) {
return; return;
} }
if (Baritone.settings().legitMine.value) { if (settings().legitMine.value) {
return; return;
} }
List<BlockPos> dropped = droppedItemsScan(); List<BlockPos> dropped = droppedItemsScan();
@@ -231,7 +233,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
return true; return true;
} }
BlockState state = context.bsi.get0(pos); BlockState state = context.bsi.get0(pos);
if (Baritone.settings().internalMiningAirException.value && state.getBlock() instanceof AirBlock) { if (settings().internalMiningAirException.value && state.getBlock() instanceof AirBlock) {
return true; return true;
} }
return filter.has(state) && plausibleToBreak(context, pos); return filter.has(state) && plausibleToBreak(context, pos);
@@ -239,7 +241,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
private Goal coalesce(BlockPos loc, List<BlockPos> locs, CalculationContext context) { private Goal coalesce(BlockPos loc, List<BlockPos> locs, CalculationContext context) {
boolean assumeVerticalShaftMine = !(baritone.bsi.get0(loc.up()).getBlock() instanceof FallingBlock); boolean assumeVerticalShaftMine = !(baritone.bsi.get0(loc.up()).getBlock() instanceof FallingBlock);
if (!Baritone.settings().forceInternalMining.value) { if (!settings().forceInternalMining.value) {
if (assumeVerticalShaftMine) { if (assumeVerticalShaftMine) {
// we can get directly below the block // we can get directly below the block
return new GoalThreeBlocks(loc); return new GoalThreeBlocks(loc);
@@ -300,7 +302,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
} }
public List<BlockPos> droppedItemsScan() { public List<BlockPos> droppedItemsScan() {
if (!Baritone.settings().mineScanDroppedItems.value) { if (!settings().mineScanDroppedItems.value) {
return Collections.emptyList(); return Collections.emptyList();
} }
List<BlockPos> ret = new ArrayList<>(); List<BlockPos> ret = new ArrayList<>();
@@ -319,39 +321,51 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
public static List<BlockPos> searchWorld(CalculationContext ctx, BlockOptionalMetaLookup filter, int max, List<BlockPos> alreadyKnown, List<BlockPos> blacklist, List<BlockPos> dropped) { public static List<BlockPos> searchWorld(CalculationContext ctx, BlockOptionalMetaLookup filter, int max, List<BlockPos> alreadyKnown, List<BlockPos> blacklist, List<BlockPos> dropped) {
List<BlockPos> locs = new ArrayList<>(); List<BlockPos> locs = new ArrayList<>();
List<Block> untracked = new ArrayList<>(); List<Block> untracked = new ArrayList<>();
for (BlockOptionalMeta bom : filter.blocks()) {
Block block = bom.getBlock();
if (CachedChunk.BLOCKS_TO_KEEP_TRACK_OF.contains(block)) {
BetterBlockPos pf = ctx.baritone.getPlayerContext().playerFeet();
// maxRegionDistanceSq 2 means adjacent directly or adjacent diagonally; nothing further than that // Check mine with seed
locs.addAll(ctx.worldData.getCachedWorld().getLocationsOf( if (!settings().mineWithSeed.value)
{
// Search the actual world
for (BlockOptionalMeta bom : filter.blocks()) {
Block block = bom.getBlock();
if (CachedChunk.BLOCKS_TO_KEEP_TRACK_OF.contains(block)) {
BetterBlockPos pf = ctx.baritone.getPlayerContext().playerFeet();
// maxRegionDistanceSq 2 means adjacent directly or adjacent diagonally; nothing further than that
locs.addAll(ctx.worldData.getCachedWorld().getLocationsOf(
BlockUtils.blockToString(block), BlockUtils.blockToString(block),
Baritone.settings().maxCachedWorldScanCount.value, settings().maxCachedWorldScanCount.value,
pf.x, pf.x,
pf.z, pf.z,
2 2
)); ));
} else { } else {
untracked.add(block); untracked.add(block);
}
} }
}
locs = prune(ctx, locs, filter, max, blacklist, dropped); locs = prune(ctx, locs, filter, max, blacklist, dropped);
if (!untracked.isEmpty() || (Baritone.settings().extendCacheOnThreshold.value && locs.size() < max)) { if (!untracked.isEmpty() || (settings().extendCacheOnThreshold.value && locs.size() < max)) {
locs.addAll(WorldScanner.INSTANCE.scanChunkRadius( locs.addAll(WorldScanner.INSTANCE.scanChunkRadius(
ctx.getBaritone().getPlayerContext(), ctx.getBaritone().getPlayerContext(),
filter, filter,
max, max,
10, 10,
32 32
)); // maxSearchRadius is NOT sq )); // maxSearchRadius is NOT sq
}
locs.addAll(alreadyKnown);
locs = prune(ctx, locs, filter, max, blacklist, dropped);
}
else
{
// Add seed ores
locs.addAll(Hyritone.seedServerCache.cacheBlocks);
} }
locs.addAll(alreadyKnown); return locs;
return prune(ctx, locs, filter, max, blacklist, dropped);
} }
private void addNearby() { private void addNearby() {
@@ -368,7 +382,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
// is an x-ray and it'll get caught // is an x-ray and it'll get caught
if (filter.has(bsi.get0(x, y, z))) { if (filter.has(bsi.get0(x, y, z))) {
BlockPos pos = new BlockPos(x, y, z); BlockPos pos = new BlockPos(x, y, z);
if ((Baritone.settings().legitMineIncludeDiagonals.value && knownOreLocations.stream().anyMatch(ore -> ore.distanceSq(pos) <= 2 /* sq means this is pytha dist <= sqrt(2) */)) || RotationUtils.reachable(ctx.player(), pos, fakedBlockReachDistance).isPresent()) { if ((settings().legitMineIncludeDiagonals.value && knownOreLocations.stream().anyMatch(ore -> ore.distanceSq(pos) <= 2 /* sq means this is pytha dist <= sqrt(2) */)) || RotationUtils.reachable(ctx.player(), pos, fakedBlockReachDistance).isPresent()) {
knownOreLocations.add(pos); knownOreLocations.add(pos);
} }
} }
@@ -400,7 +414,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
.filter(pos -> !blacklist.contains(pos)) .filter(pos -> !blacklist.contains(pos))
.sorted(Comparator.comparingDouble(new BlockPos(ctx.getBaritone().getPlayerContext().player())::distanceSq)) .sorted(Comparator.comparingDouble(new BlockPos(ctx.getBaritone().getPlayerContext().player())::distanceSq))
.collect(Collectors.toList()); .collect(toList());
if (locs.size() > max) { if (locs.size() > max) {
return locs.subList(0, max); return locs.subList(0, max);