-
Notifications
You must be signed in to change notification settings - Fork 9
Biome generators using the Bukkit API
Biome generators decide what biomes spawn where. There are two ways of writing custom biome generators:
- Using resource packs
- Using the Bukkit API
Using resource packs has the advantage that you can work with custom biomes that you added through resource packs. However, you have only limited control over the pattern in which biomes spawn. Basically, you can only create vanilla-like patterns. With the Bukkit API, you can actually generate any biome pattern that you want. However, you cannot spawn custom biomes.
In this tutorial, we will show how to use the Bukkit API to generate custom biomes.
Software tools usage | |
---|---|
Uses Bukkit | Yes |
Uses resource packs | No |
Uses WorldGeneratorApi | No |
There are two ways to make your biome generator known to Bukkit
- Override
getDefaultBiomeProvider(WorldInfo)
inChunkGenerator
. This is only useful if your plugin already supplies a custom chunk generator. See here how to supply a custom chunk generator. Your biome generator will automatically be used whenever your custom chunk generator is used. - Override
getDefaultBiomeProvider(String worldName, String id)
inJavaPlugin
. This is useful if you biome generator can be used on its own.
In this tutorial, we will create a plugin that supplies just a biome generator. Therefore, we will use option 2, which results in a class that looks like this:
import org.bukkit.generator.BiomeProvider;
import org.bukkit.plugin.java.JavaPlugin;
public class TheMainClassOfYourPlugin extends JavaPlugin {
@Override
public BiomeProvider getDefaultBiomeProvider(String worldName, String id) {
return new YourBiomeProvider();
}
// Here other methods can be added, such as onEnable
}
This is the main class of your plugin, so make sure that the plugin.yml
is set up correctly.
Next, we're going to define our biome generator:
public class YourBiomeProvider implements BiomeProvider {
@Override
public Biome getBiome(WorldInfo worldInfo, int x, int y, int z) {
if (x % 8 == 0) {
return Biome.DESERT;
} else {
return Biome.PLAINS;
}
}
@Override
public List<Biome> getBiomes(WorldInfo worldInfo) {
return Arrays.asList(Biome.DESERT, Biome.PLAINS);
}
}
A biome generator needs to override two methods. The first actually generates the biomes. Here, we generate a striped pattern. The second method provides a list of all the biomes that your class can generate.
The x
, y
and z
given to your getBiome
method are block coordinates. However, you cannot decide on the biome of each block individually. Instead, the method is only called for numbers that are divisble by four. For all blocks in between, Minecraft will interpolate the biomes.
Compile your plugin, place the JAR file in the plugins folder, and then edidt the bukkit.yml
file. In the worlds
section, define the biome generator as follows:
worlds:
name_of_your_world:
biome-provider: name_of_your_plugin
Here, name_of_your_world
and name_of_your_plugin
should be replaced by the actual names. Note: if you have already a section for that world, simply add the biome-provider
setting to it, instead of creating a duplicate section.
Once you delete the world and (re)start the server, your striped biomes should show up.