# Live view

> How Minekube shows a Minecraft world in a browser - a real client runs a camera bundle that writes a world stream, and a WebGPU renderer draws it with the textures and models of the real game, fetched from Mojang by the browser itself.

A game is easier to judge when you can see it. The live view shows what a Minecraft client sees in a browser tab: the real world, with the game's own block models, textures, light, sky, weather and entities. Nobody needs Minecraft installed to watch.

> **Preview:**
> Watching a client works today, locally and through a relay. Playing in the browser, replay in the browser and a producer on the server are planned.

## How it works

```text
Paper server ──packets──▶ Minecraft client with the camera bundle
                                    │  world stream: a snapshot, then changes per tick
                                    ▼
                          Minekube daemon  ──▶  browser (local)
                                    │
                               mk share  ──▶  relay  ──▶  browsers anywhere
```

1. **A real client is the camera.** A Minecraft client with the Minekube client runtime runs the camera bundle, an Effect TS bundle in `packages/view/camera/`. The real game has already decoded every packet, computed light and biome tints and built each entity's model. The camera reads those results through the client's own API and writes them as the world stream.
2. **The world stream is its own format.** It is one JSON frame per line, defined with Effect Schema in `packages/view/src/World.ts`, not the Minecraft protocol. Block states travel as names, such as `Block{minecraft:oak_stairs}[facing=north,…]`, so the browser needs no block tables per version.
3. **The browser fetches the game's assets itself.** It downloads the client jar of the server's version straight from Mojang, checks it against Mojang's SHA-1 and keeps it in the browser's cache. Minekube hosts no Minecraft assets.
4. **A WebGPU renderer draws it.** The renderer in `packages/view` ports the client's own shaders and baking rules: smooth light and ambient occlusion, tints, animated textures, fluids, sky, clouds, weather, particles and entities. Sections are meshed in a pool of web workers.

## What the stream carries

| Frame | Carries |
| --- | --- |
| `Hello` | The Minecraft version, the dimension and its height, again on every change of dimension |
| `States` | New block states, numbered, with the facts that light and ambient occlusion need |
| `Section` | One 16 by 16 by 16 section: block states, visible faces, sky and block light, tints |
| `Unload` | A section the client left |
| `View` | The camera's position, direction and matrices, when they change |
| `Look` | Light map, fog, sky and clouds, when they change a visible pixel |
| `Tick` | Game time and time of day, once per second and when the tick rate changes |
| `Weather`, `Particles` | Rain and snow columns, and the particles the client draws |
| `Models`, `Entities` | Entity models once, then the entities that changed in each tick |

When nothing moves and no block light is in view, the stream sends only the `Tick` frame once per second.

## Why a real client

There are three ways to show Minecraft in a browser: rebuild the client in JavaScript, stream the real client as video, or run the real client without a picture and draw its world in the browser. Minekube takes the third way:

- **It is exact.** The real game speaks the protocol, simulates and lights the world. The browser draws what the client computed.
- **It needs no GPU on the server.** The client does not render for the browser, and there is no video encoder.
- **It is sharp.** The browser draws at the screen's resolution, instead of showing a compressed video.

Watching is playing without inputs, so the same path leads to playing in the browser.

## How it stays correct

Each part is checked against the real client. A test makes the client write the quads it bakes for every block state and compares them with the browser's. Other tests place blocks, fluids, entities and weather in front of a client, take a screenshot in the client and a picture in the browser, and compare them pixel by pixel. The results are on [Performance](https://minekube.com/games/platform/performance#live-view).

When Mojang ships a new version, the browser reads blocks, models, textures and animations from the new jar at run time. What only the game's code knows, the client computes and sends.

## Limits

- The browser needs WebGPU. There is no WebGL fallback.
- One camera client runs per watched player, not per viewer.
- Through the relay, anyone with the link can watch. Streams are named by the client's name.

## What is planned

| Planned | What it adds |
| --- | --- |
| Playing in the browser | The browser sends keys, view, clicks, hotbar and chat to a client that does not render. Hotbar, chat and inventory are Effect UI components. |
| A world track in recordings | The world stream next to the message log, on the same tick clock. |
| Replay in the browser | A timeline over a recorded match. See [Recordings and replay](https://minekube.com/games/testing/recordings#what-is-planned). |
| A producer on the server | The Paper runtime writes the stream itself, without a client process, for many games at once. |

## Related

- [Watch and share a world](https://minekube.com/games/local-development/watch-and-share): open the live view and share it.
- [Browser wall example](https://minekube.com/games/examples/browser-wall): the opposite direction, a web page shown on maps in the game.
