Fix oversized chunk merging

This commit is contained in:
Nassim Jahnke 2021-11-27 16:07:45 +01:00 committed by MiniDigger | Martin
parent 8e5d5b8753
commit 0440a08b8d
4 changed files with 25 additions and 30 deletions

View File

@ -142,7 +142,7 @@ index 04e45b4de2f4e26853a4fed6271cf79ef8607154..44de464b5f2190944c7a7316a76e13f9
private final ChunkPos pos;
diff --git a/src/main/java/net/minecraft/world/level/chunk/storage/RegionFileStorage.java b/src/main/java/net/minecraft/world/level/chunk/storage/RegionFileStorage.java
index 40830a2b231df9bbf676d8325e76c8252a6c1d6c..164db987210aae06432a6abd9b22796c2168e212 100644
index 40830a2b231df9bbf676d8325e76c8252a6c1d6c..2cbc17288b1dc52edb2bdad29976d0f551b1e176 100644
--- a/src/main/java/net/minecraft/world/level/chunk/storage/RegionFileStorage.java
+++ b/src/main/java/net/minecraft/world/level/chunk/storage/RegionFileStorage.java
@@ -11,8 +11,10 @@ import java.nio.file.Files;
@ -156,7 +156,7 @@ index 40830a2b231df9bbf676d8325e76c8252a6c1d6c..164db987210aae06432a6abd9b22796c
import net.minecraft.util.ExceptionCollector;
import net.minecraft.world.level.ChunkPos;
@@ -79,6 +81,74 @@ public class RegionFileStorage implements AutoCloseable {
@@ -79,6 +81,71 @@ public class RegionFileStorage implements AutoCloseable {
}
}
@ -190,12 +190,9 @@ index 40830a2b231df9bbf676d8325e76c8252a6c1d6c..164db987210aae06432a6abd9b22796c
+ return chunk;
+ }
+ CompoundTag oversizedLevel = oversizedData.getCompound("Level");
+ CompoundTag level = chunk.getCompound("Level");
+
+ mergeChunkList(level, oversizedLevel, "Entities");
+ mergeChunkList(level, oversizedLevel, "TileEntities");
+
+ chunk.put("Level", level);
+ mergeChunkList(chunk, oversizedLevel, "entities", "Entities");
+ mergeChunkList(chunk, oversizedLevel, "block_entities", "TileEntities");
+
+ return chunk;
+ } catch (Throwable throwable) {
@ -205,9 +202,9 @@ index 40830a2b231df9bbf676d8325e76c8252a6c1d6c..164db987210aae06432a6abd9b22796c
+ }
+ }
+
+ 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 oversizedList = oversizedLevel.getList(key, 10);
+ ListTag oversizedList = oversizedLevel.getList(oversizedKey, 10);
+
+ if (!oversizedList.isEmpty()) {
+ levelList.addAll(oversizedList);
@ -231,7 +228,7 @@ index 40830a2b231df9bbf676d8325e76c8252a6c1d6c..164db987210aae06432a6abd9b22796c
@Nullable
public CompoundTag read(ChunkPos pos) throws IOException {
// CraftBukkit start - SPIGOT-5680: There's no good reason to preemptively create files on read, save that for writing
@@ -90,6 +160,12 @@ public class RegionFileStorage implements AutoCloseable {
@@ -90,6 +157,12 @@ public class RegionFileStorage implements AutoCloseable {
try { // Paper
DataInputStream datainputstream = regionfile.getChunkDataInputStream(pos);
@ -244,7 +241,7 @@ index 40830a2b231df9bbf676d8325e76c8252a6c1d6c..164db987210aae06432a6abd9b22796c
CompoundTag nbttagcompound;
label43:
{
@@ -172,6 +248,7 @@ public class RegionFileStorage implements AutoCloseable {
@@ -172,6 +245,7 @@ public class RegionFileStorage implements AutoCloseable {
try {
NbtIo.write(nbt, (DataOutput) dataoutputstream);

View File

@ -184,10 +184,10 @@ index 44de464b5f2190944c7a7316a76e13f9c3b954ab..293cce2c80fbdc18480977f5f6b24d6b
this.padToFullSector();
} finally {
diff --git a/src/main/java/net/minecraft/world/level/chunk/storage/RegionFileStorage.java b/src/main/java/net/minecraft/world/level/chunk/storage/RegionFileStorage.java
index 164db987210aae06432a6abd9b22796c2168e212..91cf5878dc13e1abca0c301d1346248bda251cbf 100644
index 2cbc17288b1dc52edb2bdad29976d0f551b1e176..2ee32657a49937418b352a138aca21fbb27857e6 100644
--- a/src/main/java/net/minecraft/world/level/chunk/storage/RegionFileStorage.java
+++ b/src/main/java/net/minecraft/world/level/chunk/storage/RegionFileStorage.java
@@ -248,6 +248,7 @@ public class RegionFileStorage implements AutoCloseable {
@@ -245,6 +245,7 @@ public class RegionFileStorage implements AutoCloseable {
try {
NbtIo.write(nbt, (DataOutput) dataoutputstream);

View File

@ -678,7 +678,7 @@ index 293cce2c80fbdc18480977f5f6b24d6b4fa8dcf3..834fa7048e3affb4fcc734d56526b9fb
return bytebuffer;
}
diff --git a/src/main/java/net/minecraft/world/level/chunk/storage/RegionFileStorage.java b/src/main/java/net/minecraft/world/level/chunk/storage/RegionFileStorage.java
index 0c5f5b2960f1a0d4bbd41c3c3baf101b4c388c43..cf555bd67599441ce53ae8559c1ffd4bb681ac71 100644
index 7b4f3c30cfc4bf68cc872598726f7f7eab5f9830..2dde10324e515bd58fc6ba7e93156ae783492cc2 100644
--- a/src/main/java/net/minecraft/world/level/chunk/storage/RegionFileStorage.java
+++ b/src/main/java/net/minecraft/world/level/chunk/storage/RegionFileStorage.java
@@ -26,7 +26,15 @@ public class RegionFileStorage implements AutoCloseable {
@ -709,7 +709,7 @@ index 0c5f5b2960f1a0d4bbd41c3c3baf101b4c388c43..cf555bd67599441ce53ae8559c1ffd4b
this.regionCache.putAndMoveToFirst(i, regionfile1);
// Paper start
@@ -178,6 +186,13 @@ public class RegionFileStorage implements AutoCloseable {
@@ -175,6 +183,13 @@ public class RegionFileStorage implements AutoCloseable {
if (regionfile == null) {
return null;
}
@ -723,7 +723,7 @@ index 0c5f5b2960f1a0d4bbd41c3c3baf101b4c388c43..cf555bd67599441ce53ae8559c1ffd4b
// CraftBukkit end
try { // Paper
DataInputStream datainputstream = regionfile.getChunkDataInputStream(pos);
@@ -194,6 +209,20 @@ public class RegionFileStorage implements AutoCloseable {
@@ -191,6 +206,20 @@ public class RegionFileStorage implements AutoCloseable {
try {
if (datainputstream != null) {
nbttagcompound = NbtIo.read((DataInput) datainputstream);

View File

@ -4090,10 +4090,10 @@ index 0000000000000000000000000000000000000000..177d0a969f3d72a34e773e8309c3719a
+}
diff --git a/src/main/java/ca/spottedleaf/starlight/common/util/SaveUtil.java b/src/main/java/ca/spottedleaf/starlight/common/util/SaveUtil.java
new file mode 100644
index 0000000000000000000000000000000000000000..0cfb9c213e7970e98895cafdc9dd4b66cf557d72
index 0000000000000000000000000000000000000000..8cb5c999aa48892d0054e769962aca2fb9400e44
--- /dev/null
+++ b/src/main/java/ca/spottedleaf/starlight/common/util/SaveUtil.java
@@ -0,0 +1,185 @@
@@ -0,0 +1,183 @@
+package ca.spottedleaf.starlight.common.util;
+
+import ca.spottedleaf.starlight.common.light.SWMRNibbleArray;
@ -4128,8 +4128,8 @@ index 0000000000000000000000000000000000000000..0cfb9c213e7970e98895cafdc9dd4b66
+ }
+ }
+
+ private static void saveLightHookReal(final Level world, final ChunkAccess chunk, final CompoundTag nbt) {
+ if (nbt == null) {
+ private static void saveLightHookReal(final Level world, final ChunkAccess chunk, final CompoundTag tag) {
+ if (tag == null) {
+ return;
+ }
+
@ -4139,18 +4139,17 @@ index 0000000000000000000000000000000000000000..0cfb9c213e7970e98895cafdc9dd4b66
+ SWMRNibbleArray[] blockNibbles = chunk.getBlockNibbles();
+ SWMRNibbleArray[] skyNibbles = chunk.getSkyNibbles();
+
+ CompoundTag level = nbt.getCompound("Level");
+ boolean lit = chunk.isLightCorrect() || !(world instanceof ServerLevel);
+ // diff start - store our tag for whether light data is init'd
+ if (lit) {
+ level.putBoolean("isLightOn", false);
+ tag.putBoolean("isLightOn", false);
+ }
+ // 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];
+
+ ListTag sectionsStored = level.getList("Sections", 10);
+ ListTag sectionsStored = tag.getList("sections", 10);
+
+ for (int i = 0; i < sectionsStored.size(); ++i) {
+ CompoundTag sectionStored = sectionsStored.getCompound(i);
@ -4207,9 +4206,9 @@ index 0000000000000000000000000000000000000000..0cfb9c213e7970e98895cafdc9dd4b66
+ sectionsStored.add(section);
+ }
+ }
+ level.put("Sections", sectionsStored);
+ tag.put("sections", sectionsStored);
+ 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..0cfb9c213e7970e98895cafdc9dd4b66
+
+
+ // start copy from from the original method
+ CompoundTag levelTag = tag.getCompound("Level");
+ boolean lit = levelTag.get("isLightOn") != null && levelTag.getInt(STARLIGHT_VERSION_TAG) == STARLIGHT_LIGHT_VERSION;
+ boolean lit = tag.get("isLightOn") != null && tag.getInt(STARLIGHT_VERSION_TAG) == STARLIGHT_LIGHT_VERSION;
+ 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
+ ListTag sections = levelTag.getList("Sections", 10);
+ ListTag sections = tag.getList("sections", 10);
+
+ for (int i = 0; i < sections.size(); ++i) {
+ CompoundTag sectionData = sections.getCompound(i);