Mods: world queries for simulations (render.query-rays, query-sections, world-changes; API level 12): block-exact rays and section occupancy by collision, sight or sound, answered next tick within budgets, and a log of changed sections

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-29 21:43:22 +03:00
committed by airdef
parent a8235704e4
commit f87d2c518f
10 changed files with 951 additions and 6 deletions
+79
View File
@@ -501,6 +501,80 @@ Particles to spawn on this client (AirDef fork).
| `color` | `u32` | 0xRRGGBB for dust and coloured types (0: white). |
| `scale` | `f32` | Dust size (0.01 to 4). |
### enum `policy`
What a block is to a query (AirDef fork): the three policies differ on purpose, so a sensor and a missile may disagree about a pane of glass.
| Case | |
| --- | --- |
| `collision` | Projectile collision: every block with a collision shape stops it (stone, leaves, glass, slabs, fences); air, fluids, plants and other shapeless blocks let it pass. |
| `sight` | Sensor line of sight: opaque blocks (those that stop light) only; glass, leaves and fluids are seen through. |
| `sound` | Sound occlusion: blocks with a full-cube collision shape. |
### enum `verdict`
How a query ended. Never `clear` for a chunk that isn't loaded.
| Case | |
| --- | --- |
| `clear` | Nothing on the way, everything checked. |
| `hit` | A block stops it; see the other fields. |
| `unknown` | A part of the way is in a chunk the game doesn't have (far terrain, not yet loaded) or the budget ran out: no verdict. A `hit` found before the unknown part still comes back as `hit`. |
### record `ray`
A segment to trace through the loaded blocks.
| Field | Type | |
| --- | --- | --- |
| `id` | `u32` | Echoed in the answer. |
| `start` | `tuple<f64, f64, f64>` | |
| `end` | `tuple<f64, f64, f64>` | |
| `policy` | `policy` | |
### record `ray-answer`
| Field | Type | |
| --- | --- | --- |
| `id` | `u32` | |
| `verdict` | `verdict` | |
| `fraction` | `f64` | For a `hit`: how far along the segment, 0 to 1, where it enters the shape. |
| `normal` | `tuple<s32, s32, s32>` | For a `hit`: the face normal (the axis it entered along). |
| `block` | `tuple<s32, s32, s32>` | For a `hit`: the block hit. |
| `known-to` | `f64` | For an `unknown`: how far along the segment the unknown part begins. |
### enum `section-fill`
What a 16 x 16 x 16 section of the world holds, for a policy.
| Case | |
| --- | --- |
| `unknown` | The game has no such chunk loaded: nothing is known. |
| `empty` | Nothing in it stops a query. |
| `full` | Every block in it does. |
| `mixed` | Some do: `bits` tells which. |
### record `section`
| Field | Type | |
| --- | --- | --- |
| `x` | `s32` | Section coordinates: block x, y, z divided by 16, rounded down. |
| `y` | `s32` | |
| `z` | `s32` | |
| `fill` | `section-fill` | |
| `bits` | `list<u8>` | For `mixed`: 512 bytes, one bit per block, set where it stops the policy's query. The index is (y & 15) * 256 + (z & 15) * 16 + (x & 15); bit i is bit (i & 7) of byte i / 8. Empty otherwise. |
### record `changes`
Changes to the world since the last tick, for a mod's cache.
| Field | Type | |
| --- | --- | --- |
| `epoch` | `u32` | A number that changes when another world or dimension opens: everything cached before is void. |
| `revision` | `u64` | Counts block changes in the loaded world, ever (wraps). |
| `overflow` | `bool` | More sections changed than fit: treat everything as changed. |
| `sections` | `list<tuple<s32, s32, s32>>` | Sections (as in `section`) where a block changed, at most 256. |
### record `camera-view`
A camera the game renders the world from besides the player's eye (AirDef fork): the land, the sky and the entities near the player.
@@ -561,6 +635,11 @@ The HD lighting (AirDef fork): the world lit per pixel by the mods' lights, in h
| `play-sound` | `func(event: string, x: f64, y: f64, z: f64, volume: f32, pitch: f32)` | Plays a sound event (`minecraft:entity.generic.explode`, `<mod>:<name>`) at a point on this client. |
| `query-ground` | `func(columns: list<tuple<s32, s32>>)` | Asks for the ground height of these columns (x, z): at most 512 a tick, answered by `ground` from the next tick on. |
| `ground` | `func() -> list<tuple<s32, s32, s32>>` | The answers to the last tick's `query-ground`: (x, z, y), y one above the highest block that blocks motion or holds a fluid, as the motion blocking heightmap; -64 where the chunk isn't loaded. |
| `query-rays` | `func(rays: list<ray>)` | Traces segments through the loaded blocks (AirDef fork): each is walked block by block on the host, against the real collision shapes (`policy`), and answered by `rays` from the next tick on. At most 256 segments a tick, each at most 512 blocks long (longer ones are answered `unknown` past that); over the budget they are answered `unknown` too, never `clear`. A game with no chunk at a place answers `unknown` for it. |
| `rays` | `func() -> list<ray-answer>` | The answers to the last tick's `query-rays`, in the order asked. |
| `query-sections` | `func(policy: policy, sections: list<tuple<s32, s32, s32>>)` | Asks what these sections hold (AirDef fork), for a mod that traces its own paths against a cache of them: at most 64 a tick, answered by `sections` from the next tick on. Over the budget they are not answered: ask again. |
| `sections` | `func() -> list<section>` | The answers to the last tick's `query-sections`. |
| `world-changes` | `func() -> changes` | The block changes of the last tick (placed, broken, exploded) and the world's epoch. Only changes in chunks the game has loaded. |
| `set-post` | `func(wgsl: string)` | A full-screen post pass (AirDef fork): WGSL defining `fn post(uv: vec2<f32>, pixel: vec2<f32>) -> vec4<f32>`, after a prelude with `frame` (camera matrices, time, `params`), the world's colour and depth and helpers (`scene`, `depth-at`, `view-dir`, `scene-distance`, `project`). It runs after the world, before the hand and the HUD. Compile errors come back in the chat and the log; the last good pass keeps running. |
| `clear-post` | `func()` | Removes this mod's post pass: the world is shown as the game draws it. |
| `set-params` | `func(params: list<f32>)` | The pass's `frame.params` (up to 1024 floats, as 256 vec4), kept until replaced; call it once a tick (the pass gets the partial tick in `frame.time.y`). |