Orthrus Research
Guide 7 minute read

Reading a cubic world from the client

Cubature's cube source gives client-side renderers a consistent view of loaded cubes, with events once a tick, versions, immutable snapshots with their neighbors, and threads to build on.

Verified 2026-11-17Cubature b1140175Cleanroom 0.7.14-alphaJava 26

orthrus.cc/texts/reading-a-cubic-world-from-the-client

A renderer for a cubic world needs the blocks and light of each 16-block cube, and it needs them in a state that holds still while it builds a mesh. The game's own client data does not hold still: whole-cube packets, small block changes, light updates and removals each arrive on their own schedule, so a renderer that reads the world directly can mesh half of an edit. Cubature's cube source is the contract that closes that gap. It gives a renderer one ordered stream of events, a version for every cube, immutable snapshots for its builds, and threads to run them.12

The source lives in Cubature's public API, package api.client; a renderer reads only those interfaces, never Cubature's internal classes. It replaces hooks written for one renderer at a time with one contract for any renderer.1

Attaching to the source

The source exists on a client whose world is cubic. CubeSource.get() returns it, or null on a dedicated server and before Cubature has initialized. A renderer registers one listener, and every event reaches it on the client thread.1

ICubeSource source = CubeSource.get();
if (source != null) {
    source.setListener(new ICubeSourceListener() {
        @Override public void worldAttached(long worldIdentity) { /* start fresh */ }
        @Override public void worldDetached(long worldIdentity) { /* drop everything */ }
        @Override public void cubeLoaded(int x, int y, int z) { /* queue a build */ }
        @Override public void cubeUnloaded(int x, int y, int z) { /* drop its mesh */ }
        @Override public void cubeChanged(int x, int y, int z, int kinds,
                int minX, int minY, int minZ, int maxX, int maxY, int maxZ) { /* rebuild the bounds */ }
    });
}

The world has an identity that changes when the client world is replaced, by a dimension change or a disconnect. Every snapshot and event belongs to one identity and is void after it. The source also states the world's height range in cubes and whether the dimension has sky light.1

Events and versions

Cubature translates every route by which a cube changes into four events: a cube loaded, a cube unloaded, a cube changed, and the world attached or detached. Events arrive once per client tick, at its end, in the order the changes were applied, and only after the data they describe is readable.12

A change event carries what changed (BLOCKS, LIGHT, BIOMES or NEIGHBOR) and the bounds of the change inside the cube. The bounds are a contract: they always contain every block that changed and may contain more, never less, so a renderer may rebuild exactly the box it is given.3 A change in a cube's outermost layer of blocks, or its arrival or removal, also raises a NEIGHBOR change for each loaded cube that touches it, so faces drawn against a gap are rebuilt when the gap fills.1

Every loaded cube has a version, a number that rises whenever anything a snapshot would capture changes. Versions come from one counter for the whole client world, so a cube that leaves and returns never repeats an old version. The version is split for a renderer that keeps light apart from geometry: blockVersion moves with blocks and biomes, lightVersion with block light and sky light. A mesh whose block version has not moved needs only its light redone.3

An unload is final when it is delivered. By the time cubeUnloaded arrives the cube is gone, so a renderer drops the mesh and nothing brings the cube back unless it arrives again. A renderer that wants to fade a departing cube keeps that mesh on its own side.1

Snapshots

A snapshot is an immutable copy of a cube and the 26 cubes around it, taken on the client thread. For each of the 27 it holds presence, 4,096 block states, block and sky light per block, biomes, the block entity map, and the three versions.12

Four guarantees make a snapshot a safe source for a build. It never changes after it is returned, apart from the live block entity objects it holds, as the game's own chunk cache does. All 27 cubes are captured between two client ticks, so it never shows half of an edit. It can be read from any thread for as long as it is held. It presents the game's block access interface, so existing block models and color handlers run against it unchanged.1

Absent neighbors read as air with implicit sky light, which lets a renderer mesh the edge of what the client holds with an ordinary snapshot; present(dx, dy, dz) says which cubes it holds.4 A reader that needs only the cube itself, such as a mesher of interior faces, takes snapshotCenter instead. Neighbor masks, the light at one block and a light checksum are available as queries without a snapshot.5

Snapshots are cheap to share. A cube is copied once per version, and that copy serves every snapshot that includes it until its version moves, so a cube that sits in 27 neighborhoods is copied once instead of 27 times.1 A renderer releases a snapshot when its build finishes or is cancelled, and holding one never keeps a cube loaded.1

