World generation

Vanillite generates new worlds itself. It is built to match Vanilla: the same seed should give the same world, block for block. In rare cases a few blocks differ (Known limits). This is the generator players walk in: chunks are generated in the background as players explore.

Compiled density functions

Vanilla's terrain is described by a large tree of math formulas, the density functions. They decide for each point whether it is stone or air. Vanilla walks through this tree again and again.

Vanillite reads the same formulas from the data packs and turns the tree into a flat program once, when the world loads. A small interpreter then runs this program over whole blocks of space at once. Where a formula picks one of two branches, only the points that need a branch compute it. Custom data packs still work, because the program is built from whatever the data packs say.

The pointwise parts of the program (adding, multiplying, clamping, squeezing, picking a range) are compiled into fused loops: one tight loop does all those steps for a point instead of one pass over the block per step. The loops for the shapes that Vanilla's own world settings use are generated when Vanillite is built. Everything else, such as the formulas of a custom data pack, still runs in the interpreter. The results are identical; the tests compare both paths. VANILLITE_DENSITY_KERNELS=off switches the compiled loops off.

The program also knows, for each area, the smallest and largest value a formula can give. Where that proves a point is empty air (or that an ore vein places nothing), the point is not calculated at all. Neighbouring chunks share the underground water levels they both need instead of working them out twice, and the generator keeps the last few cells it worked out instead of building them again whenever a cell crosses a grid line. Structures add their shape to the terrain only in the cells they reach. The result is unchanged; only calculations that cannot change it are skipped.

Caves and canyons reach into many chunks. Vanillite works out the shapes one chunk cuts only once and keeps them (a carver plan); every neighbouring chunk then only applies the shapes that reach it, instead of running the whole cave search again.

The rules for surface blocks (grass, sand, snow…) are simplified once per chunk: conditions that are the same for the whole chunk are decided up front, so most blocks skip them. Blocks so deep in stone that every "how deep below the surface" condition is false use a shorter version of the rules for their height instead of walking the whole tree; a column's stone run below the surface is handled in one loop, and a run of the same block (the deepslate) is written in one go. The biome lookup also skips neighbour points that cannot be the closest one.

The noise itself (Perlin noise, the base of the formulas) is computed for four columns at once in SIMD lanes (the CPU does four additions or multiplications with one instruction), with the same operation order as the scalar code. Ore veins find each row of their blob as one interval, and leaves and waterlogging are read from small tables instead of by name.

To stay as exact as possible, Vanillite does every calculation in the same order and with the same number precision as Vanilla. The code never uses fused multiply-add instructions (Java does not either), and a generation job resets the CPU's floating-point mode if a native library changed it. The noise also gives the same result on CPUs without AVX2.

One thing cannot be matched bit for bit: Java's Math.sin and Math.cos (a CPU shortcut of the Java runtime) and the platform's maths library differ by 1 ulp for about 0.23 % of angles, and matching it would need GPL code, which the Apache 2.0 licence rules out. So a few blocks can differ in rare cases, for example one iceberg in a large_biomes seed (24 blocks in 3 chunks). See Known limits.

In progress: the inner loops of the generator are being reworked step by step: terrain worked out in regions on dense buffers, surface rules prepared per biome, features on dense buffers, light on a dense grid. The goal is an estimated 1.4–1.8× more chunks per CPU core, with the world unchanged. Each step is checked against the Vanilla goldens before it lands. The steps so far: generation and light reuse their work buffers from job to job (see Memory and startup), ore veins and light are cheaper (together 3.9 % fewer CPU instructions in the developers' own check), the expensive corner values of the terrain at a chunk border are worked out once for both neighbouring chunks instead of once for each, the compiled loops described above, and chunks that are still being generated keep their blocks as plain arrays (one per 16-block section) from the terrain until the chunk is complete, instead of packing them into palettes after every step (another 4.9 % fewer instructions in the developers' own check). Features and light read and write these arrays directly, and the chunk is packed once, when it is complete or saved. At most 256 such chunks per world exist at a time. The early steps gain much less than the goal. There is no measured gain of the rework on the benchmark server yet; measured numbers will appear on Chunks.

