Skip to content

events ​

INFO

Başvuru metni WIT dosyalarından otomatik üretildiği için İngilizce.

Game events with priorities and cancellation. A mod subscribes with subscribe; the host then calls the exported guest.handle-event once per event and subscription. Handlers run on the game / server main thread, one at a time.

Package blockheads:api@0.3.1 · Lua table bh.events · WIT source

Uses: types.{mod-id, priority, value, api-error, pos}, players.{player}

Types ​

subscription type ​

txt
type subscription = u32;

Identifies one subscription of the calling mod.

event-kind enum ​

The built-in events. Cases are only ever appended (0.1: player-join .. world-save; 0.2: player-pre-login .. player-move).

CaseDescription
player-joinA player finished joining (after approval and the world summary). Server only.
player-quitA player left or was kicked. Server only.
chatA chat message, before it is shown or broadcast. Cancellable; the text can be replaced.
commandA /command line, before any command handler runs. Cancellable (cancel = swallow the command).
tickOne world step (0.2 s on the server). Fires after the world update.
world-loadedThe world finished loading; world functions are usable from now on.
world-saveThe world is being saved (fires before and after, see save-phase).
player-pre-login(0.2) A player passed every vanilla join check and is about to be approved. Cancellable: the player is rejected with reject-reason (vanilla clients show their own text for it). Server only.
block-place(0.2) A player places a block or item into a tile. Cancellable: the tile stays as it is and the client is resynced exactly as for a protected tile. Server only.
block-break(0.2) A player removes a block, its contents, water or a back wall. Cancellable (same resync). Server only.
block-changed(0.2) A tile changed, by a player or by the simulation (growth, physics, NPCs). Monitor only: the outcome is ignored because cancelling simulation changes would desync clients. Server only.
object-place(0.2) A player places a workbench or an interaction object (chest, sign, door, bed, ...). Cancellable. Server only.
damage(0.2) A blockhead is about to take damage. Cancellable; the amount can be replaced. Server only.
death(0.2) A blockhead died. Server only.
player-move(0.2) A player's blockhead entered another tile. Server only.

player-join-event record ​

Fired as player-join.

FieldTypeDescription
playerborrow<player>

player-quit-event record ​

Fired as player-quit.

FieldTypeDescription
playerborrow<player>
was-kickboolTrue when the player was kicked or banned rather than leaving.

chat-event record ​

Fired as chat. The handler may cancel the message or return replacement text in its outcome.

FieldTypeDescription
playerborrow<player>
textstringThe message after the server's profanity filter and after earlier handlers' changes.
cancelledboolTrue if an earlier handler cancelled it.

command-sender variant ​

Who issued a command.

