Add beginning of surface block caching
This commit is contained in:
parent
45f69a0f33
commit
56975c0e0f
@ -57,12 +57,18 @@ public final class CachedChunk implements IBlockTypeAccess {
|
|||||||
*/
|
*/
|
||||||
private final BitSet data;
|
private final BitSet data;
|
||||||
|
|
||||||
CachedChunk(int x, int z, BitSet data) {
|
/**
|
||||||
|
* The block names of each surface level block for generating an overview
|
||||||
|
*/
|
||||||
|
private final String[] overview;
|
||||||
|
|
||||||
|
CachedChunk(int x, int z, BitSet data, String[] overview) {
|
||||||
validateSize(data);
|
validateSize(data);
|
||||||
|
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.z = z;
|
this.z = z;
|
||||||
this.data = data;
|
this.data = data;
|
||||||
|
this.overview = overview;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -77,12 +77,12 @@ public final class CachedRegion implements IBlockTypeAccess {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
final void updateCachedChunk(int chunkX, int chunkZ, BitSet data) {
|
final void updateCachedChunk(int chunkX, int chunkZ, BitSet chunkData, String[] chunkOverview) {
|
||||||
CachedChunk chunk = this.getChunk(chunkX, chunkZ);
|
CachedChunk chunk = this.getChunk(chunkX, chunkZ);
|
||||||
if (chunk == null) {
|
if (chunk == null) {
|
||||||
this.chunks[chunkX][chunkZ] = new CachedChunk(chunkX, chunkZ, data);
|
this.chunks[chunkX][chunkZ] = new CachedChunk(chunkX, chunkZ, chunkData, chunkOverview);
|
||||||
} else {
|
} else {
|
||||||
chunk.updateContents(data);
|
chunk.updateContents(chunkData);
|
||||||
}
|
}
|
||||||
hasUnsavedChanges = true;
|
hasUnsavedChanges = true;
|
||||||
}
|
}
|
||||||
@ -176,7 +176,11 @@ public final class CachedRegion implements IBlockTypeAccess {
|
|||||||
byte[] bytes = new byte[CachedChunk.SIZE_IN_BYTES];
|
byte[] bytes = new byte[CachedChunk.SIZE_IN_BYTES];
|
||||||
in.readFully(bytes);
|
in.readFully(bytes);
|
||||||
BitSet bits = BitSet.valueOf(bytes);
|
BitSet bits = BitSet.valueOf(bytes);
|
||||||
updateCachedChunk(x, z, bits);
|
String[] overview = new String[256];
|
||||||
|
for(int i = 0; i < 256; i++) {
|
||||||
|
overview[i] = in.readUTF();
|
||||||
|
}
|
||||||
|
updateCachedChunk(x, z, bits, overview);
|
||||||
break;
|
break;
|
||||||
case CHUNK_NOT_PRESENT:
|
case CHUNK_NOT_PRESENT:
|
||||||
this.chunks[x][z] = null;
|
this.chunks[x][z] = null;
|
||||||
|
@ -73,7 +73,7 @@ public final class CachedWorld implements IBlockTypeAccess {
|
|||||||
|
|
||||||
private void updateCachedChunk(int chunkX, int chunkZ, BitSet data) {
|
private void updateCachedChunk(int chunkX, int chunkZ, BitSet data) {
|
||||||
CachedRegion region = getOrCreateRegion(chunkX >> 5, chunkZ >> 5);
|
CachedRegion region = getOrCreateRegion(chunkX >> 5, chunkZ >> 5);
|
||||||
region.updateCachedChunk(chunkX & 31, chunkZ & 31, data);
|
region.updateCachedChunk(chunkX & 31, chunkZ & 31, data, );
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void save() {
|
public final void save() {
|
||||||
@ -155,8 +155,9 @@ public final class CachedWorld implements IBlockTypeAccess {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Chunk chunk = queue.take();
|
Chunk chunk = queue.take();
|
||||||
BitSet packed = ChunkPacker.createPackedChunk(chunk);
|
BitSet packedChunk = ChunkPacker.createPackedChunk(chunk);
|
||||||
CachedWorld.this.updateCachedChunk(chunk.x, chunk.z, packed);
|
String[] packedOverview = ChunkPacker.createPackedOverview(chunk);
|
||||||
|
CachedWorld.this.updateCachedChunk(chunk.x, chunk.z, packedChunk);
|
||||||
//System.out.println("Processed chunk at " + chunk.x + "," + chunk.z);
|
//System.out.println("Processed chunk at " + chunk.x + "," + chunk.z);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -20,11 +20,14 @@ package baritone.bot.chunk;
|
|||||||
import baritone.bot.pathing.movement.MovementHelper;
|
import baritone.bot.pathing.movement.MovementHelper;
|
||||||
import baritone.bot.utils.BlockStateInterface;
|
import baritone.bot.utils.BlockStateInterface;
|
||||||
import baritone.bot.utils.Helper;
|
import baritone.bot.utils.Helper;
|
||||||
|
import baritone.bot.utils.pathing.BetterBlockPos;
|
||||||
import baritone.bot.utils.pathing.PathingBlockType;
|
import baritone.bot.utils.pathing.PathingBlockType;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockAir;
|
import net.minecraft.block.BlockAir;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
|
import net.minecraft.init.Blocks;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.util.math.BlockPos.MutableBlockPos;
|
||||||
import net.minecraft.world.chunk.Chunk;
|
import net.minecraft.world.chunk.Chunk;
|
||||||
|
|
||||||
import java.util.BitSet;
|
import java.util.BitSet;
|
||||||
@ -59,6 +62,26 @@ public final class ChunkPacker implements Helper {
|
|||||||
return bitSet;
|
return bitSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String[] createPackedOverview(Chunk chunk) {
|
||||||
|
long start = System.currentTimeMillis();
|
||||||
|
String[] blockNames = new String[256];
|
||||||
|
for(int z = 0; z < 16; z++) {
|
||||||
|
for(int x = 0; x < 16; x++) {
|
||||||
|
int height = chunk.getHeightValue(x, z);
|
||||||
|
IBlockState blockState = chunk.getBlockState(x, height, z);
|
||||||
|
for(int y = height; y > 0; y--) {
|
||||||
|
blockState = chunk.getBlockState(x, y, z);
|
||||||
|
if(blockState.getBlock() != Blocks.AIR) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
blockNames[z << 4 | x] = blockState.getBlock().getLocalizedName();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
long end = System.currentTimeMillis();
|
||||||
|
return blockNames;
|
||||||
|
}
|
||||||
|
|
||||||
private static PathingBlockType getPathingBlockType(BlockPos pos, IBlockState state) {
|
private static PathingBlockType getPathingBlockType(BlockPos pos, IBlockState state) {
|
||||||
Block block = state.getBlock();
|
Block block = state.getBlock();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user