This commit is contained in:
Pierre Kisters 2020-08-15 16:49:02 +02:00
parent e0439fe712
commit 128d356655
6 changed files with 49 additions and 24 deletions

View File

@ -125,7 +125,10 @@ public class ChunkSnapshot {
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;
@ -187,10 +190,11 @@ public class ChunkSnapshot {
int bitsperblock = (statelist.length * 64) / 4096;
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);
long[] expandedStatelist = new long[expectedStatelistLength];
Log.warning("Got statelist of length " + statelist.length + " but expected a length of " + expectedStatelistLength + " at ChunkPos(x=" + x + ",z=" + z + ")");
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);

View File

@ -996,7 +996,7 @@ public class FabricMapChunkCache extends MapChunkCache {
}
// 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();
@ -1072,9 +1072,13 @@ public class FabricMapChunkCache extends MapChunkCache {
if (vis) { // If visible
CompoundTag nbt = ChunkSerializer.serialize((ServerWorld) w, cps.getWorldChunk(chunk.x, chunk.z, false));
if (nbt != null) nbt = nbt.getCompound("Level");
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;
@ -1148,9 +1152,13 @@ public class FabricMapChunkCache extends MapChunkCache {
tileData = new DynIntHashMap();
} else {
// Prep snapshot
try {
SnapshotCache.SnapshotRec ssr = prepChunkSnapshot(chunk, nbt);
ss = ssr.ss;
tileData = ssr.tileData;
} catch (ChunkSnapshot.StateListException e) {
continue;
}
}
snaparray[chunkindex] = ss;
snaptile[chunkindex] = tileData;

View File

@ -50,8 +50,8 @@ public class FabricWorld extends DynmapWorld {
public FabricWorld(WorldAccess w) {
this(getWorldName(w), w.getWorld().getHeight(),
w.getWorld().getSeaLevel(),
w.getWorld().getRegistryKey() == World.END,
w.getWorld().getRegistryKey() == World.NETHER,
w.getWorld().getRegistryKey() == World.END,
w.getWorld().getRegistryKey().getValue().getPath());
setWorldLoaded(w);
}

View File

@ -125,7 +125,10 @@ public class ChunkSnapshot {
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;
@ -187,10 +190,11 @@ public class ChunkSnapshot {
int bitsperblock = (statelist.length * 64) / 4096;
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);
long[] expandedStatelist = new long[expectedStatelistLength];
Log.warning("Got statelist of length " + statelist.length + " but expected a length of " + expectedStatelistLength + " at ChunkPos(x=" + x + ",z=" + z + ")");
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);

View File

@ -1024,7 +1024,7 @@ public class FabricMapChunkCache extends MapChunkCache {
}
// 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();
@ -1104,11 +1104,16 @@ public class FabricMapChunkCache extends MapChunkCache {
} catch (NullPointerException e) {
// TODO: find out why this is happening and why it only seems to happen since 1.16.2
Log.severe("ChunkSerializer.serialize threw a NullPointerException", e);
continue;
}
if (nbt != null) nbt = nbt.getCompound("Level");
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;
@ -1182,9 +1187,13 @@ public class FabricMapChunkCache extends MapChunkCache {
tileData = new DynIntHashMap();
} else {
// Prep snapshot
try {
SnapshotCache.SnapshotRec ssr = prepChunkSnapshot(chunk, nbt);
ss = ssr.ss;
tileData = ssr.tileData;
} catch (ChunkSnapshot.StateListException e) {
continue;
}
}
snaparray[chunkindex] = ss;
snaptile[chunkindex] = tileData;

View File

@ -51,8 +51,8 @@ public class FabricWorld extends DynmapWorld {
public FabricWorld(DynmapPlugin plugin, World w) {
this(plugin, getWorldName(plugin, w), w.getHeight(),
w.getSeaLevel(),
w.getRegistryKey() == World.END,
w.getRegistryKey() == World.NETHER,
w.getRegistryKey() == World.END,
w.getRegistryKey().getValue().getPath());
setWorldLoaded(w);
}