Skip to content
This repository has been archived by the owner on Oct 18, 2020. It is now read-only.

Commit

Permalink
tried to fix chunks that look corrupted
Browse files Browse the repository at this point in the history
  • Loading branch information
LolHens authored Aug 15, 2020
1 parent c93091b commit 196ab33
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
10 changes: 7 additions & 3 deletions src/main/java/org/dynmap/fabric_1_16_1/ChunkSnapshot.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,10 @@ public ChunkSnapshot(int worldheight, int x, int z, long captime, long inhabited
this.inhabitedTicks = inhabitedTime;
}

public ChunkSnapshot(CompoundTag nbt, int worldheight) {
public static class StateListException extends Exception {
}

public ChunkSnapshot(CompoundTag nbt, int worldheight) throws StateListException {
this.x = nbt.getInt("xPos");
this.z = nbt.getInt("zPos");
this.captureFulltime = 0;
Expand Down Expand Up @@ -188,9 +191,10 @@ public ChunkSnapshot(CompoundTag nbt, int worldheight) {
int expectedStatelistLength = (4096 + (64 / bitsperblock) - 1) / (64 / bitsperblock);
if (expectedStatelistLength > statelist.length) { // TODO: find out why this is happening and why it doesn't seem to happen on other platforms
Log.warning("Got statelist of length " + statelist.length + " but expected a length of " + expectedStatelistLength + " at ChunkPos(x=" + x + ",z=" + z + ")");
long[] expandedStatelist = new long[expectedStatelistLength];
throw new StateListException();
/*long[] expandedStatelist = new long[expectedStatelistLength];
System.arraycopy(statelist, 0, expandedStatelist, 0, statelist.length);
statelist = expandedStatelist;
statelist = expandedStatelist;*/
}

PackedIntegerArray db = new PackedIntegerArray(bitsperblock, 4096, statelist);
Expand Down
22 changes: 15 additions & 7 deletions src/main/java/org/dynmap/fabric_1_16_1/FabricMapChunkCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -996,7 +996,7 @@ private boolean tryChunkCache(DynmapChunk chunk, boolean vis) {
}

// Prep snapshot and add to cache
private SnapshotCache.SnapshotRec prepChunkSnapshot(DynmapChunk chunk, CompoundTag nbt) {
private SnapshotCache.SnapshotRec prepChunkSnapshot(DynmapChunk chunk, CompoundTag nbt) throws ChunkSnapshot.StateListException {
ChunkSnapshot ss = new ChunkSnapshot(nbt, dw.worldheight);
DynIntHashMap tileData = new DynIntHashMap();

Expand Down Expand Up @@ -1072,9 +1072,13 @@ else if (cps.isChunkLoaded(chunk.x, chunk.z)) {
if (vis) { // If visible
CompoundTag nbt = ChunkSerializer.serialize((ServerWorld) w, cps.getWorldChunk(chunk.x, chunk.z, false));
if (nbt != null) nbt = nbt.getCompound("Level");
SnapshotCache.SnapshotRec ssr = prepChunkSnapshot(chunk, nbt);
ss = ssr.ss;
tileData = ssr.tileData;
try {
SnapshotCache.SnapshotRec ssr = prepChunkSnapshot(chunk, nbt);
ss = ssr.ss;
tileData = ssr.tileData;
} catch (ChunkSnapshot.StateListException e) {
continue;
}
} else {
if (hidestyle == HiddenChunkStyle.FILL_STONE_PLAIN) {
ss = STONE;
Expand Down Expand Up @@ -1148,9 +1152,13 @@ public int readChunks(int max_to_load) {
tileData = new DynIntHashMap();
} else {
// Prep snapshot
SnapshotCache.SnapshotRec ssr = prepChunkSnapshot(chunk, nbt);
ss = ssr.ss;
tileData = ssr.tileData;
try {
SnapshotCache.SnapshotRec ssr = prepChunkSnapshot(chunk, nbt);
ss = ssr.ss;
tileData = ssr.tileData;
} catch (ChunkSnapshot.StateListException e) {
continue;
}
}
snaparray[chunkindex] = ss;
snaptile[chunkindex] = tileData;
Expand Down

0 comments on commit 196ab33

Please sign in to comment.