c89c78c470
Co-Authored-By: Codex <noreply@openai.com>
1583 lines
69 KiB
Plaintext
1583 lines
69 KiB
Plaintext
/// The contract between Horizon and its mods (docs/mods.md).
|
||
///
|
||
/// A mod is a WebAssembly component targeting the `mod` world. Each imported
|
||
/// interface but `log` is a capability: the mod's manifest lists the ones it
|
||
/// uses, the player sees them before turning the mod on, and the game refuses
|
||
/// a component that imports one its manifest does not declare.
|
||
package horizon:mods@0.1.0;
|
||
|
||
/// The mod's log, in the game's log under the mod's id. Always granted.
|
||
interface log {
|
||
enum level {
|
||
debug,
|
||
info,
|
||
warn,
|
||
error,
|
||
}
|
||
/// One line in the game's log as `[mod <id>] message`, at that level.
|
||
write: func(level: level, message: string);
|
||
}
|
||
|
||
/// Capability `game-read`: the local player, the world clock and the block
|
||
/// the player looks at.
|
||
interface game {
|
||
record player {
|
||
/// Feet position, in blocks.
|
||
x: f64,
|
||
y: f64,
|
||
z: f64,
|
||
/// Degrees, as F3 shows them.
|
||
yaw: f32,
|
||
/// Degrees: -90 looks straight up, 90 straight down.
|
||
pitch: f32,
|
||
/// Hit points as vanilla counts them: 20 is full health without effects.
|
||
health: f32,
|
||
/// 0 to 20, as the hunger bar.
|
||
food: u32,
|
||
/// `minecraft:overworld`, `minecraft:the_nether`, ...
|
||
dimension: string,
|
||
}
|
||
record clock {
|
||
/// Ticks since the world was created.
|
||
game-time: u64,
|
||
/// 24000 ticks per day; 0 is 6:00 on the first day.
|
||
day-time: u64,
|
||
}
|
||
/// None on the title screen.
|
||
get-player: func() -> option<player>;
|
||
/// None on the title screen.
|
||
get-clock: func() -> option<clock>;
|
||
/// Which world is open (AirDef fork): `world:<folder>` for a saved
|
||
/// world, `server:<address>` on a server; none on the title screen.
|
||
/// Mods keep their state apart by it.
|
||
world-id: func() -> option<string>;
|
||
/// The open saved world's seed (AirDef fork, API level 25): with the
|
||
/// folder name it tells a new world from an old one that had the same
|
||
/// name. None on the title screen and on a server.
|
||
world-seed: func() -> option<s64>;
|
||
/// A block along the player's view.
|
||
record hit {
|
||
/// The block hit.
|
||
block-x: s32,
|
||
block-y: s32,
|
||
block-z: s32,
|
||
/// The point on its face where the view meets it.
|
||
x: f64,
|
||
y: f64,
|
||
z: f64,
|
||
/// `minecraft:stone`, ...
|
||
block: string,
|
||
}
|
||
/// The first block along the player's view (fluids pass), up to
|
||
/// `distance` blocks (at most 1024; past the loaded chunks, across the
|
||
/// distant terrain when LOD Distance is on), as of this tick. None when
|
||
/// nothing is hit, and on the title screen.
|
||
raycast: func(distance: f32) -> option<hit>;
|
||
}
|
||
|
||
/// Capability `chat`: messages only the local player sees.
|
||
interface chat {
|
||
/// Shown in chat after the mod's name, like a system message.
|
||
show: func(text: string);
|
||
}
|
||
|
||
/// Capability `hud`: one panel of text lines per mod, drawn by the game
|
||
/// every frame until the mod changes or clears it (no call per frame).
|
||
interface hud {
|
||
enum corner {
|
||
top-left,
|
||
top-right,
|
||
bottom-left,
|
||
bottom-right,
|
||
}
|
||
record line {
|
||
/// Plain text, up to 256 characters.
|
||
text: string,
|
||
/// 0xRRGGBB.
|
||
color: u32,
|
||
}
|
||
/// Replaces the mod's panel: up to 16 lines in that corner of the screen.
|
||
set-panel: func(corner: corner, lines: list<line>);
|
||
/// Removes the mod's panel.
|
||
clear: func();
|
||
}
|
||
|
||
/// Capability `storage`: a per-mod folder of small key/value files, quota'd
|
||
/// (docs/mods.md). Keys are `[a-z0-9_.-]{1,64}`, one path segment.
|
||
interface storage {
|
||
/// None if `key` has never been `set`, or the key is not well-formed.
|
||
get: func(key: string) -> option<list<u8>>;
|
||
/// Errs on a malformed key or over quota (bytes for the whole mod).
|
||
set: func(key: string, value: list<u8>) -> result<_, string>;
|
||
/// No error if `key` was already absent.
|
||
delete: func(key: string);
|
||
}
|
||
|
||
/// Capability `command`: vanilla commands run as the player, with the
|
||
/// player's permissions, after the hook call returns (8 per call). A mod's
|
||
/// own commands are not run this way.
|
||
interface command {
|
||
/// `line` without its slash; its feedback goes to the chat as if typed.
|
||
run: func(line: string);
|
||
/// `lines` (each without its slash, at most 256 a call) as `run` does,
|
||
/// but with nothing in the chat: no feedback and no failure. In single
|
||
/// player and on Horizon's servers, each runs exactly as the player
|
||
/// typing it would (the same rights), in order, 64 a tick, and the
|
||
/// server logs one line a batch; one that carries a chat message (`say`,
|
||
/// `msg`) is refused. On any other server they go as chat commands, and
|
||
/// there their feedback shows: a mod running many should say so.
|
||
run-quiet: func(lines: list<string>);
|
||
|
||
/// What one word of a command line takes (AirDef fork, level 19).
|
||
variant value-kind {
|
||
/// One word, anything up to the next space. The words given are
|
||
/// only what the chat box suggests; any word is accepted.
|
||
word(list<string>),
|
||
/// A whole number, within the bounds given (either may be none).
|
||
integer(tuple<option<s32>, option<s32>>),
|
||
/// A number with or without decimals, within the bounds given.
|
||
number(tuple<option<f64>, option<f64>>),
|
||
/// One of these words and no other.
|
||
choice(list<string>),
|
||
/// One word, suggested from the list `set-suggestions` last gave
|
||
/// under this name; any word is accepted, so a list that is out
|
||
/// of date refuses nothing.
|
||
names(string),
|
||
/// Three coordinates: whole numbers, each one also `~` or `~n`.
|
||
block-pos,
|
||
}
|
||
/// One `key=value` option, or a bare flag (`noaudio`) when `value` is none.
|
||
record tree-option {
|
||
key: string,
|
||
value: option<value-kind>,
|
||
}
|
||
/// The words that follow, in any order, to the end of the line.
|
||
record tree-options {
|
||
/// The options and flags that may appear, each at most once.
|
||
entries: list<tree-option>,
|
||
/// Words that are no option are free words (a name): none refuses
|
||
/// them, some accepts them and suggests the words given.
|
||
free: option<list<string>>,
|
||
}
|
||
variant node-kind {
|
||
/// One word, as `value-kind` says.
|
||
value(value-kind),
|
||
/// The rest of the line, spaces included: only a last node.
|
||
text,
|
||
options(tree-options),
|
||
}
|
||
/// A node of a command's tree. Nodes are listed flat; a node's children
|
||
/// come after it in the list (a tree, never a loop).
|
||
record tree-node {
|
||
/// A literal's word, or an argument's name (the chat box's hint
|
||
/// shows it as `<name>`).
|
||
name: string,
|
||
/// None: a literal that must be typed as it is.
|
||
kind: option<node-kind>,
|
||
/// The nodes that may follow, by their place in the list. A word
|
||
/// no literal child is, goes to the argument children, in order.
|
||
children: list<u32>,
|
||
/// The line may end here (a branch with optional words after it
|
||
/// runs without them).
|
||
runs: bool,
|
||
}
|
||
/// Describes the arguments of a command `name` the mod registered
|
||
/// (AirDef fork, level 19), replacing the free text it takes
|
||
/// otherwise: the chat box colours the line, shows the error and the
|
||
/// next word before Enter, and completes it with Tab; a line that does
|
||
/// not parse never reaches the mod's `command` hook (the player gets
|
||
/// the error). A line that parses reaches it as it was typed.
|
||
/// `nodes[0]` is the node right after the command's name (its literal
|
||
/// children are the subcommands; `runs` says whether the bare command
|
||
/// runs). At most 512 nodes, 256 words in a list, 64 characters in a
|
||
/// word, no loops, no two children of a node with one name. Errs, and
|
||
/// changes nothing, on a tree that breaks these rules; a tree for a
|
||
/// name the mod did not register in `init` is ignored. Calling again
|
||
/// replaces the tree.
|
||
set-tree: func(name: string, nodes: list<tree-node>) -> result<_, string>;
|
||
/// Sets the words a `names` node suggests under `topic` (at most 256
|
||
/// of 64 characters, kept as given, the rest dropped). Call it again
|
||
/// whenever the words change (a saved scenario, a deleted one): the
|
||
/// chat box follows.
|
||
set-suggestions: func(topic: string, values: list<string>);
|
||
}
|
||
|
||
/// Capability `ui`: widgets the game draws with its own menus' widgets, for
|
||
/// a screen the mod owns and a settings page in Options > Mods. Layout and
|
||
/// drawing are the game's: a mod says what its widgets hold, never where
|
||
/// they sit or how they look, and the game clips everything it is handed.
|
||
interface ui {
|
||
/// A line of text.
|
||
record text-widget {
|
||
/// The mod's own name for the widget; `ui-events` calls echo it.
|
||
id: u32,
|
||
/// Up to 256 characters.
|
||
text: string,
|
||
/// 0xRRGGBB; 0 is the menus' white.
|
||
color: u32,
|
||
}
|
||
/// An item's icon and a name beside it, as recipe viewers show them.
|
||
record item-widget {
|
||
/// The mod's own name for the widget.
|
||
id: u32,
|
||
/// `minecraft:diamond`, `<mod>:<path>`; an unknown id draws a "?".
|
||
item: string,
|
||
/// The name shown beside the icon (empty: the item's own).
|
||
name: string,
|
||
}
|
||
/// Rows the player picks one of, as an options page lists choices: a
|
||
/// pick is `ui-events::select`, `selected` is the row to mark now.
|
||
record list-widget {
|
||
/// The mod's own name for the widget; `ui-events::select` echoes it.
|
||
id: u32,
|
||
/// The rows' texts, at most 512, each up to 256 characters.
|
||
rows: list<string>,
|
||
/// The row to mark as the current choice, if any.
|
||
selected: option<u32>,
|
||
}
|
||
/// A thing on a mod's screen or settings page.
|
||
/// A button as the options pages have them (200 × 20): a click is
|
||
/// `ui-events::select(id, 0)`. Mods cycle its label for a choice
|
||
/// ("Corner: Top Left").
|
||
record button-widget {
|
||
/// The mod's own name for the widget.
|
||
id: u32,
|
||
/// Up to 256 characters.
|
||
label: string,
|
||
}
|
||
variant widget {
|
||
/// Text the player reads.
|
||
text(text-widget),
|
||
/// A button.
|
||
button(button-widget),
|
||
/// An item's icon and name.
|
||
item(item-widget),
|
||
/// Rows the player picks from.
|
||
%list(list-widget),
|
||
}
|
||
/// A screen the mod owns: a title over widgets stacked down the middle,
|
||
/// the Done button the game adds, and Esc to leave it.
|
||
record screen {
|
||
/// Its title, up to 256 characters.
|
||
title: string,
|
||
/// Its widgets, in order, at most 64.
|
||
widgets: list<widget>,
|
||
}
|
||
/// Show `screen` over the game; a second call while it is open replaces
|
||
/// it. Only the last call of one hook counts.
|
||
open-screen: func(screen: screen);
|
||
/// Close the mod's screen when it is open (the mod hears no `closed`
|
||
/// for this: it was its own doing).
|
||
close-screen: func();
|
||
/// The mod's page in Options > Mods, reached from a settings button on
|
||
/// its row: the widgets it shows, an empty list for no page. The player
|
||
/// opening the page is `ui-events::settings-opened`: push fresh widgets
|
||
/// then; later calls update the page while it shows.
|
||
set-settings: func(widgets: list<widget>);
|
||
}
|
||
|
||
/// What the game calls on a mod that shows widgets (capability `ui`):
|
||
/// what the player did with them.
|
||
interface ui-events {
|
||
/// A row of one of the mod's `list` widgets was picked: the widget's
|
||
/// `id` and the row, on the screen or the settings page that showed it.
|
||
select: func(id: u32, row: u32);
|
||
/// The player left the mod's screen (Esc or Done); not for a screen the
|
||
/// mod closed itself or one that went away with the mod.
|
||
closed: func();
|
||
/// The player opened the mod's settings page in Options > Mods: call
|
||
/// `ui::set-settings` now to fill it with fresh widgets.
|
||
settings-opened: func();
|
||
}
|
||
|
||
/// Capability `input` (experimental: the manifest needs
|
||
/// `experimental = ["input"]`): the use button on items the mod claims, and
|
||
/// the mod's own keys. Events wait for `poll`, at most 256.
|
||
interface input {
|
||
/// The main hand's stack.
|
||
record held-item {
|
||
/// `minecraft:spyglass`, `<mod>:<path>`.
|
||
id: string,
|
||
count: u32,
|
||
/// The hotbar slot, 0 to 8.
|
||
slot: u32,
|
||
}
|
||
record item-use {
|
||
item: held-item,
|
||
/// Game ticks the button was held (0 on `use-start`).
|
||
ticks: u32,
|
||
}
|
||
variant event {
|
||
/// The use button went down with a claimed item in the main hand.
|
||
/// The game does nothing else with the click: no placing, no eating,
|
||
/// no swing.
|
||
use-start(item-use),
|
||
/// It came up again, or the item left the hand, or a screen opened.
|
||
use-stop(item-use),
|
||
/// A key `register-key` named went down or up while playing (no
|
||
/// screen open). The game's own mapping on that key still runs. A
|
||
/// screen opening lets every held key up.
|
||
key-down(string),
|
||
key-up(string),
|
||
/// Mouse wheel steps while the mod holds the wheel (`claim-wheel`):
|
||
/// positive away from the player, as the hotbar reads them.
|
||
wheel(f32),
|
||
}
|
||
/// The items whose use the mod handles instead of the game, by id (at
|
||
/// most 64). Replaces the previous list.
|
||
claim-items: func(ids: list<string>);
|
||
/// A key of the mod's: `name` comes back in `key-down` and `key-up`,
|
||
/// `label` says what it does, `key` is the key as options.txt writes
|
||
/// it (`key.keyboard.r`), the default: the player can bind another
|
||
/// one on the mod's page in Options > Mods, and that one wins. At most
|
||
/// 16; an unknown key is an error.
|
||
register-key: func(name: string, label: string, key: string) -> result<_, string>;
|
||
/// The main hand's stack, as of this tick; none when it is empty.
|
||
held: func() -> option<held-item>;
|
||
/// The events since the last call, oldest first.
|
||
poll: func() -> list<event>;
|
||
/// Takes the mouse wheel while playing (true) or gives it back: while
|
||
/// taken, its steps are the mod's `wheel` events and the hotbar doesn't
|
||
/// move. The game gives it back when the mod stops.
|
||
claim-wheel: func(on: bool);
|
||
/// A mapping as the player has bound it.
|
||
record mapping-state {
|
||
/// The bound key's name as Controls shows it: `W`, `Space`, `LMB`.
|
||
label: string,
|
||
/// Held down now (as of this frame for a mod with a `frame` hook,
|
||
/// else this tick).
|
||
down: bool,
|
||
}
|
||
/// A movement or click mapping as the player has bound it: `key.forward`,
|
||
/// `key.left`, `key.back`, `key.right`, `key.jump`, `key.sneak`,
|
||
/// `key.sprint`, `key.attack` or `key.use`. None for another name.
|
||
mapping: func(name: string) -> option<mapping-state>;
|
||
/// Clicks of the attack and use buttons in the last second.
|
||
clicks-per-second: func() -> tuple<u32, u32>;
|
||
}
|
||
|
||
/// Capability `render` (experimental: the manifest needs
|
||
/// `experimental = ["render"]`): shapes the game draws for the mod with its
|
||
/// own renderer, kept until the mod replaces them (no call per frame). A mod
|
||
/// never supplies shader code.
|
||
interface render {
|
||
/// A corner of the screen, as `hud`'s panels use them.
|
||
enum corner {
|
||
top-left,
|
||
top-right,
|
||
bottom-left,
|
||
bottom-right,
|
||
}
|
||
/// A rectangle in GUI pixels: the top left corner and the size.
|
||
record rect {
|
||
x: f32,
|
||
y: f32,
|
||
w: f32,
|
||
h: f32,
|
||
}
|
||
/// A point in GUI pixels from the screen's top left.
|
||
record point {
|
||
x: f32,
|
||
y: f32,
|
||
}
|
||
record fill-shape {
|
||
rect: rect,
|
||
/// 0xAARRGGBB.
|
||
color: u32,
|
||
}
|
||
/// Any four-cornered shape (a wheel's segment, an arrow): the corners
|
||
/// in order round it.
|
||
record quad-shape {
|
||
corners: tuple<point, point, point, point>,
|
||
/// 0xAARRGGBB.
|
||
color: u32,
|
||
}
|
||
record sprite-shape {
|
||
/// One of the game's GUI sprites, as `gui/sprites/` names them
|
||
/// (`hud/heart/full`, `widget/button`), the resource packs' versions
|
||
/// included. An unknown one draws nothing.
|
||
sprite: string,
|
||
rect: rect,
|
||
/// A tint, 0xAARRGGBB: 0xFFFFFFFF draws it as it is.
|
||
color: u32,
|
||
}
|
||
record item-shape {
|
||
/// `minecraft:diamond`, `<mod>:<path>`; an unknown one draws nothing.
|
||
item: string,
|
||
/// The icon's top left.
|
||
at: point,
|
||
/// 1.0 is the hotbar's 16 × 16.
|
||
scale: f32,
|
||
}
|
||
record text-shape {
|
||
/// Up to 256 characters, one line.
|
||
text: string,
|
||
at: point,
|
||
/// 0xRRGGBB, as `hud`'s lines.
|
||
color: u32,
|
||
/// Centred on `at.x` instead of starting there.
|
||
centered: bool,
|
||
shadow: bool,
|
||
}
|
||
/// A picture of one of the mod's `set-views` cameras (AirDef fork).
|
||
record view-shape {
|
||
/// The camera's id; an unknown one draws nothing.
|
||
view: u32,
|
||
rect: rect,
|
||
/// 0 as seen, 1 thermal (white hot), 2 night vision (green).
|
||
mode: u32,
|
||
}
|
||
/// 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.
|
||
record terrain-shape {
|
||
rect: rect,
|
||
x: s32,
|
||
z: s32,
|
||
/// 1, 2, 4, 8, 16, 32 or 64; another value is rounded to one.
|
||
blocks-per-texel: u32,
|
||
}
|
||
variant shape {
|
||
fill(fill-shape),
|
||
quad(quad-shape),
|
||
sprite(sprite-shape),
|
||
item(item-shape),
|
||
text(text-shape),
|
||
view(view-shape),
|
||
terrain(terrain-shape),
|
||
}
|
||
/// Replaces the mod's HUD shapes: up to 1024, drawn every frame in
|
||
/// order over the HUD (after the hotbar, under chat and screens), hidden
|
||
/// with the HUD (F1). An empty list removes them.
|
||
set-hud: func(shapes: list<shape>);
|
||
/// The screen's size in GUI pixels (width, height), as of this tick.
|
||
gui-size: func() -> tuple<f32, f32>;
|
||
/// Shakes the camera: a jolt of `strength` (0 to 1, 1 the hardest) that
|
||
/// fades out over `seconds` (at most 10). Jolts add up to 1. The view
|
||
/// turns, the player doesn't, and the player's Distortion Effects option
|
||
/// scales it (0 turns it off).
|
||
shake: func(strength: f32, seconds: f32);
|
||
/// Replaces the mod's corner panel: shapes in GUI pixels from the top
|
||
/// left of a `width` × `height` box that the game places in `corner`,
|
||
/// stacked with the game's overlays and the other mods' panels (under
|
||
/// the status effects at the top right), as `hud`'s panels are.
|
||
set-corner: func(corner: corner, width: f32, height: f32, shapes: list<shape>);
|
||
/// Removes the mod's corner panel.
|
||
clear-corner: func();
|
||
/// The width of one line of text in GUI pixels, in the HUD's font: exact
|
||
/// for Latin letters (U+0000 to U+024F), 6 per other character.
|
||
text-width: func(text: string) -> f32;
|
||
record frame-rate {
|
||
/// Frames drawn in the last second.
|
||
fps: u32,
|
||
/// The slowest frame's rate, and the 1% low (the 99th percentile
|
||
/// frame time's rate), over the last 5 seconds.
|
||
min: u32,
|
||
low: u32,
|
||
}
|
||
/// The game's frame counter, recomputed twice a second.
|
||
frame-stats: func() -> frame-rate;
|
||
record zoom {
|
||
/// The field of view is divided by it: 1 is none, at most 10.
|
||
factor: f32,
|
||
/// Ease in and out through the game's field-of-view easing, as the
|
||
/// spyglass does, instead of at once.
|
||
smooth: bool,
|
||
/// Mouse turning is multiplied by it while zoomed: 1 keeps the
|
||
/// player's sensitivity, at least 0.05.
|
||
turn: f32,
|
||
}
|
||
/// Zooms the camera until the next call (`factor` 1 ends it), only
|
||
/// while playing: a screen opening or the spyglass's own view (which
|
||
/// wins) leave the camera vanilla's. With several mods, the strongest
|
||
/// zoom counts.
|
||
set-zoom: func(zoom: zoom);
|
||
record minimap {
|
||
corner: corner,
|
||
/// Its side in GUI pixels, 16 to 256.
|
||
size: f32,
|
||
/// World blocks per map pixel, 0.5 to 4; the map is 128 × 128 pixels.
|
||
blocks-per-pixel: f32,
|
||
/// The map turns with the player, who faces up, and an N on its rim
|
||
/// marks north. Otherwise north is up and the player's arrow turns.
|
||
rotate: bool,
|
||
/// Round, the corners left clear; otherwise square.
|
||
round: bool,
|
||
}
|
||
/// Shows a map of the world around the player in `corner`, stacked with
|
||
/// the game's overlays and the mods' panels, until the next call (none
|
||
/// hides it). It looks like a map item: vanilla's map colours with their
|
||
/// height shading and water depth, and the player's arrow. Underground,
|
||
/// under a roof and in the Nether it maps the floor around the player's
|
||
/// height. The game keeps the map's tiles and refreshes them within its
|
||
/// own frame budget; hidden, they are dropped. One map shows at a time:
|
||
/// the first loaded mod's.
|
||
set-minimap: func(minimap: option<minimap>);
|
||
record far-terrain {
|
||
/// How far the distant terrain reaches, in chunks: 64 to 1024. On
|
||
/// integrated graphics other than Apple's the game caps it lower.
|
||
distance: u32,
|
||
/// Coarser far tiles, as the Far Detail setting's Reduced: 2 to 4 ms
|
||
/// less GPU time per frame on integrated graphics.
|
||
reduced: bool,
|
||
}
|
||
/// Draws the world beyond the render distance as distant terrain, out to
|
||
/// `distance` chunks, until the next call (none ends it). The game builds
|
||
/// it on its own workers, from the chunks already loaded or saved and,
|
||
/// where nobody has been, from the world's generator; the simulation
|
||
/// distance doesn't change. Only worlds whose generator the game has
|
||
/// (single player and a LAN world you host) show it. The player's own LOD
|
||
/// Distance setting, when on, wins. One far terrain shows at a time: the
|
||
/// first loaded mod's.
|
||
set-far-terrain: func(far-terrain: option<far-terrain>);
|
||
/// A block model drawn in the world (AirDef fork).
|
||
record model-instance {
|
||
/// Stays the same while the object lives: the game moves an id
|
||
/// smoothly from where the last `set-models` put it.
|
||
id: u32,
|
||
/// A block state as commands write it (`airdef:shahed`,
|
||
/// `minecraft:stone`, `minecraft:furnace[facing=east]`): its block
|
||
/// model is drawn. An unknown one draws nothing.
|
||
model: string,
|
||
/// Where the model's centre is, in blocks.
|
||
x: f64,
|
||
y: f64,
|
||
z: f64,
|
||
/// Rotation about the model's centre: a quaternion (x, y, z, w).
|
||
rotation: tuple<f32, f32, f32, f32>,
|
||
/// Uniform scale, 1.0 a block (0 to 64).
|
||
scale: f32,
|
||
/// Drawn at full brightness, whatever the light where it is.
|
||
glow: bool,
|
||
}
|
||
/// Replaces the mod's models: up to 4096, drawn with the world's
|
||
/// entities until replaced. Call it once a tick: the game interpolates
|
||
/// each id between its last two positions and rotations every frame.
|
||
/// An empty list removes them.
|
||
set-models: func(models: list<model-instance>);
|
||
/// A handle for a block state name, for `set-models-by-id` (AirDef
|
||
/// fork, API level 11): the name crosses once, not every tick. None for
|
||
/// a name that is no block state of the game's registry (nothing is
|
||
/// remembered for it). Handles are valid until `model-generation`
|
||
/// changes (the registry changed: a resource reload, another world's
|
||
/// data); ask again for every name then.
|
||
model-id: func(model: string) -> option<u32>;
|
||
/// Moves on whenever the handles `model-id` gave stop being valid. A
|
||
/// mod reads it before `set-models-by-id` and re-asks when it changed.
|
||
model-generation: func() -> u32;
|
||
/// `model-instance` with the model as a handle.
|
||
record model-instance-id {
|
||
id: u32,
|
||
/// From `model-id`.
|
||
model: u32,
|
||
x: f64,
|
||
y: f64,
|
||
z: f64,
|
||
rotation: tuple<f32, f32, f32, f32>,
|
||
scale: f32,
|
||
glow: bool,
|
||
}
|
||
/// `set-models` with handles instead of names: the same models, limits
|
||
/// and interpolation, fewer bytes across the boundary. `generation` is
|
||
/// the `model-generation` the handles were asked under; if it is not
|
||
/// the current one the call is ignored and returns false (re-ask the
|
||
/// handles and call again). Handles the game doesn't know draw nothing.
|
||
set-models-by-id: func(generation: u32, models: list<model-instance-id>) -> bool;
|
||
/// Particles to spawn on this client (AirDef fork).
|
||
record particle-spawn {
|
||
/// As `/particle` names the type: `minecraft:flame`, `minecraft:dust`.
|
||
particle: string,
|
||
x: f64,
|
||
y: f64,
|
||
z: f64,
|
||
/// Gaussian spread round the point, per axis, in blocks.
|
||
spread: tuple<f32, f32, f32>,
|
||
/// Every particle's starting velocity, blocks a tick.
|
||
velocity: tuple<f32, f32, f32>,
|
||
/// Gaussian speed added to it per axis.
|
||
speed: f32,
|
||
/// 1 to 256.
|
||
count: u32,
|
||
/// 0xRRGGBB for dust and coloured types (0: white).
|
||
color: u32,
|
||
/// Dust size (0.01 to 4).
|
||
scale: f32,
|
||
}
|
||
/// Spawns particles on this client only: no command, no server.
|
||
/// At most 512 spawns a call.
|
||
spawn-particles: func(particles: list<particle-spawn>);
|
||
/// Plays a sound event (`minecraft:entity.generic.explode`,
|
||
/// `<mod>:<name>`) at a point on this client.
|
||
play-sound: func(event: string, x: f64, y: f64, z: f64, volume: f32, pitch: f32);
|
||
/// What a `sound-sources` entry does.
|
||
enum source-op-kind {
|
||
/// Starts source `id` (one that is already running restarts: the old
|
||
/// one releases, the new one attacks).
|
||
start,
|
||
/// Sets everything of a running source: pose, velocity, gain, pitch,
|
||
/// looping and the rest. An id that is not running is ignored.
|
||
update,
|
||
/// Releases source `id` (fading over its `release`). Only `id`
|
||
/// is read.
|
||
stop,
|
||
}
|
||
/// One change of a persistent sound source (AirDef fork, API level 20): a
|
||
/// sound that goes on, follows a pose and has a lifetime, over the game's
|
||
/// own mixer. Unlike `play-sound` events they are not repeated; a source
|
||
/// is started, updated as often as the mod likes (a tick) and stopped.
|
||
/// The ids are the mod's own numbers (per mod, up to 256 running).
|
||
record source-op {
|
||
kind: source-op-kind,
|
||
id: u32,
|
||
/// The sound event (`<mod>:<name>`), read by `start`: the same
|
||
/// variant is chosen for the whole life of the source.
|
||
event: string,
|
||
/// Where it is, in the world as the listener hears it (the listener
|
||
/// stays at the player; a mod that shows another place moves the
|
||
/// source by the offset itself).
|
||
x: f64,
|
||
y: f64,
|
||
z: f64,
|
||
/// Blocks a second. The mixer carries the source on along it between
|
||
/// calls (at most 0.15 s), so a source updated once a tick moves
|
||
/// without steps. Also what Doppler reads.
|
||
vx: f32,
|
||
vy: f32,
|
||
vz: f32,
|
||
/// 0 to 16, times the event's volume and the category sliders; above 1 it only widens
|
||
/// the distance it is heard from, as in vanilla.
|
||
gain: f32,
|
||
/// 0.5 to 2, the sound's own pitch (Doppler is added by `doppler`).
|
||
pitch: f32,
|
||
/// A looping source goes on until stopped; a source that is not
|
||
/// looping plays once and is gone.
|
||
looping: bool,
|
||
/// More important sources keep their voice when there are not enough
|
||
/// (0.1 to 10, 1 usually). Sources are ranked by priority times what
|
||
/// the listener would hear, 24 get a voice; the others stay virtual (silent but
|
||
/// alive, a loop only) and are heard when they rank again.
|
||
priority: f32,
|
||
/// Seconds to fade in (0 to 5; 0 is 5 ms, so there is no click).
|
||
attack: f32,
|
||
/// Seconds to fade out after `stop` (0 to 5; 0 is 5 ms).
|
||
release: f32,
|
||
/// How much of the Doppler shift of the velocity is applied, 0 (none,
|
||
/// the usual choice) to 1, bounded to a change of pitch of 12%. The
|
||
/// velocity is taken against a listener at rest. Leave 0 when the
|
||
/// pitch already follows the speed.
|
||
doppler: 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-from: f32,
|
||
loop-to: f32,
|
||
}
|
||
/// 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.
|
||
sound-source-generation: func() -> u32;
|
||
/// 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.
|
||
acoustics: func() -> 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.
|
||
set-acoustics: func(on: 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.
|
||
sound-sources: func(generation: u32, ops: list<source-op>) -> bool;
|
||
/// Asks for the ground height of these columns (x, z): at most 512 a
|
||
/// tick, answered by `ground` from the next tick on.
|
||
query-ground: func(columns: list<tuple<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.
|
||
ground: func() -> list<tuple<s32, 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.
|
||
load-chunks: func(chunks: list<tuple<s32, s32>>);
|
||
/// 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.
|
||
record canvas-button {
|
||
/// 0 left, 1 right, 2 middle, 3 and up the side buttons.
|
||
button: u32,
|
||
at: point,
|
||
}
|
||
record canvas-scroll {
|
||
/// Wheel steps, positive away from the player (up).
|
||
steps: f32,
|
||
at: point,
|
||
}
|
||
variant canvas-event {
|
||
/// The pointer moved (one event a frame at most).
|
||
moved(point),
|
||
pressed(canvas-button),
|
||
released(canvas-button),
|
||
scrolled(canvas-scroll),
|
||
/// 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`.
|
||
key(string),
|
||
/// The screen's size changed, or the canvas opened: width, height.
|
||
resized(tuple<f32, f32>),
|
||
}
|
||
/// 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.
|
||
open-canvas: func();
|
||
/// Closes the canvas when it is open.
|
||
close-canvas: func();
|
||
/// Replaces the canvas's shapes: up to 8192, drawn in order every frame
|
||
/// until the next call.
|
||
set-canvas: func(shapes: list<shape>);
|
||
/// The events since the last call, oldest first, at most 256.
|
||
canvas-events: func() -> list<canvas-event>;
|
||
/// Whether the canvas is up (the game never closes it but at the mod's
|
||
/// word, or when the world is left).
|
||
canvas-open: func() -> bool;
|
||
/// 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.
|
||
enum policy {
|
||
/// 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.
|
||
collision,
|
||
/// Sensor line of sight: opaque blocks (those that stop light) only;
|
||
/// glass, leaves and fluids are seen through.
|
||
sight,
|
||
/// Sound occlusion: blocks with a full-cube collision shape.
|
||
sound,
|
||
}
|
||
/// How a query ended. Never `clear` for a chunk that isn't loaded.
|
||
enum verdict {
|
||
/// Nothing on the way, everything checked.
|
||
clear,
|
||
/// A block stops it; see the other fields.
|
||
hit,
|
||
/// 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`.
|
||
unknown,
|
||
}
|
||
/// A segment to trace through the loaded blocks.
|
||
record ray {
|
||
/// Echoed in the answer.
|
||
id: u32,
|
||
start: tuple<f64, f64, f64>,
|
||
end: tuple<f64, f64, f64>,
|
||
policy: policy,
|
||
}
|
||
record ray-answer {
|
||
id: u32,
|
||
verdict: verdict,
|
||
/// For a `hit`: how far along the segment, 0 to 1, where it enters
|
||
/// the shape.
|
||
fraction: f64,
|
||
/// For a `hit`: the face normal (the axis it entered along).
|
||
normal: tuple<s32, s32, s32>,
|
||
/// For a `hit`: the block hit.
|
||
block: tuple<s32, s32, s32>,
|
||
/// For an `unknown`: how far along the segment the unknown part
|
||
/// begins.
|
||
known-to: f64,
|
||
}
|
||
/// 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.
|
||
query-rays: func(rays: list<ray>);
|
||
/// The answers to the last tick's `query-rays`, in the order asked.
|
||
rays: func() -> list<ray-answer>;
|
||
/// What a 16 x 16 x 16 section of the world holds, for a policy.
|
||
enum section-fill {
|
||
/// The game has no such chunk loaded: nothing is known.
|
||
unknown,
|
||
/// Nothing in it stops a query.
|
||
empty,
|
||
/// Every block in it does.
|
||
full,
|
||
/// Some do: `bits` tells which.
|
||
mixed,
|
||
}
|
||
record section {
|
||
/// Section coordinates: block x, y, z divided by 16, rounded down.
|
||
x: s32,
|
||
y: s32,
|
||
z: s32,
|
||
fill: section-fill,
|
||
/// 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.
|
||
bits: list<u8>,
|
||
}
|
||
/// 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.
|
||
query-sections: func(policy: policy, sections: list<tuple<s32, s32, s32>>);
|
||
/// The answers to the last tick's `query-sections`.
|
||
sections: func() -> list<section>;
|
||
/// Changes to the world since the last tick, for a mod's cache.
|
||
record changes {
|
||
/// A number that changes when another world or dimension opens:
|
||
/// everything cached before is void.
|
||
epoch: u32,
|
||
/// Counts block changes in the loaded world, ever (wraps).
|
||
revision: u64,
|
||
/// More sections changed than fit: treat everything as changed.
|
||
overflow: bool,
|
||
/// Sections (as in `section`) where a block changed, at most 256.
|
||
sections: list<tuple<s32, s32, s32>>,
|
||
}
|
||
/// The block changes of the last tick (placed, broken, exploded) and
|
||
/// the world's epoch. Only changes in chunks the game has loaded.
|
||
world-changes: func() -> changes;
|
||
/// 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.
|
||
set-post: func(wgsl: string);
|
||
/// Removes this mod's post pass: the world is shown as the game draws it.
|
||
clear-post: func();
|
||
/// 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`).
|
||
set-params: func(params: list<f32>);
|
||
/// 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.
|
||
record camera-view {
|
||
/// Stays the same while the camera lives: the game turns it smoothly
|
||
/// between the last two `set-views`.
|
||
id: u32,
|
||
x: f64,
|
||
y: f64,
|
||
z: f64,
|
||
/// Degrees, as the player's: yaw 0 looks south (+z), pitch 90 down.
|
||
yaw: f32,
|
||
pitch: f32,
|
||
/// Vertical field of view, degrees (1 to 110).
|
||
fov: f32,
|
||
/// The picture's size in pixels (16 to 3840 × 16 to 2160).
|
||
width: u32,
|
||
height: u32,
|
||
}
|
||
/// Replaces the mod's cameras: up to 8. A `view` shape shows one; the
|
||
/// game renders up to three a frame, in turn.
|
||
set-views: func(views: list<camera-view>);
|
||
/// Renders the screen's world from one of the `set-views` cameras
|
||
/// (AirDef fork), with everything the player's own view has: the HD
|
||
/// lighting, sky, clouds, fog, smoke, TAA and the post passes, at the
|
||
/// window's resolution. The picture size of that camera is ignored, the
|
||
/// player's hand, block outline and the game's HUD are not drawn (the mod's
|
||
/// own `set-hud` shapes are); a `view` shape of that camera draws nothing.
|
||
/// For a full-screen replay or a director's camera; the small pictures of
|
||
/// monitors stay `view` shapes. None (or an unknown id) is the player's
|
||
/// own view. The chunks stay those round the player.
|
||
set-main-view: func(view: option<u32>);
|
||
/// A light the mod's things give off (AirDef fork): rocket flames,
|
||
/// flares, blasts. Drawn by the HD lighting (`set-lighting`).
|
||
record point-light {
|
||
/// Stays the same while the light lives: the game moves it smoothly.
|
||
id: u32,
|
||
x: f64,
|
||
y: f64,
|
||
z: f64,
|
||
/// Linear RGB, 0 to 1.
|
||
color: tuple<f32, f32, f32>,
|
||
/// Brightness: about what it lights one block away (0 to 100000).
|
||
intensity: f32,
|
||
/// Nothing past this many blocks (1 to 256).
|
||
radius: f32,
|
||
}
|
||
/// Replaces the mod's lights: up to 512, interpolated per id between
|
||
/// the last two calls.
|
||
set-lights: func(lights: list<point-light>);
|
||
/// The HD lighting (AirDef fork): the world lit per pixel by the mods'
|
||
/// lights, in high dynamic range, with bloom and tone mapping.
|
||
record lighting {
|
||
hd: bool,
|
||
/// 1 as is; more brightens.
|
||
exposure: f32,
|
||
/// How much bright things glow (0 none, 1 strong).
|
||
bloom: f32,
|
||
}
|
||
/// Switches the HD lighting on or off for this mod's world, with its
|
||
/// exposure and bloom; off, the world is drawn as the game draws it.
|
||
set-lighting: func(lighting: lighting);
|
||
/// Shows the world at this time of day (AirDef fork): the sky, the sun
|
||
/// and moon, the sky light and the fog, as `day-time` ticks (24000 a day,
|
||
/// as `clock`). Only what the player sees changes: the world's own clock,
|
||
/// its saves and its rules do not. None shows the world's own time.
|
||
set-time-override: func(day-time: option<u64>);
|
||
/// A piece of smoke or exhaust trail (AirDef fork): a tube from `a` to `b`
|
||
/// (equal ends: a puff) that the HD renderer ray-marches as a volume, lit by
|
||
/// the sun, the sky and the mod's lights, and that thins the fog and clouds
|
||
/// it passes through. The game derives everything from the age
|
||
/// (`clock - born`): the radius grows from `radius-start` to `radius-end`,
|
||
/// the density fades to nothing at `life`, the smoke drifts with the wind
|
||
/// and rises by `rise`, so a segment is sent once per change of the set, not
|
||
/// per frame, and a replay that seeks sends the segments of that moment.
|
||
record smoke-segment {
|
||
/// Seeds the smoke's noise.
|
||
id: u32,
|
||
ax: f64,
|
||
ay: f64,
|
||
az: f64,
|
||
bx: f64,
|
||
by: f64,
|
||
bz: f64,
|
||
/// When it was made, in the `clock` of `set-smoke` (ticks).
|
||
born: f64,
|
||
/// How long it lasts, in the same ticks (1 to 72000).
|
||
life: f32,
|
||
/// Radius of the tube in blocks at birth and at the end of its life.
|
||
radius-start: f32,
|
||
radius-end: f32,
|
||
/// How thick it is at the core at birth: extinction per block (0 to 8).
|
||
density: f32,
|
||
/// How hot it glows at birth, 0 soot to 1 white hot; it cools in seconds.
|
||
heat: f32,
|
||
/// How dark it is, 0 white vapour to 1 black soot.
|
||
soot: f32,
|
||
/// Blocks per second it floats up (negative sinks).
|
||
rise: f32,
|
||
/// Radius in blocks of the clear tunnel it leaves in fog and cloud, filling
|
||
/// back in over `life` (0 none).
|
||
clear: f32,
|
||
}
|
||
/// Replaces the mod's smoke: up to 4096 segments, `clock` being now in ticks
|
||
/// (the game shows the age between the last two calls). Returns whether the
|
||
/// HD renderer draws them; when it does not (the effects preset, HD smoke
|
||
/// off), the mod draws its own smoke.
|
||
set-smoke: func(clock: f64, segments: list<smoke-segment>) -> bool;
|
||
|
||
/// State of volumetric smoke, as of the last prepared main-view frame (API level 26).
|
||
/// `available` means this host implements the API, not that the backend is ready.
|
||
/// `enabled` means HD and smoke are enabled; `backend-ready` means that frame's
|
||
/// HD smoke/fog path was scheduled. It does not guarantee GPU submission, a visible
|
||
/// pixel, or inclusion of every segment (culling and budgets still apply).
|
||
/// `request-accepted` means this mod called set-smoke in this generation and its
|
||
/// sanitized submission was stored; it is not a rendering acknowledgement.
|
||
/// `generation` changes when the host observes a world/seed transition or restarts
|
||
/// the mod runtime. Until a frame is prepared after a transition, keep fallbacks.
|
||
record smoke-state {
|
||
generation: u64,
|
||
available: bool,
|
||
enabled: bool,
|
||
request-accepted: bool,
|
||
backend-ready: bool,
|
||
reason: smoke-reason,
|
||
}
|
||
enum smoke-reason {
|
||
awaiting-frame,
|
||
disabled,
|
||
path-unavailable,
|
||
ready,
|
||
}
|
||
/// The calling mod's submission and the last main-view smoke path state.
|
||
smoke-status: func() -> smoke-state;
|
||
/// API level 27: state for the calling mod and current world generation.
|
||
/// Accepted means the request was stored, not that output was produced.
|
||
/// Prepared is a host-side processing milestone, not audible or GPU completion.
|
||
record capability-state {
|
||
generation: u64,
|
||
available: bool,
|
||
enabled: bool,
|
||
request-accepted: bool,
|
||
prepared: bool,
|
||
reason: capability-reason,
|
||
}
|
||
enum capability-reason {
|
||
awaiting-world,
|
||
disabled,
|
||
not-requested,
|
||
awaiting-backend,
|
||
failed,
|
||
ready,
|
||
}
|
||
/// The caller's last set-acoustics request and the last geometry processing step.
|
||
/// Enabled reflects the actual audio setting. A silent or headless world may
|
||
/// remain awaiting-backend until a positional sound is processed. A later
|
||
/// disable or world transition clears the processing milestone.
|
||
acoustics-status: func() -> capability-state;
|
||
/// The caller's capture request, scoped to its run and world generation.
|
||
/// Enabled means a world is present, not that the encoder or GPU is ready.
|
||
/// Prepared means recording, encoding, or done; inspect capture-status for
|
||
/// completion and errors. Other mods cannot claim it. A world transition
|
||
/// invalidates ownership and asks the host to cancel the capture.
|
||
capture-owner-status: func() -> capability-state;
|
||
/// A directional light with a visible beam (AirDef fork): a searchlight, a
|
||
/// headlight. The HD lighting lights the surfaces and flying things inside
|
||
/// its cone (smoothly from the inner to the outer angle, down to nothing at
|
||
/// `range`) and draws the beam as a translucent volume lit from inside: it
|
||
/// scatters in the air (more in fog and smoke, a faint artistic one in clear
|
||
/// air), the world hides it where it is in front, and the camera may stand
|
||
/// inside it. The light does not look for walls: send `range` as far as the
|
||
/// beam is free (a cast along the axis) so it stops where the land stops it.
|
||
record spot-light {
|
||
/// Stays the same while the light lives: the game moves it smoothly.
|
||
id: u32,
|
||
/// The apex, in the lens.
|
||
x: f64,
|
||
y: f64,
|
||
z: f64,
|
||
/// Where it points (any length but zero; it is normalised).
|
||
dx: f32,
|
||
dy: f32,
|
||
dz: f32,
|
||
/// Linear RGB, 0 to 1.
|
||
color: tuple<f32, f32, f32>,
|
||
/// Brightness: about what it lights one block away (0 to 100000).
|
||
intensity: f32,
|
||
/// Nothing past this many blocks (1 to 1024).
|
||
range: f32,
|
||
/// Half angle in radians where the light is at full strength (0.005 to 1.2).
|
||
inner-angle: f32,
|
||
/// Half angle in radians where it has faded to nothing (past the inner one, to 1.4).
|
||
outer-angle: f32,
|
||
/// How visible the beam is in the air, 0 (the light only lights things) to 1.
|
||
beam: f32,
|
||
}
|
||
/// Replaces the mod's spot lights: up to 32 (the nearest 16 are drawn),
|
||
/// interpolated per id between the last two calls. Returns whether the HD
|
||
/// renderer draws them with their beams; when it does not (the effects
|
||
/// preset, HD off), the mod draws its own beam if it wants one.
|
||
set-spot-lights: func(lights: list<spot-light>) -> bool;
|
||
/// What `capture-start` records (AirDef fork, API level 17).
|
||
record capture-options {
|
||
/// A folder under the game's home (letters, digits, `-`, `_` and `/`; no
|
||
/// `..`); made if missing. The result lands in it.
|
||
folder: string,
|
||
/// The file name without its extension (letters, digits, `-`, `_`, `.`).
|
||
name: string,
|
||
/// Frames a second of the picture (1 to 120).
|
||
fps: u32,
|
||
/// The picture's size in pixels; 0 keeps the window's. An offscreen game
|
||
/// is resized to it, a window asked to be (what it gets is in the state).
|
||
width: u32,
|
||
height: u32,
|
||
/// x264 quality, 0 (lossless) to 51; 14 is visually clean.
|
||
crf: u32,
|
||
/// Mix the sounds the mod plays (`play-sound`) into the file's audio
|
||
/// track, heard from the main view's camera at the capture's own time.
|
||
audio: bool,
|
||
/// Frames drawn and thrown away after a cut (a new `set-main-view` id) so
|
||
/// the anti-aliasing and the volumes settle in the new shot (0 to 32).
|
||
warmup: u32,
|
||
}
|
||
/// Where a capture is.
|
||
enum capture-phase {
|
||
/// Nothing running (or never started).
|
||
idle,
|
||
/// Asked; waiting for the picture to reach the size.
|
||
arming,
|
||
/// Frames are being rendered and written.
|
||
recording,
|
||
/// The frames are written; the encoder is closing the file.
|
||
encoding,
|
||
/// Finished: `file` is the result.
|
||
done,
|
||
/// Stopped by an error or cancelled: `message` says why.
|
||
failed,
|
||
}
|
||
record capture-state {
|
||
phase: capture-phase,
|
||
/// Frames written so far.
|
||
frames: u32,
|
||
/// The size of the frames, once known.
|
||
width: u32,
|
||
height: u32,
|
||
/// The result: the MP4, or the folder of the PNG sequence when no
|
||
/// `ffmpeg` was found. Empty until `done`.
|
||
file: string,
|
||
/// An error, or a note about the result (no encoder, no audio).
|
||
message: string,
|
||
}
|
||
/// Records the screen frame by frame (AirDef fork), at a fixed time step
|
||
/// whatever the speed of the machine: while it records, the game clock
|
||
/// advances exactly `1 / fps` seconds a frame (ticks, interpolation, the
|
||
/// mod's `tick`s and the sounds with it), so a slow frame is a longer wait
|
||
/// and not a skipped one. The frames are read back from the GPU and
|
||
/// encoded to H.264 MP4 by `ffmpeg` (found on the `PATH`, or named by
|
||
/// `HORIZON_FFMPEG`) through a bounded queue, never held in memory; with no
|
||
/// `ffmpeg` they are written as a PNG sequence. Returns an error for a
|
||
/// capture already running, a bad name, or an invalid size. Only the
|
||
/// game's own files are written, under its home.
|
||
capture-start: func(options: capture-options) -> result<_, string>;
|
||
/// Ends this mod run's capture: finishes the file, or (`cancel`) throws it away.
|
||
/// A different mod cannot stop it. World transitions cancel mod-owned captures.
|
||
capture-stop: func(cancel: bool);
|
||
/// The capture's state; `done` and `failed` stay until the next start.
|
||
capture-status: func() -> capture-state;
|
||
/// Asks for the best picture the renderer can give (AirDef fork, level 17):
|
||
/// the HD world at the full size of the window (no resolution scale, so no
|
||
/// upscaling), and the volumetric clouds and fog marched with more steps.
|
||
/// Meant for replays and films; false restores the player's settings. A
|
||
/// capture turns it on for its duration.
|
||
set-film-quality: func(on: bool);
|
||
/// Starts a log of the world's block changes as the game's client sees
|
||
/// them (AirDef fork, level 18): each change keeps its position, the
|
||
/// state before and after, and the game tick (the number `tick` is
|
||
/// called with). It is bounded (about a million changes): the oldest go
|
||
/// first. Returns the log's id, which stays the same while it runs (a
|
||
/// second call returns it). Only the world open now has it: a new world
|
||
/// (leaving, rejoining) loses it. Not kept when the world runs in the
|
||
/// game's own frame (`--in-frame`), where `world-log-range` stays none.
|
||
world-log-start: func() -> u32;
|
||
/// Ends the log and forgets what it kept (a different id is ignored).
|
||
world-log-stop: func(id: u32);
|
||
/// What the log covers, as (the earliest tick whose world it can show,
|
||
/// the tick it is at now); none for an unknown id, a log of another
|
||
/// world, or one that has not been taken up yet (the tick after
|
||
/// `world-log-start`). Asking for a time before the earliest shows the
|
||
/// earliest.
|
||
world-log-range: func(id: u32) -> option<tuple<u64, u64>>;
|
||
/// Shows the world as it stood at a game tick, (log id, tick), to the
|
||
/// player's eyes only (AirDef fork, level 18): the changes logged after
|
||
/// it are undone in the game's own copy of the blocks, a little each
|
||
/// frame, and redone as the tick moves on; none (or the mod stopping,
|
||
/// the world changing) puts every block back. The server, the saves,
|
||
/// the player's own collision and the blocks next to the player are
|
||
/// untouched, and changes that arrive meanwhile are kept and shown
|
||
/// when the view ends. Chunks that are not loaded are skipped.
|
||
set-world-time-view: func(view: option<tuple<u32, u64>>);
|
||
}
|
||
|
||
/// What the game calls. Only the hooks `init` asks for are ever called.
|
||
interface events {
|
||
record registration {
|
||
/// Chat commands, without the slash. A name vanilla already uses is
|
||
/// refused (vanilla's command runs).
|
||
commands: list<string>,
|
||
/// Call `tick` every game tick (20 per second while playing).
|
||
tick: bool,
|
||
/// Call `frame` every rendered frame. Budget: 0.1 ms.
|
||
frame: bool,
|
||
/// Call `chat` for each chat line the player receives.
|
||
chat: bool,
|
||
}
|
||
/// Once, after loading. An error keeps the mod off and is shown.
|
||
init: func() -> result<registration, string>;
|
||
/// Each game tick while in a world, with the game's tick counter.
|
||
tick: func(tick: u64);
|
||
/// Each rendered frame, with the seconds since the last one.
|
||
frame: func(seconds: f32);
|
||
/// `/name args`: ok(some(text)) is shown as feedback, err(text) in red.
|
||
command: func(name: string, args: string) -> result<option<string>, string>;
|
||
/// Each chat line the player receives, as plain text.
|
||
chat: func(text: string);
|
||
}
|
||
|
||
/// Capability `recipes` (experimental): the recipes and items the game
|
||
/// knows, for recipe viewers. In single player and on Horizon's servers
|
||
/// they are the world's; on any other server they are vanilla 26.3's (a
|
||
/// client is sent no others), while `known` follows that server's book.
|
||
interface recipes {
|
||
/// An item of `items`, by its index there, with a count and the
|
||
/// components it has beyond the item's own, in vanilla's item syntax
|
||
/// (`[potion_contents={potion:"minecraft:swiftness"}]`), or "".
|
||
record stack {
|
||
item: u32,
|
||
count: u32,
|
||
components: string,
|
||
}
|
||
/// The station a recipe is made at.
|
||
enum kind {
|
||
crafting-shaped,
|
||
crafting-shapeless,
|
||
smelting,
|
||
blasting,
|
||
smoking,
|
||
campfire,
|
||
stonecutting,
|
||
smithing,
|
||
brewing,
|
||
}
|
||
record recipe {
|
||
/// `minecraft:oak_planks`.
|
||
id: string,
|
||
kind: kind,
|
||
/// The recipe book's tab (`crafting_building_blocks`,
|
||
/// `furnace_food`), or "".
|
||
category: string,
|
||
/// Recipes the book shows on one button share a group, or "".
|
||
group: string,
|
||
/// A shaped recipe's grid: `slots` holds its cells row by row.
|
||
/// 0 for the other kinds.
|
||
width: u32,
|
||
height: u32,
|
||
/// Each slot's stacks, any one of which fits; an empty list is an
|
||
/// empty cell. Cooking and stonecutting: the input. Smithing: the
|
||
/// template, the base, the addition. Brewing: the bottle, the
|
||
/// reagent.
|
||
slots: list<list<stack>>,
|
||
/// What it makes; several when that varies (a trim on any armour).
|
||
results: list<stack>,
|
||
/// Cooking: game ticks and experience; 0 for the other kinds.
|
||
cooking-time: u32,
|
||
experience: f32,
|
||
/// The recipe book's id for it (one per way the book shows it), as
|
||
/// `known` lists them; -1 for the kinds the book doesn't show
|
||
/// (campfire, stonecutting, smithing, brewing).
|
||
book-id: s32,
|
||
}
|
||
record item {
|
||
/// `minecraft:diamond`, `<mod>:<path>`.
|
||
id: string,
|
||
/// In the player's language.
|
||
name: string,
|
||
/// Its item tags, without the `#`.
|
||
tags: list<string>,
|
||
}
|
||
/// Every item, in the registry's order: `stack.item` indexes this list.
|
||
items: func() -> list<item>;
|
||
/// Every recipe: the book's in its order, then campfire, stonecutting,
|
||
/// smithing and brewing. They don't change while a world is open.
|
||
all: func() -> list<recipe>;
|
||
/// The `book-id`s of the recipes the player's recipe book holds now.
|
||
known: func() -> list<s32>;
|
||
/// Places a recipe in the open screen's grid as a click in the recipe
|
||
/// book does (`ServerboundPlaceRecipePacket`): the inventory's grid or
|
||
/// a crafting table. `all` places as many as the items allow, as with
|
||
/// Shift. Refused while no such screen is open, for a recipe the
|
||
/// player's book doesn't hold and for one that can't be placed; one
|
||
/// missing items shows as a ghost in the grid, as in the book.
|
||
place: func(book-id: s32, all: bool) -> result<_, string>;
|
||
/// Creative mode only: gives the player the stack, as taking it from
|
||
/// the creative inventory does (`ServerboundSetCreativeModeSlot`): the
|
||
/// selected slot first, then the hotbar, then the inventory. The count
|
||
/// is cut to one stack of the item (64, 16 or 1).
|
||
give: func(stack: stack) -> result<_, string>;
|
||
}
|
||
|
||
/// Capability `ui` (experimental): a recipe viewer's panel beside the
|
||
/// game's inventory and container screens (not the creative inventory), on
|
||
/// the right of the screen. The game draws it with its own widgets and
|
||
/// slots, pages it and keeps its search box; the mod says what it holds.
|
||
/// The first loaded mod with a panel shows.
|
||
interface browser {
|
||
/// An item to show: its id, a count (1 draws none) and its components
|
||
/// beyond the item's own, in vanilla's item syntax, or "".
|
||
record stack {
|
||
item: string,
|
||
count: u32,
|
||
components: string,
|
||
}
|
||
/// A click on an item of the panel, by its index in `set-items`'s list.
|
||
record click {
|
||
index: u32,
|
||
right: bool,
|
||
}
|
||
/// A key the mod registered (`input.register-key`) went down while the
|
||
/// pointer was on an item: a slot of the screen's, or the panel's.
|
||
record item-key {
|
||
key: string,
|
||
stack: stack,
|
||
}
|
||
/// A click on a slot of a recipe the panel shows (`set-recipes`).
|
||
record slot-click {
|
||
/// The recipe's index in `set-recipes`'s list and the slot's in
|
||
/// it; the results come after the slots.
|
||
recipe: u32,
|
||
slot: u32,
|
||
/// The stack the slot showed at that moment.
|
||
stack: stack,
|
||
right: bool,
|
||
}
|
||
variant event {
|
||
clicked(click),
|
||
/// The search box's text, each time the player changes it.
|
||
search(string),
|
||
key(item-key),
|
||
slot-clicked(slot-click),
|
||
/// The action button of the recipe at this index in
|
||
/// `set-recipes`'s list.
|
||
action(u32),
|
||
/// The player turned the recipes' page (`set-recipes`): the index
|
||
/// of the first recipe now shown.
|
||
page(u32),
|
||
/// The back button of `set-recipes`.
|
||
back,
|
||
/// The player picked the tab at this index of `set-recipes`' tabs.
|
||
tab(u32),
|
||
}
|
||
/// How the game lays out a recipe of `set-recipes`.
|
||
enum layout {
|
||
/// A crafting grid of `width` x `height` slots, an arrow and the
|
||
/// result.
|
||
grid,
|
||
/// One input over a flame, an arrow and the result (furnaces,
|
||
/// smokers, campfires).
|
||
cooking,
|
||
/// One input, an arrow and the result (the stonecutter).
|
||
single,
|
||
/// Template, base and addition, an arrow and the result.
|
||
smithing,
|
||
/// A potion and an ingredient, an arrow and the result.
|
||
brewing,
|
||
}
|
||
/// A recipe to show. Each slot, and the result, cycles through its
|
||
/// stacks, one a second; an empty slot shows nothing.
|
||
record recipe-view {
|
||
layout: layout,
|
||
/// The grid's size (`grid` only), at most 3 x 3.
|
||
width: u32,
|
||
height: u32,
|
||
slots: list<list<stack>>,
|
||
results: list<stack>,
|
||
/// A short line under the recipe (a cooking time), or "".
|
||
note: string,
|
||
/// The action button beside it: none, enabled, or shown greyed.
|
||
action: option<bool>,
|
||
}
|
||
/// The panel's items, at most 8192 (an empty list hides the panel).
|
||
set-items: func(items: list<stack>);
|
||
/// Shows these recipes in the panel instead of its items, as many as
|
||
/// fit a page, under `title` and a back button, with a row of `tabs`
|
||
/// (each an icon; `tab` is the selected one) between them; an empty
|
||
/// list of recipes shows the items again. At most 256 recipes and 16
|
||
/// tabs.
|
||
set-recipes: func(title: string, tabs: list<stack>, tab: u32, recipes: list<recipe-view>);
|
||
/// What the player did on the panel since the last poll, at most 256
|
||
/// kept.
|
||
poll: func() -> list<event>;
|
||
}
|
||
|
||
/// Capability `players`, server mods only (manifest `api = "0.3"`,
|
||
/// experimental): the players on the server, and messages to them.
|
||
interface players {
|
||
enum game-mode {
|
||
survival,
|
||
creative,
|
||
adventure,
|
||
spectator,
|
||
}
|
||
record player {
|
||
/// The player's UUID, `xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx`.
|
||
id: string,
|
||
name: string,
|
||
/// Feet position, in blocks.
|
||
x: f64,
|
||
y: f64,
|
||
z: f64,
|
||
/// `minecraft:overworld`, `minecraft:the_nether`, ...
|
||
dimension: string,
|
||
game-mode: game-mode,
|
||
/// Hit points as vanilla counts them: 20 is full health without effects.
|
||
health: f32,
|
||
}
|
||
/// The players online, in the order they joined.
|
||
online: func() -> list<player>;
|
||
/// A system message to one player, after the mod's name; false when no
|
||
/// player with that id is online. Up to 8 messages per call.
|
||
tell: func(player: string, text: string) -> bool;
|
||
/// A system message to every player and the server's log, after the
|
||
/// mod's name. Counts toward the same 8 per call.
|
||
broadcast: func(text: string);
|
||
}
|
||
|
||
/// Capability `world`, server mods only (manifest `api = "0.3"`,
|
||
/// experimental): the blocks of the server's loaded chunks, and changes to
|
||
/// them through the server's own block updates.
|
||
interface %world {
|
||
record block-change {
|
||
x: s32,
|
||
y: s32,
|
||
z: s32,
|
||
/// `minecraft:oak_log[axis=y]`; properties left out take the block's
|
||
/// defaults, `minecraft:stone` alone is the default state.
|
||
state: string,
|
||
}
|
||
/// The block state at a position in a dimension (`minecraft:overworld`,
|
||
/// ...), as `minecraft:oak_log[axis=y]`, as of this call: none where the
|
||
/// server has no chunk loaded there.
|
||
get-block: func(dimension: string, x: s32, y: s32, z: s32) -> option<string>;
|
||
/// The biome at a position (`minecraft:plains`, ...), as the server
|
||
/// stores it (one per 4 x 4 x 4 cell): none where no chunk is loaded.
|
||
get-biome: func(dimension: string, x: s32, y: s32, z: s32) -> option<string>;
|
||
/// Sets blocks as `/setblock` does: the old block entity removed,
|
||
/// neighbours and shapes updated, light, and every player told. Every
|
||
/// state is checked now (an error queues nothing); the changes are made
|
||
/// in order after this call returns, before that dimension's next tick;
|
||
/// one in a chunk not loaded then is skipped. At most 4096 per call.
|
||
set-blocks: func(dimension: string, blocks: list<block-change>) -> result<_, string>;
|
||
}
|
||
|
||
/// What the server calls in a server mod (manifest `api = "0.3"`,
|
||
/// experimental). Only the hooks `init` asks for are ever called. The player
|
||
/// in each event is as the server saw them when it happened.
|
||
interface server-events {
|
||
use players.{player};
|
||
|
||
record block-pos {
|
||
x: s32,
|
||
y: s32,
|
||
z: s32,
|
||
}
|
||
/// What an argument of a command takes. The server sends each command
|
||
/// and its arguments to players' games, whose chat box completes and
|
||
/// colours them as vanilla's; the server parses them before the mod's
|
||
/// `command` hook gets their values.
|
||
variant argument-kind {
|
||
/// One word: letters, digits and `_ - . +`.
|
||
word,
|
||
/// The rest of the line, spaces included: only last.
|
||
text,
|
||
/// A whole number, within the bounds given.
|
||
integer(tuple<option<s32>, option<s32>>),
|
||
/// A number with or without decimals.
|
||
number,
|
||
/// `true` or `false`.
|
||
boolean,
|
||
/// One online player: a name, or `@s` or `@p` (whoever typed it,
|
||
/// as vanilla picks for a player).
|
||
player,
|
||
/// A block position: three whole numbers, each one also `~` or
|
||
/// `~n`, relative to whoever typed it.
|
||
block-pos,
|
||
}
|
||
record argument {
|
||
/// Shown in the chat box's hint (`<height>`) and the key of its value.
|
||
name: string,
|
||
kind: argument-kind,
|
||
/// Optional arguments come after every required one.
|
||
optional: bool,
|
||
}
|
||
record server-command {
|
||
/// Without the slash. A name vanilla already uses is refused
|
||
/// (vanilla's command runs).
|
||
name: string,
|
||
/// In order; none: the command takes nothing after its name. Free
|
||
/// text is one optional `text` argument.
|
||
arguments: list<argument>,
|
||
}
|
||
/// An argument's value, parsed as its kind says.
|
||
variant argument-value {
|
||
word(string),
|
||
text(string),
|
||
integer(s32),
|
||
number(f64),
|
||
boolean(bool),
|
||
player(player),
|
||
block-pos(block-pos),
|
||
}
|
||
record registration {
|
||
/// Commands players may type.
|
||
commands: list<server-command>,
|
||
/// Call `tick` every server tick (20 per second).
|
||
tick: bool,
|
||
/// Call `player-joined` and `player-left`.
|
||
joins: bool,
|
||
/// Call `chat` for each chat message a player sends.
|
||
chat: bool,
|
||
/// Call `block-broken` and `block-placed`.
|
||
blocks: bool,
|
||
}
|
||
/// Once, after loading. An error keeps the mod off and is logged.
|
||
init: func() -> result<registration, string>;
|
||
/// Each server tick, with the server's tick counter.
|
||
tick: func(tick: u64);
|
||
/// A player joined the server; they are in `players.online` already.
|
||
player-joined: func(player: player);
|
||
/// A player left the server; they are no longer in `players.online`.
|
||
player-left: func(player: player);
|
||
/// A chat message a player sent, as plain text.
|
||
chat: func(player: player, text: string);
|
||
/// `/name args` typed by `player`: ok(some(text)) is their feedback,
|
||
/// err(text) their error in red. `values` holds each argument given, by
|
||
/// name, in order (an optional one left out isn't there); a line that
|
||
/// doesn't parse never reaches the mod: the player gets vanilla's error.
|
||
command: func(player: player, name: string, args: string, values: list<tuple<string, argument-value>>) -> result<option<string>, string>;
|
||
/// A player broke the block at `pos` in their dimension: `state` is what
|
||
/// was there, as `minecraft:oak_log[axis=y]`.
|
||
block-broken: func(player: player, pos: block-pos, state: string);
|
||
/// A player placed `state` at `pos` in their dimension.
|
||
block-placed: func(player: player, pos: block-pos, state: string);
|
||
}
|
||
|
||
/// A client mod: runs in the player's game.
|
||
world horizon-mod {
|
||
import log;
|
||
import game;
|
||
import chat;
|
||
import hud;
|
||
import storage;
|
||
import command;
|
||
export events;
|
||
}
|
||
|
||
/// A server mod (manifest `side = "server"`, `api = "0.3"`, experimental):
|
||
/// runs where the world is simulated, on the dedicated server, a LAN host
|
||
/// and single player's own server.
|
||
world horizon-server-mod {
|
||
import log;
|
||
import storage;
|
||
import players;
|
||
import %world;
|
||
export server-events;
|
||
}
|
||
|
||
/// A mod with widgets (capability `ui`): the SDK builds every mod against
|
||
/// this world. Mods built for `horizon-mod` alone (no `ui-events` export)
|
||
/// still load and simply hear nothing of their widgets.
|
||
world horizon-ui-mod {
|
||
include horizon-mod;
|
||
import ui;
|
||
import render;
|
||
import input;
|
||
import recipes;
|
||
import browser;
|
||
export ui-events;
|
||
}
|
||
|
||
/// The game's side of `horizon-ui-mod` beyond `horizon-mod`.
|
||
world ui-host {
|
||
import ui;
|
||
export ui-events;
|
||
}
|
||
|
||
/// The game's side of capability `render` (imports only).
|
||
world render-host {
|
||
import render;
|
||
import input;
|
||
}
|
||
|
||
/// The game's side of capability `recipes` (imports only).
|
||
world recipes-host {
|
||
import recipes;
|
||
import browser;
|
||
}
|