Skip to content
Success

Changes

Summary

  1. SPIGOT-5880, SPIGOT-5567: New ChunkGenerator API (details)
Commit 4f6bcc84f9cc534388061a0b9d1335aed8c8bc92 by md_5
SPIGOT-5880, SPIGOT-5567: New ChunkGenerator API

## **Current API**
The current world generation API is very old and limited when you want to make more complex world generation. Resulting in some hard to fix bugs such as that you cannot modify blocks outside the chunk in the BlockPopulator (which should and was per the docs possible), or strange behavior such as SPIGOT-5880.

## **New API**
With the new API, the generation is more separate in multiple methods and is more in line with Vanilla chunk generation. The new API is designed to as future proof as possible. If for example a new generation step is added it can easily also be added as a step in API by simply creating the method for it. On the other side if a generation step gets removed, the method can easily be called after another, which is the case with surface and bedrock. The new API and changes are also fully backwards compatible with old chunk generators.

### **Changes in the new api**
**Extra generation steps:**
Noise, surface, bedrock and caves are added as steps. With those generation steps three extra methods for Vanilla generation are also added. Those new methods provide the ChunkData instead of returning one. The reason for this is, that the ChunkData is now backed by a ChunkAccess. With this, each step has the information of the step before and the Vanilla information (if chosen by setting a 'should' method to true). The old method is deprecated.

**New class BiomeProvider**
The BiomeProvider acts as Biome source and wrapper for the NMS class WorldChunkManager. With this the underlying Vanilla ChunkGeneration knows which Biome to use for the structure and decoration generation. (Fixes: SPIGOT-5880). Although the List of Biomes which is required in BiomeProvider, is currently not much in use in Vanilla, I decided to add it to future proof the API when it may be required in later versions of Minecraft.
The BiomeProvider is also separated from the ChunkGenerator for plugins which only want to change the biome map, such as single Biome worlds or if some biomes should be more present than others.

**Deprecated isParallelCapable**
Mojang has and is pushing to a more multi threaded chunk generation. This should also be the case for custom chunk generators. This is why the new API only supports multi threaded generation. This does not affect the old API, which is still checking this.

**Base height method added**
This method was added to also bring the Minecraft generator and Bukkit generator more in line. With this it is possible to return the max height of a location (before decorations). This is useful to let most structures know were to place them. This fixes SPIGOT-5567. (This fixes not all structures placement, desert pyramids for example are still way up at y-level 64, This however is more a vanilla bug and should be fixed at Mojangs end).

**WorldInfo Class**
The World object was swapped for a WorldInfo object. This is because many methods of the World object won't work during world generation and would mostly likely result in a deadlock. It contains any information a plugin should need to identify the world.

**BlockPopulator Changes**
Instead of directly manipulating a chunk, changes are now made to a new class LimitedRegion, this class provides methods to populated the chunk and its surrounding area. The wrapping is done so that the population can be moved into the place where Minecraft generates decorations. Where there is no chunk to access yet. By moving it into this place the generation is now async and the surrounding area of the chunk can also be used.

For common methods between the World and LimitedRegion a RegionAccessor was added.
The file was modifiedsrc/main/java/org/bukkit/craftbukkit/block/CraftChest.java
The file was modifiedsrc/main/java/org/bukkit/craftbukkit/entity/CraftMob.java
The file was addedsrc/main/java/org/bukkit/craftbukkit/generator/OldCraftChunkData.java
The file was modifiedsrc/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
The file was modifiedsrc/main/java/org/bukkit/craftbukkit/block/CraftBlockEntityState.java
The file was modifiedsrc/main/java/org/bukkit/craftbukkit/entity/CraftHanging.java
The file was modifiedsrc/main/java/org/bukkit/craftbukkit/block/CraftBlockState.java
The file was modifiednms-patches/net/minecraft/server/MinecraftServer.patch
The file was modifiedsrc/main/java/org/bukkit/craftbukkit/block/CraftJukebox.java
The file was modifiedsrc/main/java/org/bukkit/craftbukkit/block/CraftBeacon.java
The file was addednms-patches/net/minecraft/world/level/levelgen/ChunkGeneratorAbstract.patch
The file was modifiedsrc/main/java/org/bukkit/craftbukkit/generator/CraftChunkData.java
The file was modifiedsrc/main/java/org/bukkit/craftbukkit/CraftWorld.java
The file was modifiednms-patches/net/minecraft/world/level/chunk/ChunkGenerator.patch
The file was modifiedsrc/main/java/org/bukkit/craftbukkit/block/CraftDropper.java
The file was modifiedsrc/main/java/org/bukkit/craftbukkit/CraftServer.java
The file was modifiedsrc/main/java/org/bukkit/craftbukkit/block/CraftDispenser.java
The file was modifiedsrc/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
The file was modifiednms-patches/net/minecraft/world/entity/Entity.patch
The file was addedsrc/main/java/org/bukkit/craftbukkit/generator/CraftWorldInfo.java
The file was modifiedsrc/main/java/org/bukkit/craftbukkit/block/CraftBeehive.java
The file was modifiedsrc/main/java/org/bukkit/craftbukkit/entity/CraftCreeper.java
The file was modifiednms-patches/net/minecraft/world/level/World.patch
The file was modifiedsrc/main/java/org/bukkit/craftbukkit/entity/CraftVillager.java
The file was addedsrc/main/java/org/bukkit/craftbukkit/generator/CustomWorldChunkManager.java
The file was modifiedsrc/test/java/org/bukkit/craftbukkit/generator/ChunkDataTest.java
The file was modifiedsrc/main/java/org/bukkit/craftbukkit/block/CraftShulkerBox.java
The file was modifiedsrc/main/java/org/bukkit/craftbukkit/util/DummyGeneratorAccess.java
The file was modifiedsrc/main/java/org/bukkit/craftbukkit/entity/CraftPainting.java
The file was modifiedsrc/main/java/org/bukkit/craftbukkit/entity/CraftItemFrame.java
The file was addedsrc/main/java/org/bukkit/craftbukkit/generator/CraftLimitedRegion.java
The file was modifiedsrc/main/java/org/bukkit/craftbukkit/generator/CustomChunkGenerator.java
The file was addedsrc/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java
The file was modifiedsrc/main/java/org/bukkit/craftbukkit/block/CraftBarrel.java
The file was modifiedsrc/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
The file was modifiedsrc/main/java/org/bukkit/craftbukkit/util/BlockStateListPopulator.java
The file was modifiedsrc/main/java/org/bukkit/craftbukkit/CraftHeightMap.java
The file was modifiedsrc/main/java/org/bukkit/craftbukkit/block/CraftLectern.java
The file was modifiednms-patches/net/minecraft/server/level/WorldServer.patch
The file was modifiedsrc/main/java/org/bukkit/craftbukkit/block/CraftStructureBlock.java
The file was modifiedsrc/main/java/org/bukkit/craftbukkit/entity/CraftShulkerBullet.java