CasePayloadDescription
console–The server console (or the host app's console box).
playerborrow<player>A player in chat.

command-event record ​

Fired as command.

FieldTypeDescription
sendercommand-sender
namestringThe command name without the leading /, lower-cased.
argslist<string>The rest of the line split on spaces.
rawstringThe full line as typed, including the /.
cancelledbool

tick-event record ​

Fired as tick.

FieldTypeDescription
ticku64Steps since the world was loaded, starting at 1.
dtf32Step length in seconds (0.2 on the server).

world-loaded-event record ​

Fired as world-loaded.

FieldTypeDescription
world-namestringThe world's display name.
world-idstringThe world's save id (directory name on the server).

save-phase enum ​

Before or after a save.

CaseDescription
pre
post

world-save-event record ​

Fired as world-save. Flush your storage on pre.

FieldTypeDescription
phasesave-phase

reject-reason enum ​

(0.2) Vanilla rejection reasons a player-pre-login handler may choose (the 0x26 reason byte in brackets).

CaseDescription
client-too-old[3] The client is too old.
server-full[5] The server is full.
blacklisted[6] Blacklisted.
not-whitelisted[7] Not on the whitelist.
incorrect-password[10] Wrong password.
kicked[11] Kicked. The default when a handler cancels without choosing.
banned[12] Banned.
invalid-username[14] Invalid user name.
still-loading[15] The server is still loading.

player-pre-login-event record ​

(0.2) Fired as player-pre-login. The player is not online yet, so it is identified by id, not by handle.

FieldTypeDescription
player-idstringThe player's id (the vanilla playerID).
aliasstringThe alias the player joins with.
cancelledbool
reasonreject-reasonThe reason sent if the event ends up cancelled (set it with the reject-reason mutation).

block-place-event record ​

(0.2) Fired as block-place.

FieldTypeDescription
playerborrow<player>
atposThe target tile.
itemu32The item type being placed (vanilla item ids).
data-au16Item data A (for example the paint colour or rotation).
data-bu16Item data B.
cancelledbool

break-layer enum ​

(0.2) What a block-break removes.

CaseDescription
blockThe tile, its contents or water.
back-wallThe back wall.

block-break-event record ​

(0.2) Fired as block-break.

FieldTypeDescription
playerborrow<player>
atpos
layerbreak-layer
tileu32The tile type before the removal.
cancelledbool

block-changed-event record ​

(0.2) Fired as block-changed (monitor only).

FieldTypeDescription
atpos
tileu32The new tile type.
playeroption<borrow<player>>The player who caused the change, when known.

object-kind enum ​

(0.2) What an object-place places.

CaseDescription
workbenchA workbench / crafting station; item is the workbench type.
interaction-objectAn interaction object (chest, sign, door, bed, ...); item is its item type.

object-place-event record ​

(0.2) Fired as object-place.

FieldTypeDescription
playerborrow<player>
atpos
objectobject-kind
itemu32
cancelledbool

damage-event record ​

(0.2) Fired as damage.

FieldTypeDescription
playeroption<borrow<player>>The owner of the damaged blockhead.
blockheadu64The blockhead's unique id.
amountf32The damage (1.0 = a full health bar) after earlier handlers' changes, before armour and world rules.
attackeroption<borrow<player>>The attacking player for PvP damage.
cancelledbool

death-event record ​

(0.2) Fired as death.

FieldTypeDescription
playeroption<borrow<player>>The owner of the blockhead.
blockheadu64The blockhead's unique id.

player-move-event record ​

(0.2) Fired as player-move.

FieldTypeDescription
playerborrow<player>
frompos
topos

custom-event record ​

A custom event fired by a mod with fire-custom.

FieldTypeDescription
namestringNamespaced name, <mod-id>:<name>.
sourcemod-idThe mod that fired it.
payloadvalueCanonical CBOR payload; its shape is documented by the firing mod (usually in its wit/).
cancelledbool

event variant ​

One event delivered to guest.handle-event.

CasePayloadDescription
player-joinplayer-join-event
player-quitplayer-quit-event
chatchat-event
commandcommand-event
ticktick-event
world-loadedworld-loaded-event
world-saveworld-save-event
customcustom-event
player-pre-loginplayer-pre-login-event(0.2)
block-placeblock-place-event(0.2)
block-breakblock-break-event(0.2)
block-changedblock-changed-event(0.2)
object-placeobject-place-event(0.2)
damagedamage-event(0.2)
deathdeath-event(0.2)
player-moveplayer-move-event(0.2)

mutation variant ​

A change a handler wants to make to a mutable event.

CasePayloadDescription
chat-textstringReplace the chat text (only for chat).
custom-payloadvalueReplace the custom payload (only for custom).
reject-reasonreject-reason(0.2) The rejection reason (only for player-pre-login).
damage-amountf32(0.2) The damage amount, finite and >= 0 (only for damage).

outcome record ​

What a handler returns. Ignored for monitor handlers and for events that are not cancellable.

FieldTypeDescription
cancelledboolThe new cancelled state. Returning false on a cancelled event un-cancels it.
mutationoption<mutation>An optional change; a mutation that does not fit the event is ignored with a warning.

Functions ​

subscribe function ​

txt
subscribe: func(kind: event-kind, priority: priority, ignore-cancelled: bool) -> result<subscription, api-error>;

Subscribes to a built-in event. ignore-cancelled skips this handler while the event is cancelled.

subscribe-custom function ​

txt
subscribe-custom: func(name: string, priority: priority, ignore-cancelled: bool) -> result<subscription, api-error>;

Subscribes to a custom event by its full name (<mod-id>:<name>). Any mod's events may be subscribed.

unsubscribe function ​

txt
unsubscribe: func(sub: subscription) -> bool;

Removes a subscription. Returns false if it did not exist.

fire-custom function ​

txt
fire-custom: func(name: string, payload: value) -> result<bool, api-error>;

Fires a custom event. name must start with the caller's mod id and a colon. Listeners run synchronously with the normal priority rules; the result is true if the event ended up cancelled. Handlers of mods that are on the call stack (including the caller) get the event after the outermost call returns, with their outcome ignored.

Resmî olmayan topluluk projesi. Majic Jungle Software veya Noodlecake ile bağlantısı yoktur. Oyun dosyası içermez.