Docs menu

API reference

Mod API reference

The contract between Horizon and its mods: the WIT package horizon:mods@0.1.0, every interface, type, function and hook in it, and the capabilities a manifest may list. The guide is mods.md; stability and versions: stability.md. Manifest api lines this game serves: 0.1, 0.2, 0.3.

Capabilities

In capabilitiesGrantsThe player reads "May …"
game-readgamesee your position, health and the time
chatchatshow you chat messages
hudhuddraw text on your screen
storagestoragesave its own settings to disk
commandcommandrun commands as you, with your permissions
registriesdata files (assets/, data/), no interfaceadd blocks and items to your worlds
uiuishow its own screens and a settings page
renderrenderdraw on your screen, shake and zoom the camera
inputinputsee the keys you hold and your clicks, take over the use button on its own items and the mouse wheel, and add keys
playersplayerssee who is on the server and message them

World horizon-mod

A client mod: runs in the player's game.

  • Imports (what the game offers): log, game, chat, hud, storage, command
  • Exports (what the mod provides): events

World horizon-server-mod

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.

  • Imports (what the game offers): log, storage, players
  • Exports (what the mod provides): server-events

World horizon-ui-mod

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.

  • Imports (what the game offers): ui, render, input, log, game, chat, hud, storage, command
  • Exports (what the mod provides): ui-events, events

World ui-host

The game's side of horizon-ui-mod beyond horizon-mod.

  • Imports (what the game offers): ui
  • Exports (what the mod provides): ui-events

World render-host

The game's side of capability render (imports only).

  • Imports (what the game offers): render, input
  • Exports (what the mod provides):

log

Access: always granted.

The mod's log, in the game's log under the mod's id. Always granted.

enum level

Case
debug
info
warn
error
FunctionSignatureWhat it does
writefunc(level: level, message: string)One line in the game's log as [mod <id>] message, at that level.

game

Access: capability game-read.

Capability game-read: the local player, the world clock and the block the player looks at.

record player

FieldType
xf64Feet position, in blocks.
yf64
zf64
yawf32Degrees, as F3 shows them.
pitchf32Degrees: -90 looks straight up, 90 straight down.
healthf32Hit points as vanilla counts them: 20 is full health without effects.
foodu320 to 20, as the hunger bar.
dimensionstringminecraft:overworld, minecraft:the_nether, ...

record clock

FieldType
game-timeu64Ticks since the world was created.
day-timeu6424000 ticks per day; 0 is 6:00 on the first day.

record hit

A block along the player's view.

FieldType
block-xs32The block hit.
block-ys32
block-zs32
xf64The point on its face where the view meets it.
yf64
zf64
blockstringminecraft:stone, ...
FunctionSignatureWhat it does
get-playerfunc() -> option<player>None on the title screen.
get-clockfunc() -> option<clock>None on the title screen.
raycastfunc(distance: f32) -> option<hit>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.

chat

Access: capability chat.

Capability chat: messages only the local player sees.

FunctionSignatureWhat it does
showfunc(text: string)Shown in chat after the mod's name, like a system message.

hud

Access: capability hud.

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).

enum corner

Case
top-left
top-right
bottom-left
bottom-right

record line

FieldType
textstringPlain text, up to 256 characters.
coloru320xRRGGBB.
FunctionSignatureWhat it does
set-panelfunc(corner: corner, lines: list<line>)Replaces the mod's panel: up to 16 lines in that corner of the screen.
clearfunc()Removes the mod's panel.

storage

Access: capability storage.

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.

FunctionSignatureWhat it does
getfunc(key: string) -> option<list<u8>>None if key has never been set, or the key is not well-formed.
setfunc(key: string, value: list<u8>) -> result<_, string>Errs on a malformed key or over quota (bytes for the whole mod).
deletefunc(key: string)No error if key was already absent.

command

Access: capability command.

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.

FunctionSignatureWhat it does
runfunc(line: string)line without its slash; its feedback goes to the chat as if typed.

ui

Access: capability ui.

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.

record text-widget

A line of text.

FieldType
idu32The mod's own name for the widget; ui-events calls echo it.
textstringUp to 256 characters.
coloru320xRRGGBB; 0 is the menus' white.

record item-widget

An item's icon and a name beside it, as recipe viewers show them.

