diff --git a/src/main/java/baritone/behavior/impl/FollowBehavior.java b/src/main/java/baritone/behavior/impl/FollowBehavior.java index 55ec5539..8f9a8615 100644 --- a/src/main/java/baritone/behavior/impl/FollowBehavior.java +++ b/src/main/java/baritone/behavior/impl/FollowBehavior.java @@ -29,6 +29,7 @@ import net.minecraft.util.math.BlockPos; * @author leijurv */ public class FollowBehavior extends Behavior { + public static final FollowBehavior INSTANCE = new FollowBehavior(); private FollowBehavior() { @@ -49,8 +50,12 @@ public class FollowBehavior extends Behavior { PathingBehavior.INSTANCE.path(); } - public void follow(Entity follow) { - this.following = follow; + public void follow(Entity entity) { + this.following = entity; + } + + public Entity following() { + return this.following; } public void cancel() { diff --git a/src/main/java/baritone/behavior/impl/MineBehavior.java b/src/main/java/baritone/behavior/impl/MineBehavior.java index 5b0d6a5a..9b220d01 100644 --- a/src/main/java/baritone/behavior/impl/MineBehavior.java +++ b/src/main/java/baritone/behavior/impl/MineBehavior.java @@ -27,6 +27,7 @@ import baritone.pathing.goals.Goal; import baritone.pathing.goals.GoalComposite; import baritone.pathing.goals.GoalTwoBlocks; import baritone.utils.BlockStateInterface; +import net.minecraft.block.Block; import net.minecraft.util.math.BlockPos; import net.minecraft.world.chunk.EmptyChunk; @@ -47,14 +48,14 @@ public class MineBehavior extends Behavior { private MineBehavior() { } - List mining; + private List mining; @Override public void onPathEvent(PathEvent event) { updateGoal(); } - public void updateGoal() { + private void updateGoal() { if (mining == null) { return; } @@ -68,13 +69,13 @@ public class MineBehavior extends Behavior { PathingBehavior.INSTANCE.path(); } - public static List scanFor(List mining, int max) { + public static List scanFor(List mining, int max) { List locs = new ArrayList<>(); - List uninteresting = new ArrayList<>(); + List uninteresting = new ArrayList<>(); //long b = System.currentTimeMillis(); - for (String m : mining) { - if (CachedChunk.BLOCKS_TO_KEEP_TRACK_OF.contains(ChunkPacker.stringToBlock(m))) { - locs.addAll(WorldProvider.INSTANCE.getCurrentWorld().cache.getLocationsOf(m, 1, 1)); + for (Block m : mining) { + if (CachedChunk.BLOCKS_TO_KEEP_TRACK_OF.contains(m)) { + locs.addAll(WorldProvider.INSTANCE.getCurrentWorld().cache.getLocationsOf(ChunkPacker.blockToString(m), 1, 1)); } else { 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 locs.removeAll(locs.stream() .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())); if (locs.size() > max) { locs = locs.subList(0, max); @@ -99,13 +100,18 @@ public class MineBehavior extends Behavior { return locs; } - public void mine(String... mining) { - this.mining = mining == null || mining.length == 0 ? null : new ArrayList<>(Arrays.asList(mining)); + public void mine(String... blocks) { + 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(); } public void cancel() { PathingBehavior.INSTANCE.cancel(); - mine(); + mine((String[]) null); } } diff --git a/src/main/java/baritone/cache/ChunkPacker.java b/src/main/java/baritone/cache/ChunkPacker.java index 9dffe5ae..5c2374ce 100644 --- a/src/main/java/baritone/cache/ChunkPacker.java +++ b/src/main/java/baritone/cache/ChunkPacker.java @@ -124,8 +124,7 @@ public final class ChunkPacker implements Helper { blockNames[z << 4 | x] = "air"; } } - CachedChunk cached = new CachedChunk(chunk.x, chunk.z, bitSet, blockNames, specialBlocks); - return cached; + return new CachedChunk(chunk.x, chunk.z, bitSet, blockNames, specialBlocks); } public static String blockToString(Block block) { diff --git a/src/main/java/baritone/cache/WorldScanner.java b/src/main/java/baritone/cache/WorldScanner.java index 2b1ebe23..975683d1 100644 --- a/src/main/java/baritone/cache/WorldScanner.java +++ b/src/main/java/baritone/cache/WorldScanner.java @@ -28,18 +28,16 @@ import net.minecraft.world.chunk.storage.ExtendedBlockStorage; import java.util.LinkedList; import java.util.List; -import java.util.stream.Collectors; public enum WorldScanner implements Helper { INSTANCE; - public List scanLoadedChunks(List blockTypes, int max) { - List asBlocks = blockTypes.stream().map(ChunkPacker::stringToBlock).collect(Collectors.toList()); - if (asBlocks.contains(null)) { - throw new IllegalStateException("Invalid block name should have been caught earlier: " + blockTypes.toString()); + public List scanLoadedChunks(List blocks, int max) { + if (blocks.contains(null)) { + throw new IllegalStateException("Invalid block name should have been caught earlier: " + blocks.toString()); } LinkedList res = new LinkedList<>(); - if (asBlocks.isEmpty()) { + if (blocks.isEmpty()) { return res; } ChunkProviderClient chunkProvider = world().getChunkProvider(); @@ -79,7 +77,7 @@ public enum WorldScanner implements Helper { for (int z = 0; z < 16; z++) { for (int x = 0; x < 16; x++) { 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)); } } diff --git a/src/main/java/baritone/utils/ExampleBaritoneControl.java b/src/main/java/baritone/utils/ExampleBaritoneControl.java index 6a301a6c..3abd11b5 100644 --- a/src/main/java/baritone/utils/ExampleBaritoneControl.java +++ b/src/main/java/baritone/utils/ExampleBaritoneControl.java @@ -246,13 +246,14 @@ public class ExampleBaritoneControl extends Behavior { Waypoint.Tag tag = Waypoint.Tag.fromString(waypointType); if (tag == null) { String mining = waypointType; + Block block = ChunkPacker.stringToBlock(mining); //logDirect("Not a valid tag. Tags are: " + Arrays.asList(Waypoint.Tag.values()).toString().toLowerCase()); event.cancel(); - if (ChunkPacker.stringToBlock(mining) == null) { + if (block == null) { logDirect("No locations for " + mining + " known, cancelling"); return; } - List locs = MineBehavior.scanFor(Arrays.asList(mining), 64); + List locs = MineBehavior.scanFor(Collections.singletonList(block), 64); if (locs.isEmpty()) { logDirect("No locations for " + mining + " known, cancelling"); return;