worldgen library

Declarative world generation on package:voxel_engine/core.dart: noise, terrain recipes, biomes, caves, ores, trees and structures, as a ChunkGenerator.

Classes

Biome
One biome: what covers the ground, what grows on it, what falls on it.
Camp
A tent pitched on the ground: a ridge of cloth 7 long along x over a floor 5 wide, its four corner poles down to their own ground, a chest inside and a light six blocks off on a pole of its own.
CaveCarver
Caves carved out of the ground by two 3D noises: cheese caves anywhere in the rock, wider caverns in the deep, and cave mouths near the surface only where the cave noise runs strong. Pure in the position, so a tree or a structure can ask about a cell of another chunk.
CavernSpec
A world that is one great cave: a slab of the world's stone between a floor and a roof of its bedrock, opened by 3D noise into caverns, the world's sea (its water, lava in an underworld) filling every open cell up to its seaLevel.
CaveSpec
The caves of a world.
ChunkWriter
One chunk's block array, written in world coordinates. Everything outside the chunk is silently skipped, which is the point: a feature (a tree, a village) is drawn whole by every chunk it touches, and each keeps its own part, so the pieces meet at the borders without any chunk seeing another.
Climate
A window of climate a biome claims. Temperature and humidity are noise in -1..1 (temperature drops with altitude); height is the surface height.
Cover
A biome's surface block where the ground stands in a window of height and a roll hits: snow above a height, patches of mud.
CustomStructure
A game's own structure, drawn by a function.
DimensionGenerator
A world of several dimensions, one WorldGenSpec each, compiled for one seed: the ChunkGenerator the worker isolates run, handing each chunk to the generator of the dimension it is asked for. Dimension d is specs[d]; the first is the world a game starts in.
Dungeon
Three rooms in a row under the ground, joined by corridors, a ladder shaft up from the first: two guard rooms with a spawner each, and a larger last room with the chest, a relic and a treasure block. Every wall, floor and ceiling is walls, one brick in four mossy; two lights a room. The rooms lie along x, the site in the middle one, depth to depth + 13 blocks under the surface (never under y 8). Where each part lies is its DungeonPlan, which a game reads too.
DungeonPlan
Where the parts of a Dungeon lie, in world cells: its floor rolled from its site, its three rooms along x, the spawners of the two guard rooms and the last room's chest. The dungeon draws from it, and a game finds the same cells by it without reading the world.
FastNoiseLite Noise
A web-safe port of FastNoiseLite covering the OpenSimplex2, OpenSimplex2S, Perlin, Value, and Cellular noise types with None/FBm/Ridged/PingPong fractal layering, plus domain warp (domainWarp2/domainWarp3).
Flats
Low ground pressed flat, as a swamp's is: a column standing from one to reach blocks over the sea is pressed toward height over it, keeping keep of its rise past that, wherever the biome declaring it is the one the column would then grow. The hills by a swamp stay hills, and a desert tried before it keeps its own ground.
Mine
An abandoned mine: a head frame on the surface (frame floor, four posts, a roof) over a ladder shaft down to a corridor at floorY, three wide and three high, running minLength to maxLength blocks along +x. Every fourth block a support of beams under the roof block, a pair of lights on every second one; a rail down the middle to the chest at the end, a spawner before it a third of the time. Where the corridor's shell meets air or a liquid it is sealed with walls; where it meets the world's rock, veins show through it, each in its per cent of the cells. Where its corridor, chest and spawner lie is its MinePlan, which a game reads too.
MinePlan
Where the parts of a Mine lie, in world cells: its corridor at floor, running length blocks along +x from beside its site, the chest at its end and the spawner three before it, the one mine in three that has one. The mine draws from it, and a game finds the same cells by it without reading the world.
Ore
An ore of a world.
OreTable
Ores by depth. A cell of 2 x 2 x 2 blocks rolls one vein, and a per-block roll thins it to fill per cent, so ore comes in clumps rather than specks.
OreVein
One ore of an OreTable.
Plant
A small plant on a biome's surface.
Plaza
A square of open-sky ground pressed flat: columns x in [minX, maxX) and z in [minZ, maxZ) stand at height (the first air cell, as SpecGenerator.surfaceHeight answers), wear the land biome named biome and carve no caves; the ground outside eases back to its own height over blend blocks. No tree, plant or cave comes within clearing blocks of it, and no structure's site within structureClearing (a structure reaches out from its site). The spec throws for one in a cavern or one naming a biome that is not among its land biomes.
Pools
Shallow pools: one block of the world's water over bed, wherever noise runs over threshold on land above the sea and the four neighbours stand no lower, so the water stays where it is.
Ruins
What is left of a 7 x 7 house: a cracked floor laid in the ground, the ground showing through one cell in four, broken walls two to four high with gaps (one brick in five mossy), one or two plants grown on the wall tops, and a chest half the time.
ScatterGrid
At most one feature per patch x patch square, placed by hash, never closer than inset to the square's border. Two features of one grid therefore stand at least 2 * inset + 1 blocks apart, and every chunk agrees where each one is from the position alone.
SpecGenerator
A WorldGenSpec compiled for one seed against one game's block ids: the ChunkGenerator the worker isolates run, and the queries a game asks of its terrain (a spawn point, the biome under the player, the structures on the map). Pure in (seed, position), so every isolate agrees.
Stratum
The rock of a world below a height: dark stone in the deep.
Structure
What a structure is: how far it reaches, how deep it sits, the blocks it uses, and how it is drawn around a StructureSite. A StructureSpec places one in the world; the stock ones (Dungeon, Tower, Well, Camp, Ruins, Mine, Village, Temple) take their blocks by name, and a game's own is a CustomStructure or a subclass.
StructureGrid
One structure candidate per region of regionChunks x regionChunks chunks, rolled from the region's hash, so every chunk agrees where it is. A chunk asks the 3 x 3 regions around it, because a structure near a region border reaches into its neighbours.
StructureSite
What a Structure draws with: a site in the world and the chunk being generated. Coordinates are relative to the site (x, y, z) — the surface, or depth under it — and every write outside the chunk is dropped, so the builder draws the whole structure every time and each chunk keeps its own part.
StructureSpec
A structure of a world: at most one per region of regionChunks square, in chance of the regions, on the land biomes named in biomes (any land when null), its structure built around a site on the surface (or its depth under it).
Temple
A desert temple: a step pyramid of stone, 9 x 9 at its base and five steps of two blocks, over a 3 x 3 x 3 chamber reached by a corridor from the south (+z). In the chamber two chests stand against the north wall under a light, and a plate in the middle of its floor sits on a trap (TNT: the plate powers it). Every furnishing left null is left out.
TerrainRecipe
How high the ground stands: a continental land mask between lowland and highland, rolling hills, ridged mountains inland and rivers carved to just under the sea.
Tower
A square watchtower, 5 x 5 and height tall, on a foundation down to its ground: a door on its +z side, windows every third row, a ladder up the inside to a floor under the top, a chest and a light up there, and battlements. One brick in five is mossy.
TreeBlocks
The blocks a tree is drawn with.
TreeCanvas
A scratch volume a tree is drawn on before it is printed into a chunk.
Trees
Tree shapes drawn on a TreeCanvas at the stump (x, y, z), where y is the first air cell above the ground. hsh is the tree's own roll (a scatter grid's spot hash), so the same tree is drawn in every chunk.
TreeSpec
A tree a biome grows.
Village
A clearing with minHuts to maxHuts huts on a ring around a well, each hut sat on its own ground with its door to the well and a path from the door to it, and a fenced farm off to one side.
VillageFarm
A village's field: 9 x 7, fenced, crop on tilled soil in rows either side of a channel of the village's water, its ground soil, a gate on the side towards the village and a torch on the post beside it.
Well
A village well on its own: a 3 x 3 rim standing a block over the ground around water deep blocks deep, two posts and a roof.
WorldGenSpec
A whole world described as data: its terrain, biomes, ores, caves and structures, with blocks named by string. compile turns it into a ChunkGenerator against a game's block ids.

