> For the complete documentation index, see [llms.txt](https://docs.aethercube.fr/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.aethercube.fr/developers/plugins/world-biomes-and-generation.md). Agents can also search and read this documentation through its [MCP server](https://docs.aethercube.fr/~gitbook/mcp).

# World, biomes and generation

This page covers what a plugin can do with the world: add creatures to biome spawn tables and replace terrain generation with a generator of your own.

## Biomes and spawn tables

`server.biomes()` is the `BiomeRegistry`.

| Method                          | Meaning                                                                                                                        |
| ------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
| `get(key)`, `byId(id)`, `all()` | Read biomes. `BiomeDefinition` holds the key, id (0 to 255), climate, terrain shape, surface materials and vegetation density. |
| `spawns(biome)`                 | The natural spawn table of a biome.                                                                                            |
| `addSpawn(owner, biome, entry)` | Add an entry for a plugin. The server removes it when the plugin is disabled.                                                  |
| `removeSpawns(biome, type)`     | Remove every entry of a creature type from a biome. Returns whether one was removed.                                           |

Plugins cannot add biomes. They add spawn entries.

Built-in biomes, all in the `aethercube` namespace:

| Ids      | Biomes                                                                                                                                                                                           |
| -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| 0 to 10  | `ocean`, `beach`, `plains`, `forest`, `desert`, `deep_ocean`, `dense_forest`, `snowfield`, `mountains`, `swamp`, `caverns`                                                                       |
| 11 to 22 | `sunlit_meadows`, `amber_woods`, `elder_grove`, `glowcap_hollows`, `canopy_wilds`, `ochre_badlands`, `frostveil`, `skyspire_peaks`, `mirelight_fen`, `prism_vale`, `ember_reach`, `aether_isles` |

### A spawn entry

```java
import com.velyorix.game.api.util.NamespacedKey;
import com.velyorix.game.api.world.biome.SpawnEntry;

getServer().biomes().addSpawn(
        this,
        new NamespacedKey("aethercube", "aether_isles"),
        new SpawnEntry(new NamespacedKey("skyglass", "keel_drifter"), 2, 1, 2));
```

`SpawnEntry(type, weight, minGroup, maxGroup)`: the weight is 1 to 1000 relative to the other entries of the biome, and a group has 1 to 8 creatures.

`addSpawn` throws `IllegalArgumentException` for an unknown biome or for a type that is not a registered creature type. Spawn entries are not saved. Add them at every start, in `onEnable`.

Natural spawning runs only when `creatures.enabled` is `true` in `server.yml`.

## Looking at a world

`server.world(name)` returns a `World`. `biomeAt(x, y, z)` returns the biome at a block and `regionNameAt(x, y, z)` the name of the region. See [Players, entities and creatures](https://docs.aethercube.fr/developers/plugins/players-entities-creatures.md) for the rest of the `World` API.

## Chunk generators

A generator fills a 32 by 32 by 32 chunk with voxels. The built-in generators are `aethercube:terrain` and `aethercube:flat`. A plugin can add its own and select it with `world.generator` in `server.yml`.

```java
public interface ChunkGenerator {
    NamespacedKey getKey();
    int getVersion();
    default Optional<ChunkGenerator> forVersion(int version) { ... }
    void generate(ChunkGenerationContext context, ChunkBuffer buffer);
}
```

| Part                        | Meaning                                                                                                                                       |
| --------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
| `getKey()`                  | The generator's id, for example `myplugin:islands`.                                                                                           |
| `getVersion()`              | Recorded in `world.meta`. Raise it whenever the output for an existing seed changes.                                                          |
| `forVersion(v)`             | Returns the generator that produced version `v`, so older worlds keep generating as before. By default only the current version is available. |
| `generate(context, buffer)` | Fills the chunk.                                                                                                                              |

`ChunkGenerationContext` is a record: `seed`, `position` (a `ChunkPosition`), `minHeight`, `maxHeight` (exclusive), `config` (the `world.generator_config` map) and `random` (a `RandomGenerator` derived from the seed, the generator key and the position).

`ChunkBuffer` is the write buffer. Coordinates are local, 0 to 31. Material ids are unsigned 16-bit numbers.

| Method                         | Effect                                                                                                                                            |
| ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------- |
| `get(x, y, z)`                 | Read a voxel. The buffer starts all air.                                                                                                          |
| `set(x, y, z, materialId)`     | Write a voxel.                                                                                                                                    |
| `fill(materialId)`             | Fill the whole chunk.                                                                                                                             |
| `setLootChest(x, y, z, table)` | Place a chest that rolls a loot table the first time it is opened. Throws `UnsupportedOperationException` when the buffer cannot hold containers. |

Rules for a generator:

* **Deterministic.** The output depends only on the seed, the position, the version and the configuration. Use `context.random()`, never your own random source or the clock. The server regenerates chunks nobody modified instead of storing them, so a generator that gives a different answer twice would silently change a world.
* **Isolated.** It runs on worker threads, for several chunks at once, and must never touch the live world.
* **Versioned.** A world created with another version is never opened with this generator. Raise the version whenever the output changes.

### A flat generator

```java
import com.velyorix.game.api.util.NamespacedKey;
import com.velyorix.game.api.world.generation.ChunkBuffer;
import com.velyorix.game.api.world.generation.ChunkGenerationContext;
import com.velyorix.game.api.world.generation.ChunkGenerator;

public final class SlabGenerator implements ChunkGenerator {

    private final int material;

    public SlabGenerator(int material) {
        this.material = material;
    }

    @Override
    public NamespacedKey getKey() {
        return new NamespacedKey("myplugin", "slab");
    }

    @Override
    public int getVersion() {
        return 1;
    }

    @Override
    public void generate(ChunkGenerationContext context, ChunkBuffer buffer) {
        int baseY = context.position().y() * 32;
        for (int y = 0; y < 32; y++) {
            if (baseY + y < 8) {
                for (int x = 0; x < 32; x++) {
                    for (int z = 0; z < 32; z++) {
                        buffer.set(x, y, z, material);
                    }
                }
            }
        }
    }
}
```

### Registering a generator

`ChunkGeneratorRegistry.register(generator)` throws `IllegalArgumentException` when the key is taken and `IllegalStateException` once the worlds are loaded. So register in `onLoad`, or in `onEnable` of a plugin that declares `load: STARTUP`:

```java
@Override
public void onLoad() {
    getServer().generators().register(new SlabGenerator(1));
}
```

Then set `world.generator: myplugin:slab` in `server.yml` and create a world. The server records the generator and its version in `world.meta`. A world whose generator is not registered refuses to load. Keep the plugin installed for as long as the world exists.

The registry also offers `get(key)` and `all()`.

## Structures and loot tables

`server.structures()` returns the `StructureRegistry` and `server.lootTables()` the `LootTableRegistry`. Operators use `structure list`, `structure locate <id>` and `structure place <id> [rotation]` to inspect and place the built-in structures. Containers use loot tables, and `LootGenerateEvent` lets a plugin edit what a chest holds. See [Events](https://docs.aethercube.fr/developers/plugins/events.md).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.aethercube.fr/developers/plugins/world-biomes-and-generation.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
