From 479ce445d681980d4d95a74d091649d24939f6b4 Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Sun, 28 Nov 2021 12:09:29 +1100 Subject: [PATCH] Configurable Below Zero Generation By: DerFrZocker --- .../chunk/storage/ChunkStorage.java.patch | 20 ++++++++++++++++--- .../main/java/org/spigotmc/SpigotConfig.java | 5 +++++ .../java/org/spigotmc/SpigotWorldConfig.java | 5 +++++ 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/paper-server/patches/sources/net/minecraft/world/level/chunk/storage/ChunkStorage.java.patch b/paper-server/patches/sources/net/minecraft/world/level/chunk/storage/ChunkStorage.java.patch index 8525d2ca6a..1e67cf2171 100644 --- a/paper-server/patches/sources/net/minecraft/world/level/chunk/storage/ChunkStorage.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/level/chunk/storage/ChunkStorage.java.patch @@ -18,7 +18,7 @@ import net.minecraft.world.level.levelgen.structure.LegacyStructureDataHandler; import net.minecraft.world.level.storage.DimensionDataStorage; -@@ -39,27 +45,71 @@ +@@ -39,27 +45,85 @@ return this.worker.isOldChunkAround(chunkPos, checkRadius); } @@ -94,15 +94,29 @@ - ChunkStorage.removeDatafixingContext(nbt); - NbtUtils.addCurrentDataVersion(nbt); - return nbt; ++ // Spigot start - SPIGOT-6806: Quick and dirty way to prevent below zero generation in old chunks, by setting the status to heightmap instead of empty ++ boolean stopBelowZero = false; ++ boolean belowZeroGenerationInExistingChunks = (generatoraccess != null) ? ((ServerLevel) generatoraccess).spigotConfig.belowZeroGenerationInExistingChunks : org.spigotmc.SpigotConfig.belowZeroGenerationInExistingChunks; ++ ++ if (i <= 2730 && !belowZeroGenerationInExistingChunks) { ++ stopBelowZero = "full".equals(nbttagcompound.getCompound("Level").getString("Status")); ++ } ++ // Spigot end ++ + ChunkStorage.injectDatafixingContext(nbttagcompound, resourcekey, optional); + nbttagcompound = DataFixTypes.CHUNK.updateToCurrentVersion(this.fixerUpper, nbttagcompound, Math.max(1493, i)); ++ // Spigot start ++ if (stopBelowZero) { ++ nbttagcompound.putString("Status", net.minecraft.core.registries.BuiltInRegistries.CHUNK_STATUS.getKey(ChunkStatus.SPAWN).toString()); ++ } ++ // Spigot end + ChunkStorage.removeDatafixingContext(nbttagcompound); + NbtUtils.addCurrentDataVersion(nbttagcompound); + return nbttagcompound; } catch (Exception exception) { CrashReport crashreport = CrashReport.forThrowable(exception, "Updated chunk"); CrashReportCategory crashreportsystemdetails = crashreport.addCategory("Updated chunk details"); -@@ -70,7 +120,7 @@ +@@ -70,7 +134,7 @@ } } @@ -111,7 +125,7 @@ LegacyStructureDataHandler persistentstructurelegacy = this.legacyStructureHandler; if (persistentstructurelegacy == null) { -@@ -85,7 +135,7 @@ +@@ -85,7 +149,7 @@ return persistentstructurelegacy; } diff --git a/paper-server/src/main/java/org/spigotmc/SpigotConfig.java b/paper-server/src/main/java/org/spigotmc/SpigotConfig.java index 92adc987fd..038fd72710 100644 --- a/paper-server/src/main/java/org/spigotmc/SpigotConfig.java +++ b/paper-server/src/main/java/org/spigotmc/SpigotConfig.java @@ -401,4 +401,9 @@ public class SpigotConfig private static void disablePlayerDataSaving() { SpigotConfig.disablePlayerDataSaving = SpigotConfig.getBoolean("players.disable-saving", false); } + + public static boolean belowZeroGenerationInExistingChunks; + private static void belowZeroGenerationInExistingChunks() { + SpigotConfig.belowZeroGenerationInExistingChunks = SpigotConfig.getBoolean("world-settings.default.below-zero-generation-in-existing-chunks", true); + } } diff --git a/paper-server/src/main/java/org/spigotmc/SpigotWorldConfig.java b/paper-server/src/main/java/org/spigotmc/SpigotWorldConfig.java index 75e4aa5c6c..974e679ff2 100644 --- a/paper-server/src/main/java/org/spigotmc/SpigotWorldConfig.java +++ b/paper-server/src/main/java/org/spigotmc/SpigotWorldConfig.java @@ -388,4 +388,9 @@ public class SpigotWorldConfig { this.thunderChance = this.getInt("thunder-chance", 100000); } + + public boolean belowZeroGenerationInExistingChunks; + private void belowZeroGenerationInExistingChunks() { + this.belowZeroGenerationInExistingChunks = this.getBoolean("below-zero-generation-in-existing-chunks", true); + } }