mine many block types at once
This commit is contained in:
parent
5cfb270a32
commit
2452a69089
@ -29,6 +29,7 @@ import net.minecraft.util.math.BlockPos;
|
|||||||
import net.minecraft.world.chunk.EmptyChunk;
|
import net.minecraft.world.chunk.EmptyChunk;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@ -44,7 +45,7 @@ public class MineBehavior extends Behavior {
|
|||||||
private MineBehavior() {
|
private MineBehavior() {
|
||||||
}
|
}
|
||||||
|
|
||||||
String mining;
|
List<String> mining;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTick(TickEvent event) {
|
public void onTick(TickEvent event) {
|
||||||
@ -54,14 +55,17 @@ public class MineBehavior extends Behavior {
|
|||||||
if (mining == null) {
|
if (mining == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
List<BlockPos> locs = new ArrayList<>(WorldProvider.INSTANCE.getCurrentWorld().cache.getLocationsOf(mining, 1, 1));
|
List<BlockPos> locs = new ArrayList<>();
|
||||||
|
for (String m : mining) {
|
||||||
|
locs.addAll(WorldProvider.INSTANCE.getCurrentWorld().cache.getLocationsOf(m, 1, 1));
|
||||||
|
}
|
||||||
BlockPos playerFeet = playerFeet();
|
BlockPos playerFeet = playerFeet();
|
||||||
locs.sort(Comparator.comparingDouble(playerFeet::distanceSq));
|
locs.sort(Comparator.comparingDouble(playerFeet::distanceSq));
|
||||||
|
|
||||||
// remove any that are within loaded chunks that aren't actually what we want
|
// remove any that are within loaded chunks that aren't actually what we want
|
||||||
locs.removeAll(locs.stream()
|
locs.removeAll(locs.stream()
|
||||||
.filter(pos -> !(world().getChunk(pos) instanceof EmptyChunk))
|
.filter(pos -> !(world().getChunk(pos) instanceof EmptyChunk))
|
||||||
.filter(pos -> !ChunkPacker.blockToString(BlockStateInterface.get(pos).getBlock()).equalsIgnoreCase(mining))
|
.filter(pos -> !mining.contains(ChunkPacker.blockToString(BlockStateInterface.get(pos).getBlock()).toLowerCase()))
|
||||||
.collect(Collectors.toList()));
|
.collect(Collectors.toList()));
|
||||||
if (locs.size() > 30) {
|
if (locs.size() > 30) {
|
||||||
locs = locs.subList(0, 30);
|
locs = locs.subList(0, 30);
|
||||||
@ -75,8 +79,8 @@ public class MineBehavior extends Behavior {
|
|||||||
PathingBehavior.INSTANCE.path();
|
PathingBehavior.INSTANCE.path();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void mine(String mining) {
|
public void mine(String... mining) {
|
||||||
this.mining = mining;
|
this.mining = new ArrayList<>(Arrays.asList(mining));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cancel() {
|
public void cancel() {
|
||||||
|
@ -189,8 +189,8 @@ public class ExampleBaritoneControl extends Behavior {
|
|||||||
}
|
}
|
||||||
if (msg.toLowerCase().startsWith("mine")) {
|
if (msg.toLowerCase().startsWith("mine")) {
|
||||||
String blockType = msg.toLowerCase().substring(4).trim();
|
String blockType = msg.toLowerCase().substring(4).trim();
|
||||||
MineBehavior.INSTANCE.mine(blockType);
|
MineBehavior.INSTANCE.mine(blockType.split(" "));
|
||||||
displayChatMessageRaw("Started mining blocks of type " + blockType);
|
displayChatMessageRaw("Started mining blocks of type " + Arrays.toString(blockType.split(" ")));
|
||||||
event.cancel();
|
event.cancel();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user