Building on Cubature's threads

A renderer does not need to start threads. buildWork() gives it a pool for work on cube snapshots, such as background meshing:6

IClientBuildWork work = source.buildWork();
Task<Mesh> task = work.submit(priority, x, y, z, false,
        IClientBuildWork.STALE_ON_BLOCKS, (snapshot, t) -> mesh(snapshot, t));
// each frame, on the client thread:
for (Task<?> done; (done = work.poll()) != null; ) { /* take the result */ }

A task waits on the client thread without a snapshot and takes its snapshot only when a thread is ready for it, so a task that waits a long time builds from the cube as it is when it runs. Lower priorities run first, and reprioritizeAll re-sorts every waiting task when the camera moves or turns. A task becomes stale when its cube leaves, or after the changes its staleOn mask names, and a stale task never comes back from poll; the renderer hears the change as an event and submits a new task.6

The pool is bounded. It runs a quarter of the processors' threads by default, between one and four, one step above the lowest priority, and never the common pool. It shares one budget of work permits with the preview pool described below, so the number of jobs running across both is set in one place.67

The held box and the settled signal

The server keeps a box of cubes sent to each player, set by its horizontal and vertical view distances. It now tells the client where that box is: heldBox() returns its center and extents, and the listener hears heldBoxChanged() when the player moves to another cube or a distance changes.8

The settled signal tells a frame capture when to take its picture. It has two parts. First, the server reports that every cube of the box has been sent. Second, quietTicks() counts the client ticks in a row in which no cube arrived, left or changed and the client's light engine had nothing queued. settled(20), one second of quiet after the whole box arrived, is the intended use.9

The signal is narrow on purpose. It says nothing about whether the renderer has built what arrived, which is the renderer's own queue, and nothing about Distant Horizons' distant terrain. Any world in which something changes every tick, such as flowing water, keeps it false, which is why the quiet count is a parameter.9

The terrain preview on the client

A generator can describe any column of its world as vertical runs of block states from the seed alone, without generating a cube. A renderer that draws terrain beyond the loaded cubes can now sample that preview on the client, so the server does no preview work for it.10

When a player joins, the generator sends an offer: a factory name, an identity hash, the seed, the world's generator options and its recorded definitions. The client's factory computes its own identity from those inputs and builds the preview only if the two match, so a client with a different build of the generator draws nothing the server would not generate. A server can keep its seed private with sendSeedForClientPreview off; the identity is then withheld too, because it hashes the seed, and that client builds no preview.10

Sampling runs on previewWork(), Cubature's preview pool, with the same task model as the build pool. One governor sets the permits for both pools. Once a second it reads the last 120 frame times and, in single player, the integrated server's ticks: it halves the permits when the frames' 95th percentile reaches the frame budget (25 ms by default) and adds one when there was demand and the frames have room. Each change is logged with what decided it.71112

The source itself answers a column's ground and liquid surface heights, from loaded cubes or from the preview, and says what a cube holds, so a renderer can place distant ground before any cube arrives.1314

What is not built yet

Two pieces remain design. A client keeps no derived-data directory, so a preview's regional data stays in memory and is rebuilt each session. A server whose seed is withheld cannot yet fall back to sending its own preview tiles.1

Sources

  1. 1 Cubature Cube source
  2. 2 Cubature af1b9da Add the cube source for client-side renderers
  3. 3 Cubature 747de17 Split a cube's version into blocks and light, and state the bounds of a change
  4. 4 Cubature 64bd46b Say that a snapshot serves a cube at the edge of what is loaded
  5. 5 Cubature 4467e91 Read neighbors, one block's light, the center alone and the state limit from the cube source
  6. 6 Cubature 7b1bd62 Give renderers Cubature's threads for building from cube snapshots
  7. 7 Cubature 3ea2664 Let the client pools grow on queued work, and log each permit change
  8. 8 Cubature 99de89f Tell the client which box of cubes the server keeps sent to it
  9. 9 Cubature c87e86c Say when the client's view is settled, for frame captures
  10. 10 Cubature 802bab6 Give a client the generator's terrain preview through the cube source
  11. 11 Cubature 9d66a23 State the terrain preview's threading contract
  12. 12 Cubature a6065ac Give renderers Cubature's own threads for sampling the client terrain preview
  13. 13 Cubature 158b9a0 Answer a chunk column's ground and liquid surface from the cube source
  14. 14 Cubature 6bf47ee Let surface heights skip the preview, say what a cube holds, and find ground that passes light