preliminary refactoring
This commit is contained in:
parent
7617081637
commit
a0b1cb2993
@ -50,8 +50,8 @@ public final class MineBehavior extends Behavior implements IMineBehavior, Helpe
|
|||||||
public static final MineBehavior INSTANCE = new MineBehavior();
|
public static final MineBehavior INSTANCE = new MineBehavior();
|
||||||
|
|
||||||
private List<Block> mining;
|
private List<Block> mining;
|
||||||
private List<BlockPos> locationsCache;
|
private List<BlockPos> knownOreLocations;
|
||||||
private int quantity;
|
private int desiredQuantity;
|
||||||
|
|
||||||
private MineBehavior() {}
|
private MineBehavior() {}
|
||||||
|
|
||||||
@ -64,11 +64,11 @@ public final class MineBehavior extends Behavior implements IMineBehavior, Helpe
|
|||||||
if (mining == null) {
|
if (mining == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (quantity > 0) {
|
if (desiredQuantity > 0) {
|
||||||
Item item = mining.get(0).getItemDropped(mining.get(0).getDefaultState(), new Random(), 0);
|
Item item = mining.get(0).getItemDropped(mining.get(0).getDefaultState(), new Random(), 0);
|
||||||
int curr = player().inventory.mainInventory.stream().filter(stack -> item.equals(stack.getItem())).mapToInt(ItemStack::getCount).sum();
|
int curr = player().inventory.mainInventory.stream().filter(stack -> item.equals(stack.getItem())).mapToInt(ItemStack::getCount).sum();
|
||||||
System.out.println("Currently have " + curr + " " + item);
|
System.out.println("Currently have " + curr + " " + item);
|
||||||
if (curr >= quantity) {
|
if (curr >= desiredQuantity) {
|
||||||
logDirect("Have " + curr + " " + item.getItemStackDisplayName(new ItemStack(item, 1)));
|
logDirect("Have " + curr + " " + item.getItemStackDisplayName(new ItemStack(item, 1)));
|
||||||
cancel();
|
cancel();
|
||||||
return;
|
return;
|
||||||
@ -88,12 +88,12 @@ public final class MineBehavior extends Behavior implements IMineBehavior, Helpe
|
|||||||
if (mining == null) {
|
if (mining == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
List<BlockPos> locs = locationsCache;
|
List<BlockPos> locs = knownOreLocations;
|
||||||
if (!locs.isEmpty()) {
|
if (!locs.isEmpty()) {
|
||||||
locs = prune(new ArrayList<>(locs), mining, 64);
|
locs = prune(new ArrayList<>(locs), mining, 64);
|
||||||
PathingBehavior.INSTANCE.setGoal(coalesce(locs));
|
PathingBehavior.INSTANCE.setGoal(coalesce(locs));
|
||||||
PathingBehavior.INSTANCE.path();
|
PathingBehavior.INSTANCE.path();
|
||||||
locationsCache = locs;
|
knownOreLocations = locs;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,16 +101,16 @@ public final class MineBehavior extends Behavior implements IMineBehavior, Helpe
|
|||||||
if (mining == null) {
|
if (mining == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
List<BlockPos> locs = scanFor(mining, 64);
|
List<BlockPos> locs = xrayFor(mining, 64);
|
||||||
if (locs.isEmpty()) {
|
if (locs.isEmpty()) {
|
||||||
logDebug("No locations for " + mining + " known, cancelling");
|
logDebug("No locations for " + mining + " known, cancelling");
|
||||||
mine(0, (String[]) null);
|
mine(0, (String[]) null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
locationsCache = locs;
|
knownOreLocations = locs;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Goal coalesce(BlockPos loc, List<BlockPos> locs) {
|
private static Goal coalesce(BlockPos loc, List<BlockPos> locs) {
|
||||||
if (!Baritone.settings().forceInternalMining.get()) {
|
if (!Baritone.settings().forceInternalMining.get()) {
|
||||||
return new GoalTwoBlocks(loc);
|
return new GoalTwoBlocks(loc);
|
||||||
}
|
}
|
||||||
@ -136,7 +136,7 @@ public final class MineBehavior extends Behavior implements IMineBehavior, Helpe
|
|||||||
return new GoalComposite(locs.stream().map(loc -> coalesce(loc, locs)).toArray(Goal[]::new));
|
return new GoalComposite(locs.stream().map(loc -> coalesce(loc, locs)).toArray(Goal[]::new));
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<BlockPos> scanFor(List<Block> mining, int max) {
|
public List<BlockPos> xrayFor(List<Block> mining, int max) {
|
||||||
List<BlockPos> locs = new ArrayList<>();
|
List<BlockPos> locs = new ArrayList<>();
|
||||||
List<Block> uninteresting = new ArrayList<>();
|
List<Block> uninteresting = new ArrayList<>();
|
||||||
//long b = System.currentTimeMillis();
|
//long b = System.currentTimeMillis();
|
||||||
@ -177,8 +177,8 @@ public final class MineBehavior extends Behavior implements IMineBehavior, Helpe
|
|||||||
@Override
|
@Override
|
||||||
public void mine(int quantity, String... blocks) {
|
public void mine(int quantity, String... blocks) {
|
||||||
this.mining = blocks == null || blocks.length == 0 ? null : Arrays.stream(blocks).map(ChunkPacker::stringToBlock).collect(Collectors.toList());
|
this.mining = blocks == null || blocks.length == 0 ? null : Arrays.stream(blocks).map(ChunkPacker::stringToBlock).collect(Collectors.toList());
|
||||||
this.quantity = quantity;
|
this.desiredQuantity = quantity;
|
||||||
this.locationsCache = new ArrayList<>();
|
this.knownOreLocations = new ArrayList<>();
|
||||||
rescan();
|
rescan();
|
||||||
updateGoal();
|
updateGoal();
|
||||||
}
|
}
|
||||||
@ -186,8 +186,8 @@ public final class MineBehavior extends Behavior implements IMineBehavior, Helpe
|
|||||||
@Override
|
@Override
|
||||||
public void mine(int quantity, Block... blocks) {
|
public void mine(int quantity, Block... blocks) {
|
||||||
this.mining = blocks == null || blocks.length == 0 ? null : Arrays.asList(blocks);
|
this.mining = blocks == null || blocks.length == 0 ? null : Arrays.asList(blocks);
|
||||||
this.quantity = quantity;
|
this.desiredQuantity = quantity;
|
||||||
this.locationsCache = new ArrayList<>();
|
this.knownOreLocations = new ArrayList<>();
|
||||||
rescan();
|
rescan();
|
||||||
updateGoal();
|
updateGoal();
|
||||||
}
|
}
|
||||||
|
@ -382,7 +382,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
List<BlockPos> locs = MineBehavior.INSTANCE.scanFor(Collections.singletonList(block), 64);
|
List<BlockPos> locs = MineBehavior.INSTANCE.xrayFor(Collections.singletonList(block), 64);
|
||||||
if (locs.isEmpty()) {
|
if (locs.isEmpty()) {
|
||||||
logDirect("No locations for " + mining + " known, cancelling");
|
logDirect("No locations for " + mining + " known, cancelling");
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
Reference in New Issue
Block a user