Mod canvas with terrain tiles and mouse input (API 24), set-acoustics (API 23), acoustics stage 3: reverb

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-31 00:59:02 +03:00
committed by airdef
parent 523c855b09
commit 734f632cbf
18 changed files with 1894 additions and 26 deletions
+45
View File
@@ -462,6 +462,17 @@ A picture of one of the mod's `set-views` cameras (AirDef fork).
| `rect` | `rect` | |
| `mode` | `u32` | 0 as seen, 1 thermal (white hot), 2 night vision (green). |
### record `terrain-shape`
A square of the world's land seen from above, in the map colours of a map item with its height shading (AirDef fork, API level 24); only in `set-canvas`'s shapes. It is 128 × 128 texels, a texel being `blocks-per-texel` × `blocks-per-texel` blocks whose north-west corner is (`x`, `z`); the game keeps up to 24 such tiles at a time and draws none of the rest. A mod aligns the corners to multiples of 128 × `blocks-per-texel` so tiles meet and are reused as the view moves. Where a chunk isn't loaded the tile is transparent (the mod draws its own "unknown" under it); the game scans chunks within a small time budget a frame, so a tile fills in over a few frames.
| Field | Type | |
| --- | --- | --- |
| `rect` | `rect` | |
| `x` | `s32` | |
| `z` | `s32` | |
| `blocks-per-texel` | `u32` | 1, 2, 4, 8, 16, 32 or 64; another value is rounded to one. |
### variant `shape`
| Case | Payload | |
@@ -472,6 +483,7 @@ A picture of one of the mod's `set-views` cameras (AirDef fork).
| `item` | `item-shape` | |
| `text` | `text-shape` | |
| `view` | `view-shape` | |
| `terrain` | `terrain-shape` | |
### record `frame-rate`
@@ -588,6 +600,33 @@ One change of a persistent sound source (AirDef fork, API level 20): a sound tha
| `loop-from` | `f32` | A looping source repeats the part of its sound from `loop-from` to `loop-to` seconds into it (both 0: all of it), the join crossfaded over 50 ms: for sounds that fade in and die away at their ends. |
| `loop-to` | `f32` | |
### record `canvas-button`
What the player did on the mod's canvas (AirDef fork, API level 24). Points are in GUI pixels from the screen's top left.
| Field | Type | |
| --- | --- | --- |
| `button` | `u32` | 0 left, 1 right, 2 middle, 3 and up the side buttons. |
| `at` | `point` | |
### record `canvas-scroll`
| Field | Type | |
| --- | --- | --- |
| `steps` | `f32` | Wheel steps, positive away from the player (up). |
| `at` | `point` | |
### variant `canvas-event`
| Case | Payload | |
| --- | --- | --- |
| `moved` | `point` | The pointer moved (one event a frame at most). |
| `pressed` | `canvas-button` | |
| `released` | `canvas-button` | |
| `scrolled` | `canvas-scroll` | |
| `key` | `string` | A key went down or repeated: `key.keyboard.escape`, as options.txt writes it. Escape does not close the canvas by itself: the mod does, with `close-canvas`. |
| `resized` | `tuple<f32, f32>` | The screen's size changed, or the canvas opened: width, height. |
### 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.
@@ -804,10 +843,16 @@ Where a capture is.
| `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. |
| `sound-source-generation` | `func() -> u32` | Moves on whenever the game released every source of every mod (the world closed, the session ended, a film began or ended, the sounds reloaded). A mod reads it before `sound-sources` and starts its sources again when it changed. |
| `acoustics` | `func() -> bool` | Whether the game muffles sounds by what lies between them and the listener (AirDef fork, API level 21: `HORIZON_ACOUSTICS`). A mod that muffles by itself (a `_far` variant for a distant blast) plays the near one instead when this is true, so nothing is muffled twice. |
| `set-acoustics` | `func(on: bool)` | Turns that on or off (AirDef fork, API level 23), from the next tick: what `HORIZON_ACOUSTICS` sets at the start. Sounds that play go back to the plain ones smoothly. |
| `sound-sources` | `func(generation: u32, ops: list<source-op>) -> bool` | Starts, updates and stops persistent sound sources. `generation` is the `sound-source-generation` the mod's sources belong to; if it is not the current one the call is ignored and returns false (read the generation, forget the sources, start them again). Stops are never dropped by a limit: only new sources beyond 256 running are, and at most 512 entries a call count. Every source of a mod that stops or is reloaded is released by the game. |
| `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; -2147483648 (`i32::MIN`) where it isn't loaded yet but `load-chunks` has it on its way: ask again in a few ticks. |
| `load-chunks` | `func(chunks: list<tuple<s32, s32>>)` | Has the game load these chunks (chunk x, chunk z) for a while (AirDef fork, API level 22): generated or read from disk on the game's worker threads, meshed never, and kept loaded for 20 seconds after the last call that named them. At most 64 chunks are wanted at once (the oldest requests fall away first; 64 a call). On a server, in a world the game does not simulate itself, or with nothing running, it does nothing, and `ground` keeps answering -64 for the unloaded. |
| `open-canvas` | `func()` | Shows a full-screen canvas over the game (AirDef fork, API level 24): the mod's `set-canvas` shapes over a dark background, with the pointer free. The world goes on running (no pause), the mouse is released, and every key and button goes to the mod as `canvas-events`, none to the game. Needs nothing the mod can't do without: when the mod stops the canvas closes. Not on the title screen. |
| `close-canvas` | `func()` | Closes the canvas when it is open. |
| `set-canvas` | `func(shapes: list<shape>)` | Replaces the canvas's shapes: up to 8192, drawn in order every frame until the next call. |
| `canvas-events` | `func() -> list<canvas-event>` | The events since the last call, oldest first, at most 256. |
| `canvas-open` | `func() -> bool` | Whether the canvas is up (the game never closes it but at the mod's word, or when the world is left). |
| `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. |