Replace String lists containing block names with actual block lists
It just makes sense like wtf
This commit is contained in:
parent
a7504caa67
commit
2fd888b9ee
@ -29,6 +29,7 @@ import net.minecraft.util.math.BlockPos;
|
|||||||
* @author leijurv
|
* @author leijurv
|
||||||
*/
|
*/
|
||||||
public class FollowBehavior extends Behavior {
|
public class FollowBehavior extends Behavior {
|
||||||
|
|
||||||
public static final FollowBehavior INSTANCE = new FollowBehavior();
|
public static final FollowBehavior INSTANCE = new FollowBehavior();
|
||||||
|
|
||||||
private FollowBehavior() {
|
private FollowBehavior() {
|
||||||
@ -49,8 +50,12 @@ public class FollowBehavior extends Behavior {
|
|||||||
PathingBehavior.INSTANCE.path();
|
PathingBehavior.INSTANCE.path();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void follow(Entity follow) {
|
public void follow(Entity entity) {
|
||||||
this.following = follow;
|
this.following = entity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Entity following() {
|
||||||
|
return this.following;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cancel() {
|
public void cancel() {
|
||||||
|
@ -27,6 +27,7 @@ import baritone.pathing.goals.Goal;
|
|||||||
import baritone.pathing.goals.GoalComposite;
|
import baritone.pathing.goals.GoalComposite;
|
||||||
import baritone.pathing.goals.GoalTwoBlocks;
|
import baritone.pathing.goals.GoalTwoBlocks;
|
||||||
import baritone.utils.BlockStateInterface;
|
import baritone.utils.BlockStateInterface;
|
||||||
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.chunk.EmptyChunk;
|
import net.minecraft.world.chunk.EmptyChunk;
|
||||||
|
|
||||||
@ -47,14 +48,14 @@ public class MineBehavior extends Behavior {
|
|||||||
private MineBehavior() {
|
private MineBehavior() {
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> mining;
|
private List<Block> mining;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPathEvent(PathEvent event) {
|
public void onPathEvent(PathEvent event) {
|
||||||
updateGoal();
|
updateGoal();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateGoal() {
|
private void updateGoal() {
|
||||||
if (mining == null) {
|
if (mining == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -68,13 +69,13 @@ public class MineBehavior extends Behavior {
|
|||||||
PathingBehavior.INSTANCE.path();
|
PathingBehavior.INSTANCE.path();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<BlockPos> scanFor(List<String> mining, int max) {
|
public static List<BlockPos> scanFor(List<Block> mining, int max) {
|
||||||
List<BlockPos> locs = new ArrayList<>();
|
List<BlockPos> locs = new ArrayList<>();
|
||||||
List<String> uninteresting = new ArrayList<>();
|
List<Block> uninteresting = new ArrayList<>();
|
||||||
//long b = System.currentTimeMillis();
|
//long b = System.currentTimeMillis();
|
||||||
for (String m : mining) {
|
for (Block m : mining) {
|
||||||
if (CachedChunk.BLOCKS_TO_KEEP_TRACK_OF.contains(ChunkPacker.stringToBlock(m))) {
|
if (CachedChunk.BLOCKS_TO_KEEP_TRACK_OF.contains(m)) {
|
||||||
locs.addAll(WorldProvider.INSTANCE.getCurrentWorld().cache.getLocationsOf(m, 1, 1));
|
locs.addAll(WorldProvider.INSTANCE.getCurrentWorld().cache.getLocationsOf(ChunkPacker.blockToString(m), 1, 1));
|
||||||
} else {
|
} else {
|
||||||
uninteresting.add(m);
|
uninteresting.add(m);
|
||||||
}
|
}
|
||||||
@ -91,7 +92,7 @@ public class MineBehavior extends Behavior {
|
|||||||
// 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 -> !(MineBehavior.INSTANCE.world().getChunk(pos) instanceof EmptyChunk))
|
.filter(pos -> !(MineBehavior.INSTANCE.world().getChunk(pos) instanceof EmptyChunk))
|
||||||
.filter(pos -> !mining.contains(ChunkPacker.blockToString(BlockStateInterface.get(pos).getBlock()).toLowerCase()))
|
.filter(pos -> !mining.contains(BlockStateInterface.get(pos).getBlock()))
|
||||||
.collect(Collectors.toList()));
|
.collect(Collectors.toList()));
|
||||||
if (locs.size() > max) {
|
if (locs.size() > max) {
|
||||||
locs = locs.subList(0, max);
|
locs = locs.subList(0, max);
|
||||||
@ -99,13 +100,18 @@ public class MineBehavior extends Behavior {
|
|||||||
return locs;
|
return locs;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void mine(String... mining) {
|
public void mine(String... blocks) {
|
||||||
this.mining = mining == null || mining.length == 0 ? null : new ArrayList<>(Arrays.asList(mining));
|
this.mining = blocks == null || blocks.length == 0 ? null : Arrays.stream(blocks).map(ChunkPacker::stringToBlock).collect(Collectors.toList());
|
||||||
|
updateGoal();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void mine(Block... blocks) {
|
||||||
|
this.mining = blocks == null || blocks.length == 0 ? null : Arrays.asList(blocks);
|
||||||
updateGoal();
|
updateGoal();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cancel() {
|
public void cancel() {
|
||||||
PathingBehavior.INSTANCE.cancel();
|
PathingBehavior.INSTANCE.cancel();
|
||||||
mine();
|
mine((String[]) null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -124,8 +124,7 @@ public final class ChunkPacker implements Helper {
|
|||||||
blockNames[z << 4 | x] = "air";
|
blockNames[z << 4 | x] = "air";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
CachedChunk cached = new CachedChunk(chunk.x, chunk.z, bitSet, blockNames, specialBlocks);
|
return new CachedChunk(chunk.x, chunk.z, bitSet, blockNames, specialBlocks);
|
||||||
return cached;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String blockToString(Block block) {
|
public static String blockToString(Block block) {
|
||||||
|
12
src/main/java/baritone/cache/WorldScanner.java
vendored
12
src/main/java/baritone/cache/WorldScanner.java
vendored
@ -28,18 +28,16 @@ import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
|
|||||||
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public enum WorldScanner implements Helper {
|
public enum WorldScanner implements Helper {
|
||||||
INSTANCE;
|
INSTANCE;
|
||||||
|
|
||||||
public List<BlockPos> scanLoadedChunks(List<String> blockTypes, int max) {
|
public List<BlockPos> scanLoadedChunks(List<Block> blocks, int max) {
|
||||||
List<Block> asBlocks = blockTypes.stream().map(ChunkPacker::stringToBlock).collect(Collectors.toList());
|
if (blocks.contains(null)) {
|
||||||
if (asBlocks.contains(null)) {
|
throw new IllegalStateException("Invalid block name should have been caught earlier: " + blocks.toString());
|
||||||
throw new IllegalStateException("Invalid block name should have been caught earlier: " + blockTypes.toString());
|
|
||||||
}
|
}
|
||||||
LinkedList<BlockPos> res = new LinkedList<>();
|
LinkedList<BlockPos> res = new LinkedList<>();
|
||||||
if (asBlocks.isEmpty()) {
|
if (blocks.isEmpty()) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
ChunkProviderClient chunkProvider = world().getChunkProvider();
|
ChunkProviderClient chunkProvider = world().getChunkProvider();
|
||||||
@ -79,7 +77,7 @@ public enum WorldScanner implements Helper {
|
|||||||
for (int z = 0; z < 16; z++) {
|
for (int z = 0; z < 16; z++) {
|
||||||
for (int x = 0; x < 16; x++) {
|
for (int x = 0; x < 16; x++) {
|
||||||
IBlockState state = bsc.get(x, y, z);
|
IBlockState state = bsc.get(x, y, z);
|
||||||
if (asBlocks.contains(state.getBlock())) {
|
if (blocks.contains(state.getBlock())) {
|
||||||
res.add(new BlockPos(chunkX | x, yReal | y, chunkZ | z));
|
res.add(new BlockPos(chunkX | x, yReal | y, chunkZ | z));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -246,13 +246,14 @@ public class ExampleBaritoneControl extends Behavior {
|
|||||||
Waypoint.Tag tag = Waypoint.Tag.fromString(waypointType);
|
Waypoint.Tag tag = Waypoint.Tag.fromString(waypointType);
|
||||||
if (tag == null) {
|
if (tag == null) {
|
||||||
String mining = waypointType;
|
String mining = waypointType;
|
||||||
|
Block block = ChunkPacker.stringToBlock(mining);
|
||||||
//logDirect("Not a valid tag. Tags are: " + Arrays.asList(Waypoint.Tag.values()).toString().toLowerCase());
|
//logDirect("Not a valid tag. Tags are: " + Arrays.asList(Waypoint.Tag.values()).toString().toLowerCase());
|
||||||
event.cancel();
|
event.cancel();
|
||||||
if (ChunkPacker.stringToBlock(mining) == null) {
|
if (block == null) {
|
||||||
logDirect("No locations for " + mining + " known, cancelling");
|
logDirect("No locations for " + mining + " known, cancelling");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
List<BlockPos> locs = MineBehavior.scanFor(Arrays.asList(mining), 64);
|
List<BlockPos> locs = MineBehavior.scanFor(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;
|
return;
|
||||||
|
Loading…
Reference in New Issue
Block a user