Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Terrain

cinnabar:extension/terrain@0.1.0

Bounded local terrain reads. The queries a callback reads become its subscriptions, which the client samples before later frames, so a new query reads pending first. A deferred callback keeps its subscriptions. Unknown terrain is never reported as air.

Grants: terrain.

Types

position

An integer block position in the current dimension.

record position {
    x: s32,
    y: s32,
    z: s32,
}
MemberTypeDescription
xs32
ys32
zs32

geometry

Selects which block shapes to request; an empty set requests neither family.

flags geometry {
    collision,
    selection,
}
MemberTypeDescription
collision
selection

region-query

Inclusive minimum and exclusive maximum; each extent is 1 to MAX_TERRAIN_EXTENT blocks.

record region-query {
    min: position,
    max: position,
    geometry: geometry,
}
MemberTypeDescription
minposition
maxposition
geometrygeometry

Types: geometry, position.

stamp

Identifies one sample of one query; an equal stamp means identical contents.

record stamp {
    session: u64,
    dimension: s32,
    registry: u64,
    revision: u64,
}
MemberTypeDescription
sessionu64
dimensions32
registryu64
revisionu64

physics-flags

Available block contact properties; missing physics remains absent on the block state.

flags physics-flags {
    climbable,
    water,
    lava,
    cobweb,
    powder-snow,
    scaffolding,
    passable,
}
MemberTypeDescription
climbable
water
lava
cobweb
powder-snow
scaffolding
passable

surface-response

The resolved contact response associated with the block’s physics.

enum surface-response {
    none,
    slime,
    bed,
    honey,
    soul-sand,
    bubble-up,
    bubble-down,
}
MemberTypeDescription
none
slime
bed
honey
soul-sand
bubble-up
bubble-down

physics

Resolved movement and fluid properties, when the registry supplies them.

record physics {
    friction: f64,
    horizontal-speed-factor: f64,
    vertical-speed-factor: f64,
    fluid-height: f64,
    %flags: physics-flags,
    surface: surface-response,
}
MemberTypeDescription
frictionf64
horizontal-speed-factorf64
vertical-speed-factorf64
fluid-heightf64
flagsphysics-flags
surfacesurface-response

Types: physics-flags, surface-response.

resolved-shape

An index into the region’s shapes; shape 0 is known-empty.

variant resolved-shape {
    unavailable,
    known(u32),
}
MemberTypeDescription
unavailable
knownu32

shape-binding

Distinguishes unrequested, shared and position-dependent geometry without guessing boxes.

variant shape-binding {
    not-requested,
    fixed(resolved-shape),
    per-cell,
}
MemberTypeDescription
not-requested
fixedresolved-shape
per-cellEvery occurrence has an override.

Types: resolved-shape.

block-state

One distinct runtime ID; metadata and physics are absent when the registry lacks them.

record block-state {
    runtime-id: u32,
    identifier: option<string>,
    canonical-state: option<string>,
    tags: list<string>,
    physics: option<physics>,
    collision: shape-binding,
    selection: shape-binding,
}
MemberTypeDescription
runtime-idu32
identifieroption<string>
canonical-stateoption<string>
tagslist<string>
physicsoption<physics>
collisionshape-binding
selectionshape-binding

Types: physics, shape-binding.

chunk-revision

Revision of a column the region depends on; none is absent terrain.

record chunk-revision {
    x: s32,
    z: s32,
    revision: option<u64>,
}
MemberTypeDescription
xs32
zs32
revisionoption<u64>

shape-override

Geometry of one layer slot that depends on its position; none keeps the state’s binding.

record shape-override {
    slot: u32,
    collision: option<resolved-shape>,
    selection: option<resolved-shape>,
}
MemberTypeDescription
slotu32
collisionoption<resolved-shape>
selectionoption<resolved-shape>

Types: resolved-shape.

region

Cell ((x * size-z) + z) * size-y + y, relative to the minimum, has layer l at slot l * cells + cell. Shapes are block-local, with native position offsets applied.

record region {
    stamp: stamp,
    chunks: list<chunk-revision>,
    layer-count: u8,
    loaded: list<u64>,
    states: list<u16>,
    palette: list<block-state>,
    shape-offsets: list<u32>,
    shape-boxes: list<f64>,
    overrides: list<shape-override>,
}
MemberTypeDescription
stampstamp
chunkslist<chunk-revision>Every column read, including those consulted for neighbour or actor geometry.
layer-countu8
loadedlist<u64>Bit cell % 64 of word cell / 64 is set for known cells.
stateslist<u16>Palette index per slot; 65535 is no layer, never air.
palettelist<block-state>
shape-offsetslist<u32>Shape s is boxes shape-offsets[s] to shape-offsets[s + 1].
shape-boxeslist<f64>Six values per box: minimum then maximum x, y and z.
overrideslist<shape-override>Sorted by slot.

Types: block-state, chunk-revision, shape-override, stamp.

read-result

A deferred sample, an unchanged stamp or a complete changed region.

variant read-result {
    pending,
    unchanged(stamp),
    changed(region),
}
MemberTypeDescription
pending
unchangedstamp
changedregion

Types: region, stamp.

read-error

Admission or availability failures; shrink a query when its response exceeds a limit.

enum read-error {
    denied,
    unavailable,
    invalid-query,
    out-of-range,
    budget-exhausted,
    limit-exceeded,
}
MemberTypeDescription
denied
unavailable
invalid-query
out-of-range
budget-exhausted
limit-exceeded

Functions

read-region

read-region: func(query: region-query, after: option<stamp>) -> result<read-result, read-error>;

Requires terrain authority and a gameplay frame; the query lies within MAX_TERRAIN_DISTANCE blocks of the player’s feet on each axis. Pass the stamp last received for this query to skip unchanged data. Limits are mod-api’s MAX_TERRAIN_* constants.

Types: read-error, read-result, region-query, stamp.

find-blocks

find-blocks: func(identifiers: list<string>, range: f32, limit: u32) -> result<list<position>, read-error>;

Positions of loaded blocks whose identifier matches one of 1 to MAX_FOUND_BLOCK_IDENTIFIERS namespaced names, nearest first, within range blocks of the player’s feet (1 to MAX_TERRAIN_DISTANCE) and at most limit results (1 to MAX_FOUND_BLOCKS). Like a region query, a search becomes a subscription that the client scans incrementally between frames, so a new search returns none and results fill in as loaded terrain is scanned. Searches and region queries share MAX_TERRAIN_QUERIES and the callback’s terrain call budget. Requires terrain authority and a gameplay frame.

Types: position, read-error.