Replace String lists containing block names with actual block lists

It just makes sense like wtf
This commit is contained in:
Brady 2018-09-12 17:12:06 -05:00
parent a7504caa67
commit 2fd888b9ee
No known key found for this signature in database
GPG Key ID: 73A788379A197567
5 changed files with 33 additions and 24 deletions

View File

@ -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() {

View File

@ -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<String> mining;
private List<Block> 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<BlockPos> scanFor(List<String> mining, int max) {
public static List<BlockPos> scanFor(List<Block> mining, int max) {
List<BlockPos> locs = new ArrayList<>();
List<String> uninteresting = new ArrayList<>();
List<Block> 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);
}
}

View File

@ -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) {

View File

@ -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<BlockPos> scanLoadedChunks(List<String> blockTypes, int max) {
List<Block> 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<BlockPos> scanLoadedChunks(List<Block> blocks, int max) {
if (blocks.contains(null)) {
throw new IllegalStateException("Invalid block name should have been caught earlier: " + blocks.toString());
}
LinkedList<BlockPos> 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));
}
}

View File

@ -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<BlockPos> locs = MineBehavior.scanFor(Arrays.asList(mining), 64);
List<BlockPos> locs = MineBehavior.scanFor(Collections.singletonList(block), 64);
if (locs.isEmpty()) {
logDirect("No locations for " + mining + " known, cancelling");
return;