don't read empty chunks
This commit is contained in:
parent
54c79a3330
commit
3072142513
@ -53,10 +53,11 @@ public final class CachedRegion implements ICachedChunkAccess {
|
|||||||
@Override
|
@Override
|
||||||
public final void updateCachedChunk(int chunkX, int chunkZ, BitSet data) {
|
public final void updateCachedChunk(int chunkX, int chunkZ, BitSet data) {
|
||||||
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, data);
|
||||||
else
|
} else {
|
||||||
chunk.updateContents(data);
|
chunk.updateContents(data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private CachedChunk getChunk(int chunkX, int chunkZ) {
|
private CachedChunk getChunk(int chunkX, int chunkZ) {
|
||||||
@ -99,6 +100,7 @@ public final class CachedRegion implements ICachedChunkAccess {
|
|||||||
Path regionFile = getRegionFile(path, this.x, this.z);
|
Path regionFile = getRegionFile(path, this.x, this.z);
|
||||||
if (!Files.exists(regionFile))
|
if (!Files.exists(regionFile))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
byte[] decompressed;
|
byte[] decompressed;
|
||||||
try (FileInputStream in = new FileInputStream(regionFile.toFile())) {
|
try (FileInputStream in = new FileInputStream(regionFile.toFile())) {
|
||||||
decompressed = GZIPUtils.decompress(in);
|
decompressed = GZIPUtils.decompress(in);
|
||||||
@ -109,18 +111,28 @@ public final class CachedRegion implements ICachedChunkAccess {
|
|||||||
|
|
||||||
for (int z = 0; z < 32; z++) {
|
for (int z = 0; z < 32; z++) {
|
||||||
for (int x = 0; x < 32; x++) {
|
for (int x = 0; x < 32; x++) {
|
||||||
CachedChunk chunk = this.chunks[x][z];
|
int index = (x + (z << 5)) * CachedChunk.SIZE_IN_BYTES;
|
||||||
if (chunk != null) {
|
byte[] bytes = Arrays.copyOfRange(decompressed, index, index + CachedChunk.SIZE_IN_BYTES);
|
||||||
int index = (x + (z << 5)) * CachedChunk.SIZE_IN_BYTES;
|
if (isAllZeros(bytes)) {
|
||||||
byte[] bytes = Arrays.copyOfRange(decompressed, index, index + CachedChunk.SIZE_IN_BYTES);
|
this.chunks[x][z] = null;
|
||||||
|
} else {
|
||||||
BitSet bits = BitSet.valueOf(bytes);
|
BitSet bits = BitSet.valueOf(bytes);
|
||||||
chunk.updateContents(bits);
|
updateCachedChunk(x, z, bits);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException ignored) {}
|
} catch (IOException ignored) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean isAllZeros(final byte[] array) {
|
||||||
|
for (byte b : array) {
|
||||||
|
if (b != 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The region x coordinate
|
* @return The region x coordinate
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user