From 7ece9454f725120f7f33b053c398b84bdd3d0749 Mon Sep 17 00:00:00 2001 From: Owen <23108066+Owen1212055@users.noreply.github.com> Date: Wed, 8 Jun 2022 09:57:04 -0400 Subject: [PATCH] Use biome source method to prevent loading chunks (#7885) --- ...vanilla-BiomeProvider-from-WorldInfo.patch | 19 +++++++++---------- .../0839-Implement-regenerateChunk.patch | 4 ++-- ...0855-Fix-falling-block-spawn-methods.patch | 6 +++--- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/patches/server/0823-Expose-vanilla-BiomeProvider-from-WorldInfo.patch b/patches/server/0823-Expose-vanilla-BiomeProvider-from-WorldInfo.patch index b7eef3ac3..2e06ade18 100644 --- a/patches/server/0823-Expose-vanilla-BiomeProvider-from-WorldInfo.patch +++ b/patches/server/0823-Expose-vanilla-BiomeProvider-from-WorldInfo.patch @@ -31,30 +31,29 @@ index 46ff259c64560ac7371e138627bf1b71227d308b..ebf70b414c63cdb715d739c3333adbaf biomeProvider = generator.getDefaultBiomeProvider(worldInfo); } diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java -index 58f6348b04d776d510c0ede4e36a202e2fcb765c..425e0940159e335f3919a6f623a56968864b8fc1 100644 +index 58f6348b04d776d510c0ede4e36a202e2fcb765c..17828c924fa20ebc1d72f73adf62f1c0cb078a68 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java -@@ -195,6 +195,31 @@ public class CraftWorld extends CraftRegionAccessor implements World { +@@ -195,6 +195,30 @@ public class CraftWorld extends CraftRegionAccessor implements World { public int getPlayerCount() { return world.players().size(); } + + @Override + public BiomeProvider vanillaBiomeProvider() { -+ final net.minecraft.world.level.chunk.ChunkGenerator chunkGenerator; -+ if (this.getHandle().chunkSource.getGenerator() instanceof org.bukkit.craftbukkit.generator.CustomChunkGenerator bukkit) { -+ chunkGenerator = bukkit.delegate; -+ } else { -+ chunkGenerator = this.getHandle().chunkSource.getGenerator(); -+ } ++ 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.biome.Climate.Sampler sampler = serverCache.randomState().sampler(); + final net.minecraft.core.Registry biomeRegistry = this.getHandle().registryAccess().registryOrThrow(net.minecraft.core.Registry.BIOME_REGISTRY); -+ final List possibleBiomes = chunkGenerator.getBiomeSource().possibleBiomes().stream() ++ ++ final List possibleBiomes = biomeSource.possibleBiomes().stream() + .map(biome -> CraftBlock.biomeBaseToBiome(biomeRegistry, biome)) + .toList(); + return new BiomeProvider() { + @Override + public Biome getBiome(final org.bukkit.generator.WorldInfo worldInfo, final int x, final int y, final int z) { -+ return CraftBlock.biomeBaseToBiome(biomeRegistry, CraftWorld.this.getHandle().getNoiseBiome(x >> 2, y >> 2, z >> 2)); ++ return CraftBlock.biomeBaseToBiome(biomeRegistry, biomeSource.getNoiseBiome(x >> 2, y >> 2, z >> 2, sampler)); + } + + @Override diff --git a/patches/server/0839-Implement-regenerateChunk.patch b/patches/server/0839-Implement-regenerateChunk.patch index 67a81bb84..e5eb6f2f6 100644 --- a/patches/server/0839-Implement-regenerateChunk.patch +++ b/patches/server/0839-Implement-regenerateChunk.patch @@ -6,7 +6,7 @@ Subject: [PATCH] Implement regenerateChunk Co-authored-by: Jason Penilla <11360596+jpenilla@users.noreply.github.com> diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java -index 425e0940159e335f3919a6f623a56968864b8fc1..ee0ae10b555cf21e1e618bb3bc173c3be0e4ff2c 100644 +index 17828c924fa20ebc1d72f73adf62f1c0cb078a68..2e9b782e34ae25e982b45011a36c3b08ab298648 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java @@ -133,6 +133,7 @@ import org.bukkit.util.Vector; @@ -17,7 +17,7 @@ index 425e0940159e335f3919a6f623a56968864b8fc1..ee0ae10b555cf21e1e618bb3bc173c3b private final ServerLevel world; private WorldBorder worldBorder; -@@ -426,27 +427,61 @@ public class CraftWorld extends CraftRegionAccessor implements World { +@@ -425,27 +426,61 @@ public class CraftWorld extends CraftRegionAccessor implements World { @Override public boolean regenerateChunk(int x, int z) { org.spigotmc.AsyncCatcher.catchOp("chunk regenerate"); // Spigot diff --git a/patches/server/0855-Fix-falling-block-spawn-methods.patch b/patches/server/0855-Fix-falling-block-spawn-methods.patch index 70f77adb4..e0fa906c8 100644 --- a/patches/server/0855-Fix-falling-block-spawn-methods.patch +++ b/patches/server/0855-Fix-falling-block-spawn-methods.patch @@ -21,10 +21,10 @@ index d1fca0e3227b5f37c11367548be362f5a49b6a71..5628940cd3c3566c5db2beda506d4f20 if (Snowball.class.isAssignableFrom(clazz)) { entity = new net.minecraft.world.entity.projectile.Snowball(world, x, y, z); diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java -index ee0ae10b555cf21e1e618bb3bc173c3be0e4ff2c..105869020cd5b056b984c57f7196e9256e07b83e 100644 +index 2e9b782e34ae25e982b45011a36c3b08ab298648..e30cd412f30e26aa4c59f367b3cc26ba47e1b21c 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java -@@ -1411,7 +1411,12 @@ public class CraftWorld extends CraftRegionAccessor implements World { +@@ -1410,7 +1410,12 @@ public class CraftWorld extends CraftRegionAccessor implements World { Validate.notNull(material, "Material cannot be null"); Validate.isTrue(material.isBlock(), "Material must be a block"); @@ -38,7 +38,7 @@ index ee0ae10b555cf21e1e618bb3bc173c3be0e4ff2c..105869020cd5b056b984c57f7196e925 return (FallingBlock) entity.getBukkitEntity(); } -@@ -1420,7 +1425,12 @@ public class CraftWorld extends CraftRegionAccessor implements World { +@@ -1419,7 +1424,12 @@ public class CraftWorld extends CraftRegionAccessor implements World { Validate.notNull(location, "Location cannot be null"); Validate.notNull(data, "BlockData cannot be null");