Log inGet started
World

Builtin Library

Branchmain
Branchesmainpublish
Commit44fd9e59bd

README.md

minecraft

Minecraft-style infinite voxel world. Chunked procedural terrain that auto-streams around the local player as they move. Each chunk builds one merged mesh per block-type so the engine pipeline can apply per-type materials in a single draw per type.

Exports

  • M.generate(opts: GenerateOpts?) -> GenerateResult — set lighting, place the player, initial chunk load at the origin, enable streaming. Use this as the demo entry point.
  • M.loadChunk(cx: number, cz: number) -> ChunkRecord — build and spawn a single chunk.
  • M.unloadChunk(cx: number, cz: number) — despawn the chunk's entities.
  • M.updateChunks(worldX: number, worldZ: number) -> UpdateResult — reconcile loaded chunks against a player position; loads/unloads as needed.
  • M.getLoadedChunkCount() -> number — chunk count.
  • M.clearAll() — unload everything.
  • M.enableStreaming() — register the MinecraftStreamer component and attach it to __player_local. Idempotent.
  • M.config: Config — chunkSize / chunkHeight / viewDistance / waterLevel / treeSpacing / treeMinHeight / treeMaxHeight. Mutate before generate.

Types:

  • Config = { chunkSize: number, chunkHeight: number, viewDistance: number, waterLevel: number, treeSpacing: number, treeMinHeight: number, treeMaxHeight: number }
  • GenerateOpts = { viewDistance: number?, chunkSize: number?, chunkHeight: number? }
  • ChunkRecord = { root: string, children: { string }, faces: number, cx: number, cz: number }
  • UpdateResult = { loaded: number, unloaded: number, totalChunks: number }
  • GenerateResult = { chunks: number, faces: number }

Usage

local mc = require("@builtin::demos.minecraft.minecraft")
mc.generate({ viewDistance = 3 })

-- Per-frame (driven by the auto-attached streamer component):
-- mc.updateChunks(playerX, playerZ)

Notes

  • Terrain noise is a sum of sines (WASM-safe; no bit ops, no allocation).
  • The streamer component runs at 0.5 s intervals and calls updateChunks only when the player crosses into a new chunk — otherwise it's a cheap timer increment.
  • Each chunk uses a parent + per-block-type child layout so a single setParent groups the chunk for unload. Despawning the root despawns the children as well.
  • World coordinates use a left-handed Z (the -(z + ...) flips rendering) — keep this in mind if you mix in entities outside the module.