World generation
Make a world's chunks with your own ChunkGenerator, add biomes and worlds with data packs, and test your generator on your machine.
Register a generator
- Implement
worldgen::ChunkGenerator. - Register it with
GeneratorManager::register(generator), which returns a generator id. - Call
world.set_chunk_generator(id): the generator makes the world's new chunks.
server.create_world(name, dimension) creates a world; the name is one plain folder name. Making a new world needs the permission worlds.manage (permissions::WORLDS_MANAGE), which the server owner allows.
Set your generator in on_load. When a server names your script as its world generator, no chunk of its main world is made before your generator is set. If your script does not set one, the world stays empty and nobody is sent into it until the next start.
Generation phases
The trait has generate_biomes, generate_noise, generate_surface and generate_features, each with a mutable ChunkBuffer. Implement only the phases you need, and make the output depend only on the inputs, so the same chunk always comes out the same.
Work inside the chunk
ChunkBuffer has x, z, min_y, height, set_block, get_block, fill_layer, fill_range, fill_cuboid, set_biome and fill_biome. Coordinates inside the chunk are 0 to 15, and fills are limited to the chunk's own rows. Use block state ids that are valid for the server's Minecraft version.
Generate only some chunks
A generator for a small map can name the chunks and steps it makes, with ChunkGenerator::scope and GeneratorManager::set_on (or world.set_chunk_generator_scoped). The server calls the generator only for those chunks and steps; every other chunk is made empty without a call into your script.
Keep it fast
- Bound the work and memory of each phase.
- Do not keep the buffer after the call.
- Do no network or file work while generating.
If your generator faults, the server logs it and leaves that chunk as it is.
While the script that makes a world's terrain is not running (it failed to start, was stopped or was unloaded), players who try to enter that world are told at once that it cannot be entered, instead of waiting on a loading screen. The world is not filled with other terrain, and it takes players again as soon as your script runs. The console names the world.
A new generator does not convert terrain that already exists. Use a test world, and keep chunks that were already generated working.
To ship new maps to servers that already have the old chunks, see Game updates and your worlds.
Biomes from a data pack
A data pack can add biomes in vanilla's format: data/<namespace>/worldgen/biome/<name>.json. Add the pack to your server in the panel, or register it from your script in on_load with server.get_datapack_manager().register_pack(id, &files).
- Biomes are read while the server starts. A pack your script registers in
on_loadis known in that same start, before your generator makes its first chunk. A pack added after the server takes players waits for the next start. - Players on Java see the biome's own sky, fog, water, grass, foliage, particles and music. Rain, snow and freezing follow
has_precipitation,temperature,temperature_modifieranddownfall. - Use new names only. A file that reuses a vanilla biome's name is ignored, and so is a file without
has_precipitation,temperatureordownfall. A server takes up to 61 added biomes. - The game's own world generation never places them: your chunk generator does.
- Commands such as
/execute if biomeand/locate biomeaccept the new names. - If a pack is removed, the areas of its biomes in a saved world load as plains.
For Bedrock colours of your biomes, see Resource packs.
Place your biomes
Use set_biome_named, fill_biome_named and fill_biome_cuboid_named on the ChunkBuffer. They take the full name (my_pack:red_city) and return false for a name the server does not know.
biome_names on the world interface lists every biome the server knows, and get_biome_name (on a world and on a chunk) reads a biome's full name. get_biome returns plains for a data pack biome.
Mob spawns
A biome keeps its mob spawns where vanilla does, in attributes."minecraft:gameplay/natural_mob_spawns" (spawns_by_category with type, count and weight, and spawn_costs), so a biome file copied from the game works as it is. count is a number or a uniform or constant int provider. minecraft:gameplay/creature_world_gen_spawn_probability sets the chance of animals appearing with new chunks (0.1 by default, as in the game).
The top-level spawners and creature_spawn_probability fields work too. If a file has spawners and the attribute, the attribute is used and the server log says spawners was ignored. A spawn the server cannot read leaves that biome out, with a line in the log.
Register a data pack from a script
register_pack checks the pack before it takes it:
pack.mcmetadeclares data pack formats (min_formatandmax_format) that include the server's (Minecraft Java 26.3: 121);- every biome file is readable.
A refused pack registers nothing, and the error names the format and range, or the file and the field. Your script needs the permission datapacks.register, which the server owner allows. The documentation of the SDK's datapack module has a whole working pack for 26.3.
Worlds from a data pack
A data pack can add a world: put data/<namespace>/dimension/<name>.json in the pack, with the overworld, nether or end type and the vanilla generator. Other shapes are ignored with a console warning.
- The world is called
<namespace>:<name>. Players and/execute inreach it, and scripts see it in the world list under that name. - It is saved in
world/dimensions/<namespace>/<name>/and uses the seed of the main world, so its terrain is that of the vanilla dimension of its type. - A bed, a respawn anchor or
/spawnpointset there respawns the player there, villagers keep their home and job site there, and a lodestone compass points into it. - A pack in the server's data packs is loaded at the next start, unless it is disabled or asks for a feature the world does not have.
/datapack disablekeeps a pack off across restarts. - If the pack is removed, the player respawns at the world spawn, and the point is kept for when the pack comes back.
Test your generator with cargo test
Your ChunkGenerator can run in a plain cargo test on your own machine. ChunkBuffer::offline(chunk_x, chunk_z, min_y, height) is a chunk in memory (the overworld is -64 and 384). Call your generator's four steps on it and read the result with get_block and get_biome.
- The block lookups (
world::resolve_block_state,world::get_block_by_name,BlockState::from_id,Block::from_nameand the others) give exactly what the server gives for the SDK's Minecraft version, with the same state ids, properties, map colours, light and shapes. - The chunk keeps your writes with the server's rules: a write outside the chunk writes nothing, a box is cut to the chunk, and an unknown state id is written as air.
- Off the server, only the game's own biomes (
Biome) are kept.set_biome_namedand the other_namedcalls returnfalsethere, because only the server knows your data pack's biomes. - Every other call (a world, a player, the server, the scheduler) has no answer off the server and stops the test. A generator meant for tests makes none of them in its four steps.
Look at your map without a server
The Creator Kit's map-preview crate draws your map on your own machine, in a test of your script's crate: a view from above (cut away above a height, so the rooms under a roof show, and lit as the game lights them), the view of a player standing at a place, and every place a player can get to on foot from the spawn, with the places they cannot reach listed. It runs your ChunkGenerator itself: Scene::from_generator makes every chunk of a box you choose with your generator's steps, in memory, and your block lookups get the same answers as on a server, so every vanilla block shows with its map colour, its light and its shape without you describing it. Resolve the block states you write in your generator's constructor or in its steps; any other call to the server has no answer off the server and stops the test with a message. If your map code is a function from a place to a block instead, Scene::read calls it for the box.
Name the test so that it holds preview and let it write its pictures into the preview folder of your project; strawberry-kit preview runs every such test on your machine and lists the pictures written (strawberry-kit preview <test name> runs one). Add the crate for your tests only, and write the test like this:
[dev-dependencies]
map-preview = { version = "=0.1.0", registry = "strawberry" }#[test]
fn preview_level_one() {
use map_preview::{light::Light, top, walk, Heights, Scene};
let scene = Scene::from_generator(&LevelOne::new(), Heights::OVERWORLD, [0, -1, 0], [383, 8, 383]).unwrap();
std::fs::create_dir_all("preview").unwrap();
std::fs::write("preview/top.png", top::top(&scene, Some(4), Some(&Light::of(&scene, false)), 2).png()).unwrap();
let w = walk::walk(&scene, [12.5, 1.0, 12.5]).unwrap();
std::fs::write("preview/walk.png", walk::picture(&scene, &w, Some(4), 2).png()).unwrap();
assert!(w.sealed.is_empty(), "sealed places: {:?}", w.sealed);
}Decorations with a layout number
A decoration plan of the Creator Kit carries a layout number that starts at 1 (ChunkDecor::with_layout). When you change the plan, raise the number: a chunk built with an older number is cleared of the plan's own pieces and built again once, also on a running server. Pieces of other plans stay, and a chunk with a higher number is not touched. A script can clear one chunk itself with decor::sdk::clear_chunk(world, chunk, tag).