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. By: DerFrZocker <derrieple@gmail.com>
This commit is contained in:
@@ -5,7 +5,6 @@ import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Predicate;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.block.Block;
|
||||
@@ -14,14 +13,15 @@ import org.bukkit.boss.DragonBattle;
|
||||
import org.bukkit.entity.AbstractArrow;
|
||||
import org.bukkit.entity.Arrow;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.FallingBlock;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.LightningStrike;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.generator.BiomeProvider;
|
||||
import org.bukkit.generator.BlockPopulator;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
import org.bukkit.generator.WorldInfo;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.material.MaterialData;
|
||||
import org.bukkit.metadata.Metadatable;
|
||||
@@ -38,7 +38,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
/**
|
||||
* Represents a world, which may contain entities, chunks and blocks
|
||||
*/
|
||||
public interface World extends PluginMessageRecipient, Metadatable {
|
||||
public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient, Metadatable {
|
||||
|
||||
/**
|
||||
* Gets the {@link Block} at the given coordinates
|
||||
@@ -552,16 +552,6 @@ public interface World extends PluginMessageRecipient, Metadatable {
|
||||
*/
|
||||
public boolean generateTree(@NotNull Location loc, @NotNull TreeType type, @NotNull BlockChangeDelegate delegate);
|
||||
|
||||
/**
|
||||
* Creates a entity at the given {@link Location}
|
||||
*
|
||||
* @param loc The location to spawn the entity
|
||||
* @param type The entity to spawn
|
||||
* @return Resulting Entity of this method
|
||||
*/
|
||||
@NotNull
|
||||
public Entity spawnEntity(@NotNull Location loc, @NotNull EntityType type);
|
||||
|
||||
/**
|
||||
* Strikes lightning at the given {@link Location}
|
||||
*
|
||||
@@ -879,22 +869,6 @@ public interface World extends PluginMessageRecipient, Metadatable {
|
||||
@Nullable
|
||||
public RayTraceResult rayTrace(@NotNull Location start, @NotNull Vector direction, double maxDistance, @NotNull FluidCollisionMode fluidCollisionMode, boolean ignorePassableBlocks, double raySize, @Nullable Predicate<Entity> filter);
|
||||
|
||||
/**
|
||||
* Gets the unique name of this world
|
||||
*
|
||||
* @return Name of this world
|
||||
*/
|
||||
@NotNull
|
||||
public String getName();
|
||||
|
||||
/**
|
||||
* Gets the Unique ID of this world
|
||||
*
|
||||
* @return Unique ID of this world.
|
||||
*/
|
||||
@NotNull
|
||||
public UUID getUID();
|
||||
|
||||
/**
|
||||
* Gets the default spawn {@link Location} of this world
|
||||
*
|
||||
@@ -1179,21 +1153,6 @@ public interface World extends PluginMessageRecipient, Metadatable {
|
||||
*/
|
||||
public boolean createExplosion(@NotNull Location loc, float power, boolean setFire, boolean breakBlocks, @Nullable Entity source);
|
||||
|
||||
/**
|
||||
* Gets the {@link Environment} type of this world
|
||||
*
|
||||
* @return This worlds Environment type
|
||||
*/
|
||||
@NotNull
|
||||
public Environment getEnvironment();
|
||||
|
||||
/**
|
||||
* Gets the Seed for this world.
|
||||
*
|
||||
* @return This worlds Seed
|
||||
*/
|
||||
public long getSeed();
|
||||
|
||||
/**
|
||||
* Gets the current PVP setting for this world.
|
||||
*
|
||||
@@ -1216,6 +1175,14 @@ public interface World extends PluginMessageRecipient, Metadatable {
|
||||
@Nullable
|
||||
public ChunkGenerator getGenerator();
|
||||
|
||||
/**
|
||||
* Gets the biome provider for this world
|
||||
*
|
||||
* @return BiomeProvider associated with this world
|
||||
*/
|
||||
@Nullable
|
||||
public BiomeProvider getBiomeProvider();
|
||||
|
||||
/**
|
||||
* Saves world to disk
|
||||
*/
|
||||
@@ -1229,38 +1196,6 @@ public interface World extends PluginMessageRecipient, Metadatable {
|
||||
@NotNull
|
||||
public List<BlockPopulator> getPopulators();
|
||||
|
||||
/**
|
||||
* Spawn an entity of a specific class at the given {@link Location}
|
||||
*
|
||||
* @param location the {@link Location} to spawn the entity at
|
||||
* @param clazz the class of the {@link Entity} to spawn
|
||||
* @param <T> the class of the {@link Entity} to spawn
|
||||
* @return an instance of the spawned {@link Entity}
|
||||
* @throws IllegalArgumentException if either parameter is null or the
|
||||
* {@link Entity} requested cannot be spawned
|
||||
*/
|
||||
@NotNull
|
||||
public <T extends Entity> T spawn(@NotNull Location location, @NotNull Class<T> clazz) throws IllegalArgumentException;
|
||||
|
||||
/**
|
||||
* Spawn an entity of a specific class at the given {@link Location}, with
|
||||
* the supplied function run before the entity is added to the world.
|
||||
* <br>
|
||||
* Note that when the function is run, the entity will not be actually in
|
||||
* the world. Any operation involving such as teleporting the entity is undefined
|
||||
* until after this function returns.
|
||||
*
|
||||
* @param location the {@link Location} to spawn the entity at
|
||||
* @param clazz the class of the {@link Entity} to spawn
|
||||
* @param function the function to be run before the entity is spawned.
|
||||
* @param <T> the class of the {@link Entity} to spawn
|
||||
* @return an instance of the spawned {@link Entity}
|
||||
* @throws IllegalArgumentException if either parameter is null or the
|
||||
* {@link Entity} requested cannot be spawned
|
||||
*/
|
||||
@NotNull
|
||||
public <T extends Entity> T spawn(@NotNull Location location, @NotNull Class<T> clazz, @Nullable Consumer<T> function) throws IllegalArgumentException;
|
||||
|
||||
/**
|
||||
* Spawn a {@link FallingBlock} entity at the given {@link Location} of
|
||||
* the specified {@link Material}. The material dictates what is falling.
|
||||
@@ -1413,17 +1348,6 @@ public interface World extends PluginMessageRecipient, Metadatable {
|
||||
@Deprecated
|
||||
Biome getBiome(int x, int z);
|
||||
|
||||
/**
|
||||
* Gets the biome for the given block coordinates.
|
||||
*
|
||||
* @param x X coordinate of the block
|
||||
* @param y Y coordinate of the block
|
||||
* @param z Z coordinate of the block
|
||||
* @return Biome of the requested block
|
||||
*/
|
||||
@NotNull
|
||||
Biome getBiome(int x, int y, int z);
|
||||
|
||||
/**
|
||||
* Sets the biome for the given block coordinates
|
||||
*
|
||||
@@ -1435,16 +1359,6 @@ public interface World extends PluginMessageRecipient, Metadatable {
|
||||
@Deprecated
|
||||
void setBiome(int x, int z, @NotNull Biome bio);
|
||||
|
||||
/**
|
||||
* Sets the biome for the given block coordinates
|
||||
*
|
||||
* @param x X coordinate of the block
|
||||
* @param y Y coordinate of the block
|
||||
* @param z Z coordinate of the block
|
||||
* @param bio new Biome type for this block
|
||||
*/
|
||||
void setBiome(int x, int y, int z, @NotNull Biome bio);
|
||||
|
||||
/**
|
||||
* Gets the temperature for the given block coordinates.
|
||||
* <p>
|
||||
@@ -1505,24 +1419,6 @@ public interface World extends PluginMessageRecipient, Metadatable {
|
||||
*/
|
||||
public double getHumidity(int x, int y, int z);
|
||||
|
||||
/**
|
||||
* Gets the minimum height of this world.
|
||||
* <p>
|
||||
* If the min height is 0, there are only blocks from y=0.
|
||||
*
|
||||
* @return Minimum height of the world
|
||||
*/
|
||||
public int getMinHeight();
|
||||
|
||||
/**
|
||||
* Gets the maximum height of this world.
|
||||
* <p>
|
||||
* If the max height is 100, there are only blocks from y=0 to y=99.
|
||||
*
|
||||
* @return Maximum height of the world
|
||||
*/
|
||||
public int getMaxHeight();
|
||||
|
||||
/**
|
||||
* Gets the maximum height to which chorus fruits and nether portals can
|
||||
* bring players within this dimension.
|
||||
|
||||
Reference in New Issue
Block a user