Paper/patches/removed/1.18/0464-Allow-delegation-to-vanilla-chunk-gen.patch
2021-11-30 19:26:33 +01:00

68 lines
3.8 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MiniDigger <admin@benndorf.dev>
Date: Wed, 29 Apr 2020 02:10:32 +0200
Subject: [PATCH] Allow delegation to vanilla chunk gen
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
index b1dfd1b13652807882e057ae4fb55f9a045d1a16..926ecc79744142c1361399afa61719db435638fa 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -2244,6 +2244,32 @@ public final class CraftServer implements Server {
return new OldCraftChunkData(world.getMinHeight(), world.getMaxHeight(), handle.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY));
}
+ // Paper start
+ @Override
+ public ChunkGenerator.ChunkData createVanillaChunkData(World world, int x, int z) {
+ // get empty object
+ OldCraftChunkData data = (OldCraftChunkData) createChunkData(world);
+ // do bunch of vanilla shit
+ net.minecraft.server.level.ServerLevel nmsWorld = ((CraftWorld) world).getHandle();
+ net.minecraft.world.level.chunk.ProtoChunk protoChunk = new net.minecraft.world.level.chunk.ProtoChunk(new net.minecraft.world.level.ChunkPos(x, z), null, nmsWorld, nmsWorld);
+ List<net.minecraft.world.level.chunk.ChunkAccess> list = new ArrayList<>();
+ list.add(protoChunk);
+ net.minecraft.server.level.WorldGenRegion genRegion = new net.minecraft.server.level.WorldGenRegion(nmsWorld, list, net.minecraft.world.level.chunk.ChunkStatus.EMPTY, -1);
+ // call vanilla generator, one feature after another. Order here is important!
+ net.minecraft.world.level.chunk.ChunkGenerator chunkGenerator = nmsWorld.getChunkSource().generator;
+ if (chunkGenerator instanceof org.bukkit.craftbukkit.generator.CustomChunkGenerator) {
+ chunkGenerator = ((org.bukkit.craftbukkit.generator.CustomChunkGenerator) chunkGenerator).delegate;
+ }
+ chunkGenerator.createBiomes(nmsWorld.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY), protoChunk);
+ chunkGenerator.fillFromNoise((runnable) -> {}, nmsWorld.structureFeatureManager(), protoChunk);
+ chunkGenerator.buildSurfaceAndBedrock(genRegion, protoChunk);
+ // copy over generated sections
+ data.setRawChunkData(protoChunk.getSections());
+ // hooray!
+ return data;
+ }
+ // Paper end
+
@Override
public BossBar createBossBar(String title, BarColor color, BarStyle style, BarFlag... flags) {
return new CraftBossBar(title, color, style, flags);
diff --git a/src/main/java/org/bukkit/craftbukkit/generator/OldCraftChunkData.java b/src/main/java/org/bukkit/craftbukkit/generator/OldCraftChunkData.java
index 960405935e395a31c0300773c41413801cf0d290..f86a8619862c752ca5d47a2ce4c2d0fab6f0810d 100644
--- a/src/main/java/org/bukkit/craftbukkit/generator/OldCraftChunkData.java
+++ b/src/main/java/org/bukkit/craftbukkit/generator/OldCraftChunkData.java
@@ -23,7 +23,7 @@ import org.bukkit.material.MaterialData;
public final class OldCraftChunkData implements ChunkGenerator.ChunkData {
private final int minHeight;
private final int maxHeight;
- private final LevelChunkSection[] sections;
+ private LevelChunkSection[] sections;
private final Registry<net.minecraft.world.level.biome.Biome> biomes;
private Set<BlockPos> tiles;
private final Set<BlockPos> lights = new HashSet<>();
@@ -192,4 +192,10 @@ public final class OldCraftChunkData implements ChunkGenerator.ChunkData {
Set<BlockPos> getLights() {
return this.lights;
}
+
+ // Paper start
+ public void setRawChunkData(LevelChunkSection[] sections) {
+ this.sections = sections;
+ }
+ // Paper end
}