convert blocks to strings and back less

This commit is contained in:
Leijurv 2018-09-24 15:45:12 -07:00
parent da3f5251b5
commit cef4fb0f50
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
3 changed files with 12 additions and 13 deletions

View File

@ -99,13 +99,13 @@ public final class CachedChunk implements IBlockTypeAccess {
/** /**
* The block names of each surface level block for generating an overview * The block names of each surface level block for generating an overview
*/ */
private final String[] overview; private final IBlockState[] overview;
private final int[] heightMap; private final int[] heightMap;
private final Map<String, List<BlockPos>> specialBlockLocations; private final Map<String, List<BlockPos>> specialBlockLocations;
CachedChunk(int x, int z, BitSet data, String[] overview, Map<String, List<BlockPos>> specialBlockLocations) { CachedChunk(int x, int z, BitSet data, IBlockState[] overview, Map<String, List<BlockPos>> specialBlockLocations) {
validateSize(data); validateSize(data);
this.x = x; this.x = x;
@ -122,12 +122,11 @@ public final class CachedChunk implements IBlockTypeAccess {
int internalPos = z << 4 | x; int internalPos = z << 4 | x;
if (heightMap[internalPos] == y) { if (heightMap[internalPos] == y) {
// we have this exact block, it's a surface block // we have this exact block, it's a surface block
IBlockState state = ChunkPacker.stringToBlock(overview[internalPos]).getDefaultState();
/*System.out.println("Saying that " + x + "," + y + "," + z + " is " + state); /*System.out.println("Saying that " + x + "," + y + "," + z + " is " + state);
if (!Minecraft.getMinecraft().world.getBlockState(new BlockPos(x + this.x * 16, y, z + this.z * 16)).getBlock().equals(state.getBlock())) { if (!Minecraft.getMinecraft().world.getBlockState(new BlockPos(x + this.x * 16, y, z + this.z * 16)).getBlock().equals(state.getBlock())) {
throw new IllegalStateException("failed " + Minecraft.getMinecraft().world.getBlockState(new BlockPos(x + this.x * 16, y, z + this.z * 16)).getBlock() + " " + state.getBlock() + " " + (x + this.x * 16) + " " + y + " " + (z + this.z * 16)); throw new IllegalStateException("failed " + Minecraft.getMinecraft().world.getBlockState(new BlockPos(x + this.x * 16, y, z + this.z * 16)).getBlock() + " " + state.getBlock() + " " + (x + this.x * 16) + " " + y + " " + (z + this.z * 16));
}*/ }*/
return state; return overview[internalPos];
} }
PathingBlockType type = getType(x, y, z); PathingBlockType type = getType(x, y, z);
if (type == PathingBlockType.SOLID && y == 127 && mc.player.dimension == -1) { if (type == PathingBlockType.SOLID && y == 127 && mc.player.dimension == -1) {
@ -157,7 +156,7 @@ public final class CachedChunk implements IBlockTypeAccess {
} }
} }
public final String[] getOverview() { public final IBlockState[] getOverview() {
return overview; return overview;
} }

View File

@ -145,7 +145,7 @@ public final class CachedRegion implements IBlockTypeAccess {
for (int x = 0; x < 32; x++) { for (int x = 0; x < 32; x++) {
if (chunks[x][z] != null) { if (chunks[x][z] != null) {
for (int i = 0; i < 256; i++) { for (int i = 0; i < 256; i++) {
out.writeUTF(chunks[x][z].getOverview()[i]); out.writeUTF(ChunkPacker.blockToString(chunks[x][z].getOverview()[i].getBlock()));
} }
} }
} }
@ -215,7 +215,7 @@ public final class CachedRegion implements IBlockTypeAccess {
int regionZ = this.z; int regionZ = this.z;
int chunkX = x + 32 * regionX; int chunkX = x + 32 * regionX;
int chunkZ = z + 32 * regionZ; int chunkZ = z + 32 * regionZ;
tmpCached[x][z] = new CachedChunk(chunkX, chunkZ, BitSet.valueOf(bytes), new String[256], location[x][z]); tmpCached[x][z] = new CachedChunk(chunkX, chunkZ, BitSet.valueOf(bytes), new IBlockState[256], location[x][z]);
break; break;
case CHUNK_NOT_PRESENT: case CHUNK_NOT_PRESENT:
tmpCached[x][z] = null; tmpCached[x][z] = null;
@ -229,7 +229,7 @@ public final class CachedRegion implements IBlockTypeAccess {
for (int x = 0; x < 32; x++) { for (int x = 0; x < 32; x++) {
if (tmpCached[x][z] != null) { if (tmpCached[x][z] != null) {
for (int i = 0; i < 256; i++) { for (int i = 0; i < 256; i++) {
tmpCached[x][z].getOverview()[i] = in.readUTF(); tmpCached[x][z].getOverview()[i] = ChunkPacker.stringToBlock(in.readUTF()).getDefaultState();
} }
} }
} }

View File

@ -89,7 +89,8 @@ public final class ChunkPacker implements Helper {
} }
//long end = System.nanoTime() / 1000000L; //long end = System.nanoTime() / 1000000L;
//System.out.println("Chunk packing took " + (end - start) + "ms for " + chunk.x + "," + chunk.z); //System.out.println("Chunk packing took " + (end - start) + "ms for " + chunk.x + "," + chunk.z);
String[] blockNames = new String[256]; IBlockState[] blocks = new IBlockState[256];
for (int z = 0; z < 16; z++) { for (int z = 0; z < 16; z++) {
// @formatter:off // @formatter:off
https://www.ibm.com/developerworks/library/j-perry-writing-good-java-code/index.html https://www.ibm.com/developerworks/library/j-perry-writing-good-java-code/index.html
@ -98,15 +99,14 @@ public final class ChunkPacker implements Helper {
for (int y = 255; y >= 0; y--) { for (int y = 255; y >= 0; y--) {
int index = CachedChunk.getPositionIndex(x, y, z); int index = CachedChunk.getPositionIndex(x, y, z);
if (bitSet.get(index) || bitSet.get(index + 1)) { if (bitSet.get(index) || bitSet.get(index + 1)) {
String name = blockToString(chunk.getBlockState(x, y, z).getBlock()); blocks[z << 4 | x] = chunk.getBlockState(x, y, z);
blockNames[z << 4 | x] = name;
continue https; continue https;
} }
} }
blockNames[z << 4 | x] = "air"; blocks[z << 4 | x] = Blocks.AIR.getDefaultState();
} }
} }
return new CachedChunk(chunk.x, chunk.z, bitSet, blockNames, specialBlocks); return new CachedChunk(chunk.x, chunk.z, bitSet, blocks, specialBlocks);
} }
public static String blockToString(Block block) { public static String blockToString(Block block) {