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
    chunksPerFrame: number = 2
    time: number = 0
    blockEntities: BlockEntityStore = ...

    Per-block state (container contents, machine progress, …).

    scheduledTicks: ScheduledTickQueue = ...

    Min-heap of scheduled block ticks, drained in game-tick order.

    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.

    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

    • 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