Enums

CellularDistanceFunction Noise
How distance to a cell point is measured by NoiseType.cellular.
CellularReturnType Noise
What value NoiseType.cellular computes for a query point.
DomainWarpFractalType Noise
How successive domain warp octaves are combined.
DomainWarpType Noise
The warp algorithm applied by FastNoiseLite.domainWarp2 and FastNoiseLite.domainWarp3.
FractalType Noise
How successive noise octaves are combined.
NoiseType Noise
The base noise algorithm used by FastNoiseLite.
Precipitation
What falls from a biome's sky when the weather turns: Minecraft's own three. A game reads it; the generator does not.
TreeShape
The tree shapes of Trees.

Functions

floorDiv(int a, int b) → int
a divided by b, rounded toward negative infinity: the region or patch a coordinate falls in, negative coordinates included.
noiseHash2(int seed, int x, int y) → int Noise
Bit-exact hashed value for the integer lattice cell (x, y).
noiseHash3(int seed, int x, int y, int z) → int Noise
Bit-exact hashed value for the integer lattice cell (x, y, z).
simplexNoise(int seed, double frequency, int octaves, [FractalType fractal = FractalType.fbm]) → FastNoiseLite
OpenSimplex2S noise with octaves of fractal at frequency: the layer every height, climate and cave field here is built from.
smoothstep(double a, double b, double t) → double
0 below a, 1 above b, and a smooth S-curve between.
worldHash(int seed, int x, int y, int z) → int
A 32-bit hash of a world position under seed: the same cell gives the same number on every chunk, isolate and run, which is what lets two chunks agree on a tree or a structure that crosses their border. Features salt y (or scale x and z by primes) to draw independent rolls from one position.

Typedefs

DungeonRoom = ({IVec3 centre, int half})
One room of a DungeonPlan: its walls stand half blocks from its centre along x and z, its ceiling half over its floor.
PlacedStructure = ({String name, int x, int y, int z})
A structure placed in the world: what SpecGenerator.structuresNear answers.
StructureBuild = void Function(StructureSite site)
Draws one structure into one chunk.