Go to file
Chimney Swift 3632491a56 Fix incorrect generator settings being used for Nether and End dimensions 2020-10-04 23:29:19 +10:00
.github Move CONTRIBUTING file 2018-09-29 16:31:50 +02:00
worldgeneratorapi Set version to 1.1.1 2020-09-20 16:23:37 +02:00
worldgeneratorapi-impl Fix incorrect generator settings being used for Nether and End dimensions 2020-10-04 23:29:19 +10:00
.gitattributes Intial commit 2018-06-24 12:37:56 +02:00
.gitignore Ignore JAR files in main directory 2018-09-29 13:36:35 +02:00
.travis.yml Don't use Oracle JDK 2019-12-12 21:53:29 +01:00
LICENSE Intial commit 2018-06-24 12:37:56 +02:00
README.md Update README for version 1.0 2020-07-05 09:04:23 +02:00
pom.xml Set version to 1.1.1 2020-09-20 16:23:37 +02:00

README.md

WorldGeneratorApi

Build Status Download at SpigotMC.org Dev Builds at codemc.io Latest release Commits since latest release

Designing your own world generator for Bukkit is hard. Bukkit doesn't let you hook into the Minecraft terrain generator, so if you just want to change the shape of the terrain, you would need to rewrite almost the entirety of the Minecraft terrain generator. Alternatively, you can hook into Minecraft internals, but this is tricky and tends to break on every Minecraft update.

WorldGeneratorApi provides a clean API to design your own world generator, while still using components of Minecraft if you want. In just a few lines of code, we can create a complete plugin that generates flat worlds:

public class YourPlugin extends JavaPlugin {
    public ChunkGenerator getDefaultWorldGenerator(String worldName, String id) {
        return WorldGeneratorApi.getInstance(this, 1, 0).createCustomGenerator(WorldRef.ofName(worldName), generator -> {
            // Code modifying the world generator goes here
            generator.setBaseTerrainGenerator(new BaseTerrainGenerator() {
	
	            @Override
	            public int getHeight(BiomeGenerator biomeGenerator, int x, int z, HeightType type) {
	            	// Used by for example village generation to probe if the terrain is not too hilly
	            	// If calculating the terrain height would be too complex, you can also extend a
	            	// "BaseNoiseGenerator" instead of a "BaseChunkGenerator" - that class automatically
	            	// calculates the terrain height based on the noise function you give it
	                return 70;
	            }

	            @Override
	            public void setBlocksInChunk(GeneratingChunk chunk) {
	                chunk.getBlocksForChunk().setRegion(0, 0, 0, CHUNK_SIZE, 70, CHUNK_SIZE, Material.STONE);
	            }
	        });
        });
    }
}

A decorated, flat world

As you can see, only the shape of the terrain is modified, the rest of the world generator is untouched. Want to disable flowers and grass? Add generator.getWorldDecorator().withoutDefaultDecorations(DecorationType.VEGETAL_DECORATION);. Don't like caves and ravines? Add generator.getWorldDecorator().withoutDefaultDecorations(DecorationType.CARVING_AIR);.

Features

  • Control the base shape of the terrain.
  • Control the layout of biomes.
  • Disable vanilla resources (caves, flowers, villages, etc.)
  • Add custom resources
  • Supports the async chunk generator of Spigot and Paper

Tutorials/how to use

Server admins only need to download this plugin (see the releases tab) and place it in their plugins folder, alongside with the plugin that asked you to download this API.

Are you a plugin developer? We have a wiki with serveral tutorials to get you started. The source code also contains lots of JavaDocs.

Limitations

  • There is no way to add custom biomes yet.
  • There is no way to spawn entities yet.
  • Adding large custom structures (like villages) is cumbersome, as you need to write the code yourself to divide your structures into chunk-sized parts.

Plugins using WorldGeneratorApi

  • DoughWorldGenerator - a plugin that lets you modify the shape of your terrain. It supports all variables from the old Customized world type, plus some variables from the (now defunct) plugin TerrainControl.
  • PancakeWorldGenerator - generates flat lands, but will all resources (ores, trees, structures, etc.) present. Useful for survival servers that want a flat world.

License

License is MIT, so you can freely use this API, even in premium plugins. Just put up a note that you're using WorldGeneratorApi.

Compiling

We use Maven. Maven can be a bit tricky to install (you need to modify the environment variables of your computer), but once you have managed to do that, just run:

mvn install

You'll end up with a file ./target/WorldGeneratorApi-1.0.jar (version number will be different of course), which is a ready-to-use plugin. There's also the file ./worldgeneratorapi/target/worldgeneratorapi-1.0.jar, which is just the API. This file can be used by plugin developers to code against: it will not run on the server, as it is missing the implementation.

Bug reports, feature requests and pull requests

Contributions are always welcome! Just open an issue or pull request.