// SPDX-FileCopyrightText: 2026 Paula Wisnievski // SPDX-License-Identifier: AGPL-3.0-or-later // types every side of a mod shares. these are the api mods see, not the engine's own classes: // items are { id, count, data } here, like on the network export type Id = string; // a biome's season, from its json. see docs/modding/worldgen/biomes.md export type Season = "spring" | "summer" | "autumn" | "winter"; export interface ItemStack { readonly id: Id; count: number; // any json value, set by server scripts data?: unknown; } // the registries tags are for, see docs/modding/resources/tags.md export type TagRegistry = "blocks" | "items" | "entities" | "biomes"; // every mod's tags, the same on the server and every client. tags can be written with or without their # export interface TagApi { // whether any mod defines the tag and it loaded exists(registry: TagRegistry, tag: Id): boolean; // whether id is in the tag, like has("items", "bworld:planks", "bworld:birch_planks"). false for a tag nobody defines has(registry: TagRegistry, tag: Id, id: Id): boolean; // every id in the tag, including its tags' ids, in the order they were added. empty for a tag nobody defines get(registry: TagRegistry, tag: Id): Id[]; // every tag id is in of(registry: TagRegistry, id: Id): Id[]; // the items a recipe's item choice stands for, once each: an item id or "#tag", or a list of those expand(choice: Id | Id[]): Id[]; } export interface ModInfo { readonly id: string; readonly version: string; } export interface Position { x: number; y: number; z: number; } export type Face = "west" | "east" | "bottom" | "top" | "north" | "south"; // KeyboardEvent.code values, like "KeyE" or "Digit1" export type KeyCode = string; export type Unsubscribe = () => void; export interface EventSignal { subscribe(handler: (event: T) => void): Unsubscribe; } // shared scripts: block rules that run on the server and on every client, so a client places blocks the way the // server will, like minecraft's Block code that both sides run. see docs/modding/gettingstarted/modfiles.md export interface SharedContext { readonly mod: ModInfo; // which one this is running on. the server's say is final, clients only guess ahead of it readonly side: "server" | "client"; readonly tags: TagApi; // the world rules look at and change. on a client it's what that client sees, and what rules change there is a // guess until the server says what really happened. only for use in rules, not during setup readonly world: SharedWorld; // every block any mod registered, like the server's and clients' ctx.blocks. for rules that look at what's around, // like a shaft lining up with the axle of the block it's placed against readonly blocks: { exists(id: Id): boolean; // the components its json lists and their params, a copy components(id: Id): Record; }; readonly components: { // the rules of a block component, the same id the server script registers the rest of it under // deno-lint-ignore no-explicit-any register_block

(id: Id, rules: BlockRules

): void; }; } export interface SharedWorld { // undefined when the chunk isn't loaded, "bworld:air" for air get_block(x: number, y: number, z: number): Id | undefined; get_state(x: number, y: number, z: number, name: string): number | undefined; // changing what a block is tells the blocks beside it, see BlockRules.on_neighbor_change set_state(x: number, y: number, z: number, name: string, value: number): boolean; // whether the block's side is a full square things can attach to, like minecraft's isFaceSturdy: its collision // shape covers the whole face. false for air, plants, water and the sides of a slab is_face_sturdy(x: number, y: number, z: number, face: Face): boolean; // the column's biome, like "bworld:plains", and that biome's season. undefined when the chunk isn't loaded biome_at(x: number, z: number): Id | undefined; season_at(x: number, z: number): Season | undefined; } // a block in the world, for rules export interface SharedBlock extends Position { readonly id: Id; } // a player placing a block at x y z by clicking face of the block next to it, at hit (0 to 1 on each axis of that // block), like minecraft's BlockPlaceContext. facing is the way the player looks along the ground, and looking the face // of the six they look most toward, up and down too, like getNearestLookingDirection. sneaking is whether they hold the // sneak key, for blocks placed another way round when they do export interface BlockPlacement extends Position { readonly face: Face; readonly hit: readonly [number, number, number]; readonly facing: "north" | "east" | "south" | "west"; readonly looking: Face; readonly sneaking: boolean; } // a player right clicking face of a block, at hit (0 to 1 on each axis of the block), like minecraft's BlockHitResult. // facing is the way the player looks, along the ground, and sneaking whether they hold the sneak key. sneaking with // an item in hand doesn't interact at all, the item is used or placed instead export interface BlockInteraction { readonly face: Face; readonly hit: readonly [number, number, number]; readonly facing: "north" | "east" | "south" | "west"; readonly sneaking: boolean; } // P is the component's params from the block json // deno-lint-ignore no-explicit-any export interface BlockRules

{ // the states it's placed with when a player places it, like minecraft's getStateForPlacement. states it doesn't // return keep their defaults, and a 2 bit "facing" faces the player. false when it can't go there, so it isn't // placed, like getStateForPlacement returning null state_for_placement?(placement: BlockPlacement, params: P): Record | false | void; // a block next to it (on any of the 6 sides) was placed, broken or changed its states, like minecraft's // updateShape. neighbor is where, and what's there now on_neighbor_change?(block: SharedBlock, params: P, neighbor: SharedBlock): void; // a player right clicks it, like minecraft's useWithoutItem: changes only its states and its neighbors', which // the clicking client shows right away instead of waiting for the server. return true if it did something, then // nothing is placed. the server runs the server script's on_interact too on_interact?(block: SharedBlock, params: P, interaction: BlockInteraction): boolean | void; }