Paper/patches/server/0486-Allow-delegation-to-vanilla-chunk-gen.patch
Jake Potrebic 170382fe35
Updated Upstream (Bukkit/CraftBukkit/Spigot) (#6245)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing

Bukkit Changes:
e7b0f8d6 #642: Add Crafting methods to API
9e58831e SPIGOT-6641: Use varargs in sendMessage
e409fe49 SPIGOT-6545: Unable to set Guardian target via API while awareness is disabled
6997c726 SPIGOT-6661: Fix missing radius from GenericGameEvent
02d03f35 SPIGOT-6369: Add ItemStack to HangingPlaceEvent

CraftBukkit Changes:
0abf420c SPIGOT-6665: Shearing a Snowman does not drop a carved pumpkin
e8e3cbcc #893: Add Crafting methods to API
879acfee Fix missing varargs from previous commit
6572b9c3 SPIGOT-6641: Use varargs in sendMessage
9e06bb2a SPIGOT-6663: Chicken Jockeys chickens don't despawn
699f2d36 SPIGOT-6545: Unable to set Guardian target via API while awareness is disabled
8ffa54ba SPIGOT-6369: Add ItemStack to HangingPlaceEvent
c851639c SPIGOT-6645: Call EntityChangeBlockEvent before PlayerHarvestBlockEvent
8d244b0b SPIGOT-3725, SPIGOT-6638, MC-136917: Properly clear tile entities before replacing

Spigot Changes:
18c71bf4 Rebuild patches
2021-07-22 18:11:56 +00:00

70 Zeilen
3.6 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MiniDigger <admin@minidigger.me>
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 5285a5b16b0b706d9e1728a23628ff12e6b3b55d..df20ac811d673c205695d563f84382d1bf1e82e1 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -2115,6 +2115,32 @@ public final class CraftServer implements Server {
return new CraftChunkData(world);
}
+ // Paper start
+ @Override
+ public ChunkGenerator.ChunkData createVanillaChunkData(World world, int x, int z) {
+ // get empty object
+ CraftChunkData data = (CraftChunkData) 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/CraftChunkData.java b/src/main/java/org/bukkit/craftbukkit/generator/CraftChunkData.java
index c4d5349f515d5c0ffad4db15ecca1431c830b824..4645303efa716442b14e5c1e767b0d94dbb50170 100644
--- a/src/main/java/org/bukkit/craftbukkit/generator/CraftChunkData.java
+++ b/src/main/java/org/bukkit/craftbukkit/generator/CraftChunkData.java
@@ -20,7 +20,7 @@ import org.bukkit.material.MaterialData;
public final class CraftChunkData implements ChunkGenerator.ChunkData {
private final int minHeight;
private final int maxHeight;
- private final LevelChunkSection[] sections;
+ private LevelChunkSection[] sections; // Paper - remove final
private Set<BlockPos> tiles;
private World world; // Paper - Anti-Xray - Add parameters
@@ -173,6 +173,12 @@ public final class CraftChunkData implements ChunkGenerator.ChunkData {
return this.sections;
}
+ // Paper start
+ public void setRawChunkData(LevelChunkSection[] sections) {
+ this.sections = sections;
+ }
+ // Paper end
+
Set<BlockPos> getTiles() {
return this.tiles;
}