FieldType
idu32The mod's own name for the widget.
itemstringminecraft:diamond, <mod>:<path>; an unknown id draws a "?".
namestringThe name shown beside the icon (empty: the item's own).

record list-widget

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.

FieldType
idu32The mod's own name for the widget; ui-events::select echoes it.
rowslist<string>The rows' texts, at most 512, each up to 256 characters.
selectedoption<u32>The row to mark as the current choice, if any.

record button-widget

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").

FieldType
idu32The mod's own name for the widget.
labelstringUp to 256 characters.

variant widget

CasePayload
texttext-widgetText the player reads.
buttonbutton-widgetA button.
itemitem-widgetAn item's icon and name.
listlist-widgetRows the player picks from.

record screen

A screen the mod owns: a title over widgets stacked down the middle, the Done button the game adds, and Esc to leave it.

FieldType
titlestringIts title, up to 256 characters.
widgetslist<widget>Its widgets, in order, at most 64.
FunctionSignatureWhat it does
open-screenfunc(screen: screen)Show screen over the game; a second call while it is open replaces it. Only the last call of one hook counts.
close-screenfunc()Close the mod's screen when it is open (the mod hears no closed for this: it was its own doing).
set-settingsfunc(widgets: list<widget>)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.

ui-events

Access: exported by the mod: the game calls it.

What the game calls on a mod that shows widgets (capability ui): what the player did with them.

FunctionSignatureWhat it does
selectfunc(id: u32, row: u32)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.
closedfunc()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.
settings-openedfunc()The player opened the mod's settings page in Options > Mods: call ui::set-settings now to fill it with fresh widgets.

input

Access: capability input.

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.

record held-item

The main hand's stack.

FieldType
idstringminecraft:spyglass, <mod>:<path>.
countu32
slotu32The hotbar slot, 0 to 8.

record item-use

FieldType
itemheld-item
ticksu32Game ticks the button was held (0 on use-start).

variant event

CasePayload
use-startitem-useThe 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-stopitem-useIt came up again, or the item left the hand, or a screen opened.
key-downstringA 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-upstring
wheelf32Mouse wheel steps while the mod holds the wheel (claim-wheel): positive away from the player, as the hotbar reads them.

record mapping-state

A mapping as the player has bound it.

FieldType
labelstringThe bound key's name as Controls shows it: W, Space, LMB.
downboolHeld down now (as of this frame for a mod with a frame hook, else this tick).
FunctionSignatureWhat it does
claim-itemsfunc(ids: list<string>)The items whose use the mod handles instead of the game, by id (at most 64). Replaces the previous list.
register-keyfunc(name: string, label: string, key: string) -> result<_, 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.
heldfunc() -> option<held-item>The main hand's stack, as of this tick; none when it is empty.
pollfunc() -> list<event>The events since the last call, oldest first.
claim-wheelfunc(on: bool)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.
mappingfunc(name: string) -> option<mapping-state>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.
clicks-per-secondfunc() -> tuple<u32, u32>Clicks of the attack and use buttons in the last second.

render

Access: capability render.

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.

enum corner

A corner of the screen, as hud's panels use them.

Case
top-left
top-right
bottom-left
bottom-right

record rect

A rectangle in GUI pixels: the top left corner and the size.

FieldType
xf32
yf32
wf32
hf32

record point

A point in GUI pixels from the screen's top left.

FieldType
xf32
yf32

record fill-shape

FieldType
rectrect
coloru320xAARRGGBB.

record quad-shape

Any four-cornered shape (a wheel's segment, an arrow): the corners in order round it.

FieldType
cornerstuple<point, point, point, point>
coloru320xAARRGGBB.

record sprite-shape

FieldType
spritestringOne 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.
rectrect
coloru32A tint, 0xAARRGGBB: 0xFFFFFFFF draws it as it is.

record item-shape

FieldType
itemstringminecraft:diamond, <mod>:<path>; an unknown one draws nothing.
atpointThe icon's top left.
scalef321.0 is the hotbar's 16 × 16.

record text-shape

FieldType
textstringUp to 256 characters, one line.
atpoint
coloru320xRRGGBB, as hud's lines.
centeredboolCentred on at.x instead of starting there.
shadowbool

variant shape

CasePayload
fillfill-shape
quadquad-shape
spritesprite-shape
itemitem-shape
texttext-shape

record frame-rate

FieldType
fpsu32Frames drawn in the last second.
minu32The slowest frame's rate, and the 1% low (the 99th percentile frame time's rate), over the last 5 seconds.
lowu32

record zoom

FieldType
factorf32The field of view is divided by it: 1 is none, at most 10.
smoothboolEase in and out through the game's field-of-view easing, as the spyglass does, instead of at once.
turnf32Mouse turning is multiplied by it while zoomed: 1 keeps the player's sensitivity, at least 0.05.

record minimap

FieldType
cornercorner
sizef32Its side in GUI pixels, 16 to 256.
blocks-per-pixelf32World blocks per map pixel, 0.5 to 4; the map is 128 × 128 pixels.
rotateboolThe 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.
roundboolRound, the corners left clear; otherwise square.
FunctionSignatureWhat it does
set-hudfunc(shapes: list<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.
gui-sizefunc() -> tuple<f32, f32>The screen's size in GUI pixels (width, height), as of this tick.
shakefunc(strength: f32, seconds: 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).
set-cornerfunc(corner: corner, width: f32, height: f32, shapes: list<shape>)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.
clear-cornerfunc()Removes the mod's corner panel.
text-widthfunc(text: string) -> f32The 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.
frame-statsfunc() -> frame-rateThe game's frame counter, recomputed twice a second.
set-zoomfunc(zoom: zoom)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-minimapfunc(minimap: option<minimap>)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.

events

Access: exported by the mod: the game calls it.

What the game calls. Only the hooks init asks for are ever called.

record registration

FieldType
commandslist<string>Chat commands, without the slash. A name vanilla already uses is refused (vanilla's command runs).
tickboolCall tick every game tick (20 per second while playing).
frameboolCall frame every rendered frame. Budget: 0.1 ms.
chatboolCall chat for each chat line the player receives.
FunctionSignatureWhat it does
initfunc() -> result<registration, string>Once, after loading. An error keeps the mod off and is shown.
tickfunc(tick: u64)Each game tick while in a world, with the game's tick counter.
framefunc(seconds: f32)Each rendered frame, with the seconds since the last one.
commandfunc(name: string, args: string) -> result<option<string>, string>/name args: ok(some(text)) is shown as feedback, err(text) in red.
chatfunc(text: string)Each chat line the player receives, as plain text.

players

Access: capability players.

Capability players, server mods only (manifest api = "0.3", experimental): the players on the server, and messages to them.

enum game-mode

Case
survival
creative
adventure
spectator

record player

FieldType
idstringThe player's UUID, xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.
namestring
xf64Feet position, in blocks.
yf64
zf64
dimensionstringminecraft:overworld, minecraft:the_nether, ...
game-modegame-mode
healthf32Hit points as vanilla counts them: 20 is full health without effects.
FunctionSignatureWhat it does
onlinefunc() -> list<player>The players online, in the order they joined.
tellfunc(player: string, text: string) -> boolA 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.
broadcastfunc(text: string)A system message to every player and the server's log, after the mod's name. Counts toward the same 8 per call.

server-events

Access: exported by the mod: the game calls it.

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.

type player

type player = player

record registration

FieldType
commandslist<string>Commands players may type, without the slash. A name vanilla already uses is refused (vanilla's command runs).
tickboolCall tick every server tick (20 per second).
joinsboolCall player-joined and player-left.
chatboolCall chat for each chat message a player sends.
blocksboolCall block-broken and block-placed.

record block-pos

FieldType
xs32
ys32
zs32
FunctionSignatureWhat it does
initfunc() -> result<registration, string>Once, after loading. An error keeps the mod off and is logged.
tickfunc(tick: u64)Each server tick, with the server's tick counter.
player-joinedfunc(player: player)A player joined the server; they are in players.online already.
player-leftfunc(player: player)A player left the server; they are no longer in players.online.
chatfunc(player: player, text: string)A chat message a player sent, as plain text.
commandfunc(player: player, name: string, args: string) -> result<option<string>, string>/name args typed by player: ok(some(text)) is their feedback, err(text) their error in red.
block-brokenfunc(player: player, pos: block-pos, state: string)A player broke the block at pos in their dimension: state is what was there, as minecraft:oak_log[axis=y].
block-placedfunc(player: player, pos: block-pos, state: string)A player placed state at pos in their dimension.

Edit this page on GitHub · Spotted something wrong? Open an issue or ask on Discord.

Not an official Minecraft product. Not approved by or associated with Mojang or Microsoft.