Self-check. If a world ever shows wrong terrain, for example a vertical wall at a chunk border, the cause may be state shared between generation jobs. A test builds many chunks on six threads in a scattered order and compares each with the chunk built alone. For a running server, the environment variable VANILLITE_VERIFY_TERRAIN=<n> builds every n-th terrain job a second time on its own and logs an error with the chunk and the number of blocks that differ. It is off by default and meant for finding such a case.

Batches

The generator takes many chunks per call, not one. Setup work is shared across the batch, and any number of worker threads can generate chunks at the same time. Every chunk depends only on the seed and its position, so the result does not depend on how the work is split.

Generation steps

Step What it makes Status
Biomes Which biome is where. Built
Terrain Hills, mountains, oceans, caves, aquifers (underground water and lava), surface blocks, bedrock, ore veins. Built
Structures All structures of Minecraft 26.3: villages, outposts, strongholds, mineshafts, ancient cities, trial chambers, temples, mansions, monuments, shipwrecks, ruins, nether fortresses, bastions, end cities and more, with their chests and other block data. Built
Features Trees, plants, ores, lakes, geodes, ice, coral and the other decorations. Built
Light Sky and block light. Built (see below)

Features follow Vanilla's own rules for how blocks connect and survive (a plant only stays where it can grow), so the result is meant to match Vanilla block for block. generate-structures=false in server.properties turns structures off, like on Vanilla.

Decoration order. A feature can reach into the chunks around it, so the order in which neighbouring chunks are decorated changes trees and leaf litter at chunk borders. Vanilla decorates the chunks that must become full first (by their ticket level), then by position, and a chunk waits for the earlier chunks next to it. Vanillite follows the same order when the rule performance.chunks.vanilla-feature-order is on. That is the case in the vanilla and technical profiles. It costs a fifth to a third of the generation speed, because chunks wait for their neighbours (measured by the developers on 1 and 4 threads). The paper, spigot and performance profiles switch it off: chunks are then decorated as soon as their neighbours are ready. Which order Vanilla uses also depends on when players load chunks, so Vanilla itself differs between runs there. See Performance settings.

Flat worlds use Vanilla's flat generator too: their layers, the biome's decorations (lakes, for example) and the villages and strongholds of the flat presets. Chunks of flat worlds do not spawn animals while they are generated, like on Vanilla.

The built steps are compared with Vanilla chunk by chunk (see How parity is tested), also in a nightly sweep over many seeds in every world type. The biomes, formulas, features and structures come from Vanilla's own data pack (see Data and version updates). Speed numbers for world generation: Chunks.

Structure templates (the block layouts of villages, ruins and so on) are loaded only when a structure needs them and are shared by world generation, structure blocks and commands. A server without players frees the generator's tables and builds them again when someone logs in (Memory and startup).

Light

Light is computed for each chunk the same way Vanilla's final light looks. Neighbouring chunks are lit in parallel: each chunk's light is worked out on its own and the results are combined, so no chunk has to wait for another. Light is only computed up to just above the highest blocks of an area; everything above is full sky light anyway. Like Vanilla, light is also kept in the sections just below and above the world's height limits, where Vanilla keeps it.

When blocks change later (a torch, a roof, flowing water), Vanillite does not light the whole area again. It works like Vanilla's own light engine: starting from the changed blocks, it first takes light away where a source went (a queue of cells to darken) and then spreads light again from the cells that are still lit (a second queue). Only the cells the change reaches are touched. In the developers' own check this is 4 to 9 times faster than working out a whole box around every change, and the light values are identical to a full recompute. Only a few rare cases (sky light that was filled below the world, a change that may empty or fill the lowest or highest section) still use the box. Changes of several chunks are worked out together in one background job (performance.simulation.max-relights-per-tick, see Performance settings).

The result is checked against Vanilla: for newly generated chunks, in recorded scenarios where blocks change (light sources, roofs, caves, flowing water, the height limits), and in a nightly light sweep over many seeds, every world type and many block changes, including chunks that unload and load again.

See also: Replaceable systems (world generation and lighting are slots).

Next: Memory and startup.