scan for uninteresting blocks in loaded chunks, fixes #99
This commit is contained in:
@@ -38,10 +38,8 @@ import baritone.utils.pathing.BetterBlockPos;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.chunk.EmptyChunk;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ExampleBaritoneControl extends Behavior {
|
||||
public static ExampleBaritoneControl INSTANCE = new ExampleBaritoneControl();
|
||||
@@ -188,9 +186,16 @@ public class ExampleBaritoneControl extends Behavior {
|
||||
return;
|
||||
}
|
||||
if (msg.toLowerCase().startsWith("mine")) {
|
||||
String blockType = msg.toLowerCase().substring(4).trim();
|
||||
MineBehavior.INSTANCE.mine(blockType.split(" "));
|
||||
displayChatMessageRaw("Started mining blocks of type " + Arrays.toString(blockType.split(" ")));
|
||||
String[] blockTypes = msg.toLowerCase().substring(4).trim().split(" ");
|
||||
for (String s : blockTypes) {
|
||||
if (ChunkPacker.stringToBlock(s) == null) {
|
||||
displayChatMessageRaw(s + " isn't a valid block name");
|
||||
event.cancel();
|
||||
return;
|
||||
}
|
||||
}
|
||||
MineBehavior.INSTANCE.mine(blockTypes);
|
||||
displayChatMessageRaw("Started mining blocks of type " + Arrays.toString(blockTypes));
|
||||
event.cancel();
|
||||
return;
|
||||
}
|
||||
@@ -235,21 +240,14 @@ public class ExampleBaritoneControl extends Behavior {
|
||||
String mining = waypointType;
|
||||
//displayChatMessageRaw("Not a valid tag. Tags are: " + Arrays.asList(Waypoint.Tag.values()).toString().toLowerCase());
|
||||
event.cancel();
|
||||
List<BlockPos> locs = new ArrayList<>(WorldProvider.INSTANCE.getCurrentWorld().cache.getLocationsOf(mining, 1, 1));
|
||||
if (locs.isEmpty()) {
|
||||
if (ChunkPacker.stringToBlock(mining) == null) {
|
||||
displayChatMessageRaw("No locations for " + mining + " known, cancelling");
|
||||
return;
|
||||
}
|
||||
BlockPos playerFeet = playerFeet();
|
||||
locs.sort(Comparator.comparingDouble(playerFeet::distanceSq));
|
||||
|
||||
// remove any that are within loaded chunks that aren't actually what we want
|
||||
locs.removeAll(locs.stream()
|
||||
.filter(pos -> !(world().getChunk(pos) instanceof EmptyChunk))
|
||||
.filter(pos -> !ChunkPacker.blockToString(BlockStateInterface.get(pos).getBlock()).equalsIgnoreCase(mining))
|
||||
.collect(Collectors.toList()));
|
||||
if (locs.size() > 30) {
|
||||
locs = locs.subList(0, 30);
|
||||
List<BlockPos> locs = MineBehavior.scanFor(Arrays.asList(mining), 64);
|
||||
if (locs.isEmpty()) {
|
||||
displayChatMessageRaw("No locations for " + mining + " known, cancelling");
|
||||
return;
|
||||
}
|
||||
PathingBehavior.INSTANCE.setGoal(new GoalComposite(locs.stream().map(GoalGetToBlock::new).toArray(Goal[]::new)));
|
||||
PathingBehavior.INSTANCE.path();
|
||||
|
||||
Reference in New Issue
Block a user