Fix oversized chunk merging

This commit is contained in:
Nassim Jahnke 2021-11-27 16:07:45 +01:00
parent 1dc66f14fb
commit 4641f37f4d
2 changed files with 14 additions and 19 deletions

View file

@ -190,12 +190,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ return chunk; + return chunk;
+ } + }
+ CompoundTag oversizedLevel = oversizedData.getCompound("Level"); + CompoundTag oversizedLevel = oversizedData.getCompound("Level");
+ CompoundTag level = chunk.getCompound("Level");
+ +
+ mergeChunkList(level, oversizedLevel, "Entities"); + mergeChunkList(chunk, oversizedLevel, "entities", "Entities");
+ mergeChunkList(level, oversizedLevel, "TileEntities"); + mergeChunkList(chunk, oversizedLevel, "block_entities", "TileEntities");
+
+ chunk.put("Level", level);
+ +
+ return chunk; + return chunk;
+ } catch (Throwable throwable) { + } catch (Throwable throwable) {
@ -205,9 +202,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ } + }
+ } + }
+ +
+ private static void mergeChunkList(CompoundTag level, CompoundTag oversizedLevel, String key) { + private static void mergeChunkList(CompoundTag level, CompoundTag oversizedLevel, String key, String oversizedKey) {
+ ListTag levelList = level.getList(key, 10); + ListTag levelList = level.getList(key, 10);
+ ListTag oversizedList = oversizedLevel.getList(key, 10); + ListTag oversizedList = oversizedLevel.getList(oversizedKey, 10);
+ +
+ if (!oversizedList.isEmpty()) { + if (!oversizedList.isEmpty()) {
+ levelList.addAll(oversizedList); + levelList.addAll(oversizedList);

View file

@ -4128,8 +4128,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ } + }
+ } + }
+ +
+ private static void saveLightHookReal(final Level world, final ChunkAccess chunk, final CompoundTag nbt) { + private static void saveLightHookReal(final Level world, final ChunkAccess chunk, final CompoundTag tag) {
+ if (nbt == null) { + if (tag == null) {
+ return; + return;
+ } + }
+ +
@ -4139,18 +4139,17 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ SWMRNibbleArray[] blockNibbles = chunk.getBlockNibbles(); + SWMRNibbleArray[] blockNibbles = chunk.getBlockNibbles();
+ SWMRNibbleArray[] skyNibbles = chunk.getSkyNibbles(); + SWMRNibbleArray[] skyNibbles = chunk.getSkyNibbles();
+ +
+ CompoundTag level = nbt.getCompound("Level");
+ boolean lit = chunk.isLightCorrect() || !(world instanceof ServerLevel); + boolean lit = chunk.isLightCorrect() || !(world instanceof ServerLevel);
+ // diff start - store our tag for whether light data is init'd + // diff start - store our tag for whether light data is init'd
+ if (lit) { + if (lit) {
+ level.putBoolean("isLightOn", false); + tag.putBoolean("isLightOn", false);
+ } + }
+ // diff end - store our tag for whether light data is init'd + // diff end - store our tag for whether light data is init'd
+ ChunkStatus status = ChunkStatus.byName(level.getString("Status")); + ChunkStatus status = ChunkStatus.byName(tag.getString("Status"));
+ +
+ CompoundTag[] sections = new CompoundTag[maxSection - minSection + 1]; + CompoundTag[] sections = new CompoundTag[maxSection - minSection + 1];
+ +
+ ListTag sectionsStored = level.getList("Sections", 10); + ListTag sectionsStored = tag.getList("sections", 10);
+ +
+ for (int i = 0; i < sectionsStored.size(); ++i) { + for (int i = 0; i < sectionsStored.size(); ++i) {
+ CompoundTag sectionStored = sectionsStored.getCompound(i); + CompoundTag sectionStored = sectionsStored.getCompound(i);
@ -4207,9 +4206,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ sectionsStored.add(section); + sectionsStored.add(section);
+ } + }
+ } + }
+ level.put("Sections", sectionsStored); + tag.put("sections", sectionsStored);
+ if (lit) { + if (lit) {
+ level.putInt(STARLIGHT_VERSION_TAG, STARLIGHT_LIGHT_VERSION); // only mark as fully lit after we have successfully injected our data + tag.putInt(STARLIGHT_VERSION_TAG, STARLIGHT_LIGHT_VERSION); // only mark as fully lit after we have successfully injected our data
+ } + }
+ } + }
+ +
@ -4237,12 +4236,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ +
+ +
+ // start copy from from the original method + // start copy from from the original method
+ CompoundTag levelTag = tag.getCompound("Level"); + boolean lit = tag.get("isLightOn") != null && tag.getInt(STARLIGHT_VERSION_TAG) == STARLIGHT_LIGHT_VERSION;
+ boolean lit = levelTag.get("isLightOn") != null && levelTag.getInt(STARLIGHT_VERSION_TAG) == STARLIGHT_LIGHT_VERSION;
+ boolean canReadSky = world.dimensionType().hasSkyLight(); + boolean canReadSky = world.dimensionType().hasSkyLight();
+ ChunkStatus status = ChunkStatus.byName(tag.getCompound("Level").getString("Status")); + ChunkStatus status = ChunkStatus.byName(tag.getString("Status"));
+ if (lit && status.isOrAfter(ChunkStatus.LIGHT)) { // diff - we add the status check here + if (lit && status.isOrAfter(ChunkStatus.LIGHT)) { // diff - we add the status check here
+ ListTag sections = levelTag.getList("Sections", 10); + ListTag sections = tag.getList("sections", 10);
+ +
+ for (int i = 0; i < sections.size(); ++i) { + for (int i = 0; i < sections.size(); ++i) {
+ CompoundTag sectionData = sections.getCompound(i); + CompoundTag sectionData = sections.getCompound(i);