crapton of performance improvements
This commit is contained in:
parent
71cb0f6d36
commit
a73f5c1359
@ -535,6 +535,11 @@ public final class Settings {
|
||||
*/
|
||||
public final Setting<Integer> mineGoalUpdateInterval = new Setting<>(5);
|
||||
|
||||
/**
|
||||
* After finding this many instances of the target block in the cache, it will stop expanding outward the chunk search.
|
||||
*/
|
||||
public final Setting<Integer> maxCachedWorldScanCount = new Setting<>(10);
|
||||
|
||||
/**
|
||||
* When GetToBlock doesn't know any locations for the desired block, explore randomly instead of giving up.
|
||||
*/
|
||||
|
@ -20,7 +20,7 @@ package baritone.api.cache;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* @author Brady
|
||||
@ -68,7 +68,7 @@ public interface ICachedWorld {
|
||||
* @param maxRegionDistanceSq The maximum region distance, squared
|
||||
* @return The locations found that match the special block
|
||||
*/
|
||||
LinkedList<BlockPos> getLocationsOf(String block, int maximum, int centerX, int centerZ, int maxRegionDistanceSq);
|
||||
ArrayList<BlockPos> getLocationsOf(String block, int maximum, int centerX, int centerZ, int maxRegionDistanceSq);
|
||||
|
||||
/**
|
||||
* Reloads all of the cached regions in this world from disk. Anything that is not saved
|
||||
|
@ -215,11 +215,11 @@ public final class CachedChunk {
|
||||
return specialBlockLocations;
|
||||
}
|
||||
|
||||
public final LinkedList<BlockPos> getAbsoluteBlocks(String blockType) {
|
||||
public final ArrayList<BlockPos> getAbsoluteBlocks(String blockType) {
|
||||
if (specialBlockLocations.get(blockType) == null) {
|
||||
return null;
|
||||
}
|
||||
LinkedList<BlockPos> res = new LinkedList<>();
|
||||
ArrayList<BlockPos> res = new ArrayList<>();
|
||||
for (BlockPos pos : specialBlockLocations.get(blockType)) {
|
||||
res.add(new BlockPos(pos.getX() + x * 16, pos.getY(), pos.getZ() + z * 16));
|
||||
}
|
||||
|
13
src/main/java/baritone/cache/CachedRegion.java
vendored
13
src/main/java/baritone/cache/CachedRegion.java
vendored
@ -87,19 +87,16 @@ public final class CachedRegion implements ICachedRegion {
|
||||
return chunks[x >> 4][z >> 4] != null;
|
||||
}
|
||||
|
||||
public final LinkedList<BlockPos> getLocationsOf(String block) {
|
||||
LinkedList<BlockPos> res = new LinkedList<>();
|
||||
public final ArrayList<BlockPos> getLocationsOf(String block) {
|
||||
ArrayList<BlockPos> res = new ArrayList<>();
|
||||
for (int chunkX = 0; chunkX < 32; chunkX++) {
|
||||
for (int chunkZ = 0; chunkZ < 32; chunkZ++) {
|
||||
if (chunks[chunkX][chunkZ] == null) {
|
||||
continue;
|
||||
}
|
||||
List<BlockPos> locs = chunks[chunkX][chunkZ].getAbsoluteBlocks(block);
|
||||
if (locs == null) {
|
||||
continue;
|
||||
}
|
||||
for (BlockPos pos : locs) {
|
||||
res.add(pos);
|
||||
ArrayList<BlockPos> locs = chunks[chunkX][chunkZ].getAbsoluteBlocks(block);
|
||||
if (locs != null) {
|
||||
res.addAll(locs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,6 @@ import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
@ -109,8 +108,8 @@ public final class CachedWorld implements ICachedWorld, Helper {
|
||||
}
|
||||
|
||||
@Override
|
||||
public final LinkedList<BlockPos> getLocationsOf(String block, int maximum, int centerX, int centerZ, int maxRegionDistanceSq) {
|
||||
LinkedList<BlockPos> res = new LinkedList<>();
|
||||
public final ArrayList<BlockPos> getLocationsOf(String block, int maximum, int centerX, int centerZ, int maxRegionDistanceSq) {
|
||||
ArrayList<BlockPos> res = new ArrayList<>();
|
||||
int centerRegionX = centerX >> 9;
|
||||
int centerRegionZ = centerZ >> 9;
|
||||
|
||||
@ -127,7 +126,7 @@ public final class CachedWorld implements ICachedWorld, Helper {
|
||||
CachedRegion region = getOrCreateRegion(regionX, regionZ);
|
||||
if (region != null) {
|
||||
// TODO: 100% verify if this or addAll is faster.
|
||||
region.getLocationsOf(block).forEach(res::add);
|
||||
res.addAll(region.getLocationsOf(block));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -210,7 +210,8 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
|
||||
//long b = System.currentTimeMillis();
|
||||
for (Block m : mining) {
|
||||
if (CachedChunk.BLOCKS_TO_KEEP_TRACK_OF.contains(m)) {
|
||||
locs.addAll(ctx.worldData.getCachedWorld().getLocationsOf(ChunkPacker.blockToString(m), 1, ctx.getBaritone().getPlayerContext().playerFeet().getX(), ctx.getBaritone().getPlayerContext().playerFeet().getZ(), 2));
|
||||
// maxRegionDistanceSq 2 means adjacent directly or adjacent diagonally; nothing further than that
|
||||
locs.addAll(ctx.worldData.getCachedWorld().getLocationsOf(ChunkPacker.blockToString(m), Baritone.settings().maxCachedWorldScanCount.get(), ctx.getBaritone().getPlayerContext().playerFeet().getX(), ctx.getBaritone().getPlayerContext().playerFeet().getZ(), 2));
|
||||
} else {
|
||||
uninteresting.add(m);
|
||||
}
|
||||
@ -221,7 +222,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
|
||||
}
|
||||
if (!uninteresting.isEmpty()) {
|
||||
//long before = System.currentTimeMillis();
|
||||
locs.addAll(WorldScanner.INSTANCE.scanChunkRadius(ctx.getBaritone().getPlayerContext(), uninteresting, max, 10, 26));
|
||||
locs.addAll(WorldScanner.INSTANCE.scanChunkRadius(ctx.getBaritone().getPlayerContext(), uninteresting, max, 10, 5)); // maxSearchRadius is NOT sq
|
||||
//System.out.println("Scan of loaded chunks took " + (System.currentTimeMillis() - before) + "ms");
|
||||
}
|
||||
locs.addAll(alreadyKnown);
|
||||
|
@ -376,7 +376,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
||||
}
|
||||
if (msg.startsWith("find")) {
|
||||
String blockType = msg.substring(4).trim();
|
||||
LinkedList<BlockPos> locs = baritone.getWorldProvider().getCurrentWorld().getCachedWorld().getLocationsOf(blockType, 1, ctx.playerFeet().getX(), ctx.playerFeet().getZ(), 4);
|
||||
ArrayList<BlockPos> locs = baritone.getWorldProvider().getCurrentWorld().getCachedWorld().getLocationsOf(blockType, 1, ctx.playerFeet().getX(), ctx.playerFeet().getZ(), 4);
|
||||
logDirect("Have " + locs.size() + " locations");
|
||||
for (BlockPos pos : locs) {
|
||||
Block actually = BlockStateInterface.get(ctx, pos).getBlock();
|
||||
|
Loading…
Reference in New Issue
Block a user