I'll build a full voxel engine (chunked world in a Web Worker, greedy face-culled meshing, AO lighting, procedural textures, synthesized sounds). Starting with the shared core modules.
Now the chunk mesher with ambient occlusion and per-face lighting:
Now the Web Worker that owns world data, generation and meshing:
Now the main-thread world/chunk manager:
Now the core engine (rendering, physics, controls, interaction):
Now the React UI layer (menu, HUD, hotbar, inventory, debug overlay):
The worker emitted as a separate file won't work with the single-file build — switching to an inlined worker:
A few runtime/perf refinements (streaming throttle, renderer stats, MC-accurate jump, safer pointer lock):
Adding vanilla sneak-edge protection and small UI fixes:
Blockcraft — a Minecraft-style voxel sandbox running entirely in the browser. Build succeeds and everything is inlined into a single HTML file (worker included).
Engine / optimization
src/game/worker.ts — a Web Worker owns the authoritative voxel world: terrain generation and chunk meshing happen off the main thread, with a nearest-chunk-first job queue that time-slices at 12 ms so it never blocks message handling. Mesh buffers are transferred (zero-copy) to the renderer.
src/game/mesher.ts — face-culled meshing (hidden faces never reach the GPU), per-vertex ambient occlusion with diagonal-flip fix, classic Minecraft directional face shading baked into vertex colors, three render layers (opaque / alpha-cutout / water) so leaves and glass work correctly and water renders at 0.875 height.
src/game/world.ts — chunk streaming around the player (throttled to chunk-border crossings), in-flight request cap, geometry disposal on unload, single shared atlas texture + 3 shared materials, frustum culling with static matrices.
- One-entry chunk memo in the sampler, per-chunk
maxY bound so empty sky is never iterated, MeshBasicMaterial (no per-fragment lighting cost).
Feels like Minecraft
- Vanilla-tuned movement: 4.317 walk / 5.612 sprint / 1.31 sneak m/s, gravity 32, ~1.25-block jumps, air control, sprint FOV kick, view bobbing, sneak edge-protection, 0.58 step height, swimming with reduced gravity, double-tap Space to fly, double-tap W / Ctrl to sprint, 120 Hz fixed-step AABB collision.
- Voxel DDA raycast with 5-block reach, black block outline, break/place/pick-block, hand-held block model with swing animation, creative inventory (E), hotbar (1–9 / scroll), F3 debug screen (fps, XYZ, chunk, draw calls, tris).
- Infinite procedural terrain: continents, hills, mountains, biomes (plains/forest/desert/snow), beaches, oceans with water, 3D-noise caves, ore distribution by depth, and trees that seamlessly cross chunk borders.
Assets: zero downloads — all 24 block textures are procedurally painted pixel-by-pixel into a canvas atlas (nearest-filtered, no mipmaps), and every sound (footsteps per material, digging, breaking, placing, landing, splash, glass tinkle) is synthesized live with the Web Audio API.
Files built: src/game/constants.ts, src/game/noise.ts, src/game/mesher.ts, src/game/worldgen.ts, src/game/worker.ts, src/game/textures.ts, src/game/audio.ts, src/game/world.ts, src/game/game.ts, src/App.tsx, index.html, src/vite-env.d.ts