Biome arguments

A biome argument suggesting a list of Minecraft biomes

In Minecraft 1.16, they added the ability to refer to in-game biomes. The CommandAPI implements this using the BiomeArgument. As expected, this returns Bukkit's Biome enum when used.

Example - Setting the biome of a chunk

Say you want to set the biome of the current chunk that a player is in. We can do this using the World.setBiome(x, y, z, biome) method for a given world. We will use this command syntax to set the biome of our current chunk:

/setbiome <biome>

And we can set the biome of the current chunk as expected:

new CommandAPICommand("setbiome")
    .withArguments(new BiomeArgument("biome"))
    .executesPlayer((player, args) -> {
        Biome biome = (Biome) args[0];

        Chunk chunk = player.getLocation().getChunk();
        player.getWorld().setBiome(chunk.getX(), player.getLocation().getBlockY(), chunk.getZ(), biome);
    })
    .register();
CommandAPICommand("setbiome")
    .withArguments(BiomeArgument("biome"))
    .executesPlayer(PlayerCommandExecutor { player, args ->
        val biome = args[0] as Biome

        val chunk = player.location.chunk
        player.world.setBiome(chunk.x, player.location.blockY, chunk.z, biome)
    })
    .register()

The BiomeArgument also supports returning a NamespacedKey for custom biomes. This can be done by using the BiomeArgument.NamespacedKey constructor instead of the normal BiomeArgument constructor:

// Makes a BiomeArgument that returns a Biome
new BiomeArgument("biome");

// Makes a BiomeArgument that returns a NamespacedKey
new BiomeArgument.NamespacedKey("biome");

Developer's Note:

Spigot's support for custom biomes is really limited! If you have an example that lets you use custom biomes with namespaced keys, please open a GitHub issue, or reach out to us on Discord!