From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: MiniDigger Date: Wed, 29 Apr 2020 02:10:32 +0200 Subject: [PATCH] Allow delegation to vanilla chunk gen diff --git a/src/main/java/net/minecraft/server/ChunkConverter.java b/src/main/java/net/minecraft/server/ChunkConverter.java index b51613040e4583ff056060b47b1f97a86ebcde51..5366314e5f889b5b8d7740bbd0f024d9b7b9d643 100644 --- a/src/main/java/net/minecraft/server/ChunkConverter.java +++ b/src/main/java/net/minecraft/server/ChunkConverter.java @@ -17,7 +17,7 @@ import org.apache.logging.log4j.Logger; public class ChunkConverter { private static final Logger LOGGER = LogManager.getLogger(); - public static final ChunkConverter a = new ChunkConverter(); + public static final ChunkConverter a = new ChunkConverter(); public static ChunkConverter getEmptyConverter() { return a; } // Paper - obfhelper private static final EnumDirection8[] c = EnumDirection8.values(); private final EnumSet d; private final int[][] e; @@ -303,7 +303,7 @@ public class ChunkConverter { if ((Integer) iblockdata.get(BlockProperties.an) >= j) { generatoraccess.setTypeAndData(blockposition, (IBlockData) iblockdata.set(BlockProperties.an, j), 18); if (i != 7) { - EnumDirection[] aenumdirection = null.f; + EnumDirection[] aenumdirection = f; // Paper - decomp fix int k = aenumdirection.length; for (int l = 0; l < k; ++l) { diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java index 530d337e0d1350294aeab5d6fd043496276067bf..5de62da91bc31aae1dff9fedcce11631a6c6ddc7 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java @@ -2028,6 +2028,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.WorldServer nmsWorld = ((CraftWorld) world).getHandle(); + net.minecraft.server.ProtoChunk protoChunk = new net.minecraft.server.ProtoChunk(new net.minecraft.server.ChunkCoordIntPair(x, z), net.minecraft.server.ChunkConverter.getEmptyConverter(), nmsWorld); + List list = new ArrayList<>(); + list.add(protoChunk); + net.minecraft.server.RegionLimitedWorldAccess genRegion = new net.minecraft.server.RegionLimitedWorldAccess(nmsWorld, list); + // call vanilla generator, one feature after another. Order here is important! + net.minecraft.server.ChunkGenerator chunkGenerator = nmsWorld.getChunkProvider().chunkGenerator; + if (chunkGenerator instanceof org.bukkit.craftbukkit.generator.CustomChunkGenerator) { + chunkGenerator = ((org.bukkit.craftbukkit.generator.CustomChunkGenerator) chunkGenerator).delegate; + } + chunkGenerator.createBiomes(nmsWorld.r().b(IRegistry.ay), protoChunk); + chunkGenerator.buildNoise(genRegion, nmsWorld.getStructureManager(), protoChunk); + chunkGenerator.buildBase(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 bb18740ebdf4a14ced9944efa82103b350b32ba5..948a59217cca0f8dfa9d3befb61e679a67bf29bc 100644 --- a/src/main/java/org/bukkit/craftbukkit/generator/CraftChunkData.java +++ b/src/main/java/org/bukkit/craftbukkit/generator/CraftChunkData.java @@ -19,7 +19,7 @@ import org.bukkit.material.MaterialData; */ public final class CraftChunkData implements ChunkGenerator.ChunkData { private final int maxHeight; - private final ChunkSection[] sections; + private ChunkSection[] sections; // Paper - remove final private Set tiles; private World world; // Paper - Anti-Xray - Add world @@ -168,6 +168,12 @@ public final class CraftChunkData implements ChunkGenerator.ChunkData { return sections; } + // Paper start + public void setRawChunkData(ChunkSection[] sections) { + this.sections = sections; + } + // Paper end + Set getTiles() { return tiles; } diff --git a/src/main/java/org/bukkit/craftbukkit/generator/CustomChunkGenerator.java b/src/main/java/org/bukkit/craftbukkit/generator/CustomChunkGenerator.java index c8bce32eac7437a791c7088072b603f634b6036f..41ac4e6415c3ca2fe6b5ffb2c0dde55a21b7033b 100644 --- a/src/main/java/org/bukkit/craftbukkit/generator/CustomChunkGenerator.java +++ b/src/main/java/org/bukkit/craftbukkit/generator/CustomChunkGenerator.java @@ -40,7 +40,7 @@ import org.bukkit.generator.ChunkGenerator.ChunkData; public class CustomChunkGenerator extends InternalChunkGenerator { - private final net.minecraft.server.ChunkGenerator delegate; + public final net.minecraft.server.ChunkGenerator delegate; // Paper - public private final ChunkGenerator generator; private final WorldServer world; private final Random random = new Random();