Taos API Reference
    Preparing search index...

    Class BlockWorld

    Streaming voxel world built from Chunks keyed by integer chunk coordinates.

    Chunks are stored in a Map<string, Chunk> keyed by "cx,cy,cz", where chunk coordinates are world coords floor-divided by chunk dimensions. update() generates chunks within renderDistanceH/renderDistanceV of the player and removes ones outside that radius. New chunks are created at most chunksPerFrame per call, sorted by distance to the player. Generation uses a cached 128x128 hydraulic erosion displacement field per region.

    Index

    Constructors

    • Creates an empty world with the given generation seed.

      Parameters

      • seed: number

        master seed for terrain, biome, and erosion noise

      Returns BlockWorld

    Properties

    seed: number
    renderDistanceH: number = 8
    renderDistanceV: number = 4
    verticalChunkBounds: { min: number; max: number } | null = null

    Optional fixed vertical chunk-Y band for loading. When set, chunks load over [min, max] in cy regardless of the camera's height, instead of a ±renderDistanceV window around it — so a finite-height imported world (e.g. the castle, cy 0..12) keeps its full vertical column resident when you fly up above it. null = the default camera-relative vertical window.

    blockLightField: BlockLightField | null = null

    Optional Minecraft-style colored block-light field. When set, the chunk mesher samples it per face and the chunk shader adds a colored ambient term (see block_light.ts) — torches/lamps light surrounding surfaces with no 256-point-light budget. null = feature off (plain block-type verts).

    chunksPerFrame: number = 2
    time: number = 0
    blockEntities: BlockEntityStore = ...

    Per-block state (container contents, machine progress, …). Swapped per dimension by setDimension.

    scheduledTicks: ScheduledTickQueue = ...

    Min-heap of scheduled block ticks, drained in game-tick order. Swapped per dimension by setDimension.

    tickCount: number = 0

    Monotonic game-tick counter advanced by update.

    tickRate: number = 20

    Discrete game ticks per second (Minecraft-style 20).

    randomTicksPerChunk: number = 3

    Random ticks per resident chunk per game tick (crops/grass/etc.).

    randomTickRadius: number = 5

    Chunk radius around the player that receives random ticks.

    onChunkAdded?: (chunk: Chunk, mesh: ChunkMesh) => void
    onChunkUpdated?: (chunk: Chunk, mesh: ChunkMesh) => void
    onChunkRemoved?: (chunk: Chunk) => void
    onBlockSet?: (wx: number, wy: number, wz: number, blockType: number) => void

    Fires after any block is placed via setBlockType. World-space coords.

    onBlockBeforeRemove?: (
        wx: number,
        wy: number,
        wz: number,
        blockType: number,
    ) => void

    Fires before a block is removed via mineBlock. World-space coords.

    chunkGenerator?: (chunk: Chunk, seed: number) => void

    Optional override for terrain generation, so one engine can host multiple worlds (overworld vs. nether/end) with different generators. When set, it fills a freshly-created chunk instead of the default Chunk.generateBlocks.

    dimension: number = 0

    Active dimension id (0 = overworld). Switched via setDimension; the value is opaque to the engine — the game assigns its own ids (see crafty's Dim). Each dimension keeps its own chunk store, block-entities, scheduled ticks, erosion cache, and generator, parked in _dimStates while inactive.

    pendingChunks: number = 0

    Accessors

    • get maxChunks(): number

      Hard cap on the number of resident chunks, derived from the current view range so a larger renderDistanceH/renderDistanceV raises the budget and a smaller one frees memory. Sized for the cylindrical load volume (circular footprint × vertical span) using the +1 removal hysteresis radius, plus a margin so the steady-state set never bumps the cap and stalls loading.

      Returns number

    • get chunkCount(): number

      Number of chunks currently resident in memory.

      Returns number

    Methods

    • Returns the biome at a world-space block position (does not require the chunk to exist).

      Parameters

      • wx: number

        world X

      • wy: number

        world Y

      • wz: number

        world Z

      Returns BiomeType

    • Converts a world-space block position to integer chunk coordinates.

      Parameters

      • wx: number

        world X

      • wy: number

        world Y

      • wz: number

        world Z

      Returns [number, number, number]

      [cx, cy, cz] chunk coordinates

    • Returns the chunk containing the given world-space block position, or undefined if not loaded.

      Parameters

      • wx: number

        world X

      • wy: number

        world Y

      • wz: number

        world Z

      Returns Chunk | undefined

    • Returns true if a chunk exists at the given world-space block position.

      Parameters

      • wx: number

        world X

      • wy: number

        world Y

      • wz: number

        world Z

      Returns boolean

    • Returns the block type at a world-space position, or BlockType.NONE if the chunk is not loaded.

      Parameters

      • wx: number

        world X

      • wy: number

        world Y

      • wz: number

        world Z

      Returns number

    • Sets the block at a world-space position, creating the chunk if needed and re-meshing it.

      Parameters

      • wx: number

        world X

      • wy: number

        world Y

      • wz: number

        world Z

      • blockType: BlockType

        new block type

      Returns boolean

      true on success

    • Returns the Y of the first air block above the highest solid/water block in column (wx, wz).

      Scans downward from maxY. Returns 0 if the column is empty.

      Parameters

      • wx: number

        world X

      • wz: number

        world Z

      • maxY: number

        upper bound to start scanning from

      Returns number

    • Like getTopBlockY, but skips water (and props) so it returns the Y of the first air block above the highest solid (walkable) block. Use this to distinguish dry land from ocean: a column whose top solid surface sits below Chunk.SEA_LEVEL is submerged.

      Returns 0 if the column has no solid block.

      Parameters

      • wx: number
      • wz: number
      • maxY: number

      Returns number

    • Casts a ray through the voxel grid and returns the first non-water block hit.

      Implements the Amanatides & Woo "Fast Voxel Traversal Algorithm for Ray Tracing". Water blocks are skipped (the ray passes through them).

      Parameters

      • from: Vec3

        ray origin in world space

      • dir: Vec3

        ray direction (need not be normalized)

      • maxSteps: number

        maximum number of voxel steps before giving up

      Returns RaycastResult | null

      hit description, or null if no block was hit

    • Places a block adjacent to the hit block on the given face.

      The new block goes at (gX + faceX, gY + faceY, gZ + faceZ). Existing non-air, non-water blocks block placement. Creates the target chunk if needed.

      Parameters

      • gX: number

        hit block world X

      • gY: number

        hit block world Y

      • gZ: number

        hit block world Z

      • faceX: number

        face normal X

      • faceY: number

        face normal Y

      • faceZ: number

        face normal Z

      • blockType: number

        block type to place

      Returns boolean

      true if a block was placed

    • Removes the block at the given world position and re-meshes the affected chunk(s).

      Parameters

      • gX: number

        world X

      • gY: number

        world Y

      • gZ: number

        world Z

      Returns boolean

      true if a block was removed

    • Advances world time, streams chunks around the player, and ticks water flow.

      Parameters

      • playerPos: Vec3

        current player position

      • dt: number

        elapsed time in seconds

      Returns void

    • Advances one discrete game tick: dispatches all scheduled ticks now due, then a random-tick sweep of chunks near the player. Exposed for tests / deterministic stepping; update calls it at tickRate.

      Parameters

      • OptionalplayerPos: Vec3

        center for the random-tick sweep (omit to skip random ticks)

      Returns void

    • Schedules a tick for the block at (wx,wy,wz) delayTicks ticks from now.

      Parameters

      • wx: number
      • wy: number
      • wz: number
      • blockId: number
      • delayTicks: number = 1

      Returns void

    • Returns the block-entity state at a world position, if any.

      Parameters

      • wx: number
      • wy: number
      • wz: number

      Returns BlockEntity | undefined

    • Stores block-entity state at a world position.

      Parameters

      Returns void

    • Removes block-entity state at a world position.

      Parameters

      • wx: number
      • wy: number
      • wz: number

      Returns boolean

    • Notifies the 6 face-adjacent blocks that the block at (wx,wy,wz) changed, dispatching each neighbor's registered handler. Handlers that themselves change blocks cascade through this; a depth guard caps runaway chains (handlers that would propagate far should schedule a tick instead).

      Parameters

      • wx: number
      • wy: number
      • wz: number

      Returns void

    • Removes a chunk from the world, marks it deleted, and notifies listeners.

      Parameters

      • chunk: Chunk

        chunk to delete

      Returns void

    • Switches the world to another dimension, parking the current dimension's full state (chunks, block-entities, scheduled ticks, erosion cache, generator) and restoring the target's. The active world object is unchanged, so every system holding a reference keeps working — only the underlying stores swap. Chunk meshes are detached from / re-attached to the renderer via onChunkRemoved/onChunkAdded; the next update streams any not-yet-generated chunks around the player.

      Parameters

      • dim: number

        target dimension id (the game's own numbering; 0 = overworld).

      • Optionalgenerator: (chunk: Chunk, seed: number) => void

        terrain generator for the target if it's being entered for the first time. Omit for the default overworld generation.

      Returns void

    • Computes a discrete water depth value at the given world position.

      Walks upward through stacked chunks of water and accumulates a per-chunk level contribution based on the height of the water column.

      Parameters

      • wx: number

        world X

      • wy: number

        world Y

      • wz: number

        world Z

      Returns number

      aggregate water level (0 if not in water)

    • Returns the cached hydraulic-erosion displacement at world XZ.

      Looks up (and lazily generates) the 128x128 region containing (gx, gz).

      Parameters

      • gx: number

        world X

      • gz: number

        world Z

      Returns number

    • Re-mesh every resident chunk. Used when a global meshing input changes at runtime (e.g. toggling blockLightField) so the change takes effect without reloading. Fires onChunkUpdated per chunk.

      Returns void

    • Opt in to off-thread chunk meshing: spins up (lazily) a ChunkMeshPool so generateVertices runs on workers instead of blocking the frame while chunks stream in. Safe to call more than once. If workers can't start the pool reports ChunkMeshPool.unavailable and meshing stays inline.

      Returns void