From 5b96be4ce63d5f45669c443c343f77c67dede2fc Mon Sep 17 00:00:00 2001 From: Jason Penilla <11360596+jpenilla@users.noreply.github.com> Date: Sat, 31 Aug 2024 10:59:17 -0700 Subject: [PATCH] Fixup porting issue in vanillaBiomeProvider impl (#11185) --- ...vanilla-BiomeProvider-from-WorldInfo.patch | 48 +++++++++++++++++-- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/patches/server/Expose-vanilla-BiomeProvider-from-WorldInfo.patch b/patches/server/Expose-vanilla-BiomeProvider-from-WorldInfo.patch index 0cfb326c13..27991baf98 100644 --- a/patches/server/Expose-vanilla-BiomeProvider-from-WorldInfo.patch +++ b/patches/server/Expose-vanilla-BiomeProvider-from-WorldInfo.patch @@ -17,6 +17,19 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 if (biomeProvider == null && gen != null) { biomeProvider = gen.getDefaultBiomeProvider(worldInfo); } +diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/net/minecraft/server/level/ServerLevel.java ++++ b/src/main/java/net/minecraft/server/level/ServerLevel.java +@@ -0,0 +0,0 @@ public class ServerLevel extends Level implements WorldGenLevel { + this.serverLevelData.setWorld(this); + + if (biomeProvider != null) { +- BiomeSource worldChunkManager = new CustomWorldChunkManager(this.getWorld(), biomeProvider, this.server.registryAccess().registryOrThrow(Registries.BIOME)); ++ BiomeSource worldChunkManager = new CustomWorldChunkManager(this.getWorld(), biomeProvider, this.server.registryAccess().registryOrThrow(Registries.BIOME), chunkgenerator.getBiomeSource()); // Paper - add vanillaBiomeProvider + if (chunkgenerator instanceof NoiseBasedChunkGenerator cga) { + chunkgenerator = new NoiseBasedChunkGenerator(worldChunkManager, cga.settings); + } else if (chunkgenerator instanceof FlatLevelSource cpf) { diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java @@ -43,16 +56,26 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + public BiomeProvider vanillaBiomeProvider() { + net.minecraft.server.level.ServerChunkCache serverCache = this.getHandle().chunkSource; + -+ final net.minecraft.world.level.biome.BiomeSource biomeSource = serverCache.getGenerator().getBiomeSource(); ++ final net.minecraft.world.level.chunk.ChunkGenerator gen = serverCache.getGenerator(); ++ net.minecraft.world.level.biome.BiomeSource biomeSource; ++ if (gen instanceof org.bukkit.craftbukkit.generator.CustomChunkGenerator custom) { ++ biomeSource = custom.getDelegate().getBiomeSource(); ++ } else { ++ biomeSource = gen.getBiomeSource(); ++ } ++ if (biomeSource instanceof org.bukkit.craftbukkit.generator.CustomWorldChunkManager customBiomeSource) { ++ biomeSource = customBiomeSource.vanillaBiomeSource; ++ } ++ final net.minecraft.world.level.biome.BiomeSource finalBiomeSource = biomeSource; + final net.minecraft.world.level.biome.Climate.Sampler sampler = serverCache.randomState().sampler(); + -+ final List possibleBiomes = biomeSource.possibleBiomes().stream() -+ .map(biome -> org.bukkit.craftbukkit.block.CraftBiome.minecraftHolderToBukkit(biome)) ++ final List possibleBiomes = finalBiomeSource.possibleBiomes().stream() ++ .map(CraftBiome::minecraftHolderToBukkit) + .toList(); + return new BiomeProvider() { + @Override + public Biome getBiome(final org.bukkit.generator.WorldInfo worldInfo, final int x, final int y, final int z) { -+ return org.bukkit.craftbukkit.block.CraftBiome.minecraftHolderToBukkit(biomeSource.getNoiseBiome(x >> 2, y >> 2, z >> 2, sampler)); ++ return CraftBiome.minecraftHolderToBukkit(finalBiomeSource.getNoiseBiome(x >> 2, y >> 2, z >> 2, sampler)); + } + + @Override @@ -135,3 +158,20 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + } + // Paper end } +diff --git a/src/main/java/org/bukkit/craftbukkit/generator/CustomWorldChunkManager.java b/src/main/java/org/bukkit/craftbukkit/generator/CustomWorldChunkManager.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/org/bukkit/craftbukkit/generator/CustomWorldChunkManager.java ++++ b/src/main/java/org/bukkit/craftbukkit/generator/CustomWorldChunkManager.java +@@ -0,0 +0,0 @@ public class CustomWorldChunkManager extends BiomeSource { + return biomeBases; + } + +- public CustomWorldChunkManager(WorldInfo worldInfo, BiomeProvider biomeProvider, Registry registry) { ++ // Paper start - add vanillaBiomeProvider ++ public final BiomeSource vanillaBiomeSource; ++ public CustomWorldChunkManager(WorldInfo worldInfo, BiomeProvider biomeProvider, Registry registry, BiomeSource vanillaBiomeSource) { ++ this.vanillaBiomeSource = vanillaBiomeSource; ++ // Paper end - add vanillaBiomeProvider + this.worldInfo = worldInfo; + this.biomeProvider = biomeProvider; + this.registry = registry;