목차

Blocks

Blocks are owned by the server (Umbra). You describe a block as data (shape, hardness, drops) and write its behaviour as hooks the server calls. The same .wasm runs on both the client and the server. Singleplayer runs an embedded Umbra, so blocks work there too. On Paper or vanilla servers this feature is off.

Shape of a block mod

It is the same veil_mod!. Put the block table in the content: field and the server hook in block_hook:, and the macro picks version 5 (one wasm for client and server). A client body can sit alongside as main:; the easy_block example does that.

FieldRuns onDoes
content: TABLEclient and serverThe block table (decl::Content). The macro registers it, sets up models and checks it at compile time
common: fclient and serverRegister things by hand (reg::block_def) when you do not use a table
client: fclient onlySet appearance by hand (block::model)
block_hook: fserver onlyThe block hook, fn(&srvblock::Hook) -> i32
groups: [...]The permission groups you use (see below)

Fields can come in any order.

One rule matters more than any other: registration must be unconditional and happen in the same order on both sides. The client and server compare a hash of what was registered when you connect. If they differ, the connection is dropped with "mod version differs from the server". Never register something on one side only.

The minimal block: a decl::Content table

Each block is written once, in a table. Registration (both sides), appearance (client) and the hook number all come from that one entry. This is what mc189 mod new my_block --template block generates (light level 15, plays a sound on right-click; assets/glow.png is a 16×16 placeholder):

//! my block — block mod template. The same wasm runs on client and server.
#![no_std]
use mc189_mod_sdk::prelude::*;
use mc189_mod_sdk::srvblock::{ev, Hook};

/// Definition fields are listed below. "name" is filled in from the table.
const CONTENT: Content = Content::new().blocks(&[
    Block::new("glow_block", r#"{"light":15,"hardness":0.5,"sound":"glass","hooks":["use"]}"#).cube("glow.png"),
]);
const GLOW: u32 = CONTENT.block("glow_block");

/// Server hook: play a sound on right-click
fn on_block(h: &Hook) -> i32 {
    if h.blk == GLOW && h.ev == ev::USE {
        srvblock::sound(h.x as f32 + 0.5, h.y as f32 + 0.5, h.z as f32 + 0.5, "note.pling", 1.0, 1.4);
        return 1;
    }
    0
}

veil_mod! {
    id: "my_block",
    name: "my block",
    version: "0.1.0",
    description: "my block",
    authors: ["me"],
    groups: ["base", "content", "server"],
    res: ["glow.png" => include_bytes!("../assets/glow.png")],
    content: CONTENT,
    block_hook: on_block,
}
  • content: CONTENT checks the table when you compile: names must match [a-z0-9_./]{1,64}, must not clash across kinds, definitions must start with {, per_meta must have 1 to 16 models, and there are limits of 4096 registrations and 1024 recipes.
  • CONTENT.block("glow_block") is the block's hook number. A name that is not in the table is a compile error.
  • You can leave "name" out of the definition JSON; the table entry's name is inserted. If you do write it, it must match.
  • Appearance: .cube("tex.png") puts one texture on all six faces, .model("model", "tex.png") uses one model, .per_meta(&["m0", "m1", …], "tex.png") gives each state its own model.
  • In game the block is called modid:name, here my_block:glow_block.
  • groups must list every group you use: base, content for reg and block, server for srvblock. A missing one makes the game refuse to link the mod.

The hook number trap. The number a hook receives (srvblock::Hook::blk, srvitem::Hook::item, srvent::Hook::ent) is not a per-kind index. It counts blocks, items and mobs together, in registration order. With two blocks and one item, the item is number 2. Never hard-code 0 or 1; ask the table with CONTENT.block("…"), CONTENT.item("…") or CONTENT.mob("…").

Definition fields

These are the fields of the JSON passed to reg::block_def. Up to 64 KiB. The normalised bytes go into the registration hash, so both sides must get identical JSON.

FieldDefaultMeaning
namerequired (optional in a decl table)[a-z0-9_./]{1,64}
displaynone (registry name)Shown name, 1 to 64 characters. See below
states11 to 16 (the number of meta values)
collisionfull cubeList of boxes [[x0,y0,z0,x1,y1,z1], …] for all states, or {"meta": list}. Coordinates 0 to 1, up to 16 boxes. Empty list = walk-through
outlinebox around the collisionOne box, or {"meta": box}
hardness, resistance1.5, hardness × 5-1 = unbreakable. resistance uses the 1.8 blockResistance scale (stone is 30)
pushnormalPiston behaviour: normal, destroy (breaks and drops), block (immovable)
tool, harvest_levelpickaxe, -1pickaxe, axe, shovel, sword, shears, none; level -1 to 3 (-1 = drops even by hand)
light, opacity, translucent0, 255 for full opaque blocks, false
soundstonestone, wood, gravel, grass, metal, glass, cloth, sand, snow, ladder, anvil, slime
placefixedfixed, facing4, half, facing4_half (sets meta from the facing or half when placed)
drops[{"item":"self"}]Up to 8 of {item, count: N or [min,max], meta, chance}. item is self, minecraft:name or modid:name
fallbacknonePlaceholder shown to vanilla clients only. It is not what 月蝕 players see
hooks[]Events to receive: added, removed, use, neighbor, random_tick, scheduled_tick, entity_inside, placed_by, harvested, caught_fire
fire_spread, flammability0, 0Vanilla fire values (planks 5/20, TNT 15/100), 0 to 300
power_sourcefalseRedstone power source
comparatorfalseGives a comparator value through comparator_out
tilefalseUses tile entity bytes (te_set, te_sync)
inventorynoneA machine with slots (together with tile: true); see the Korean gui guide

Unknown values make registration fail. Unknown field names are silently ignored, so a typo like "ligth" is caught nowhere (not by the build, mod check or registration).

The shown name is "display" (1 to 64 characters, the same key as display in item_def). The block and its block item (inventory, tooltip, creative search) show it; without it the registry name modid:name shows as is. The block item is made by the block registration, so an item_def with the same name is rejected as a duplicate — name blocks with display in block_def. item_display is not a name: it is the model transform of the held/GUI block item (vanilla ItemCameraTransforms).

Name order (the same path as vanilla 1.8.9 StatCollector/LanguageMap, example mods-examples/names_demo):

  1. Resource-pack lang key — blocks tile.<modid>:<name>.name, items item.<modid>:<name>.name
  2. "display" in the definition JSON
  3. The registry name modid:name

Per-language names come from resource packs. As in vanilla 1.8.9, assets/<any namespace>/lang/<lang>.lang is read from every namespace. File names are case-exact (ko_KR.lang, en_US.lang), one key=value per line. en_US is read first and the selected language overrides it; higher packs override lower ones. The 1.8.9 build does not read .json lang files (1.12.2 uses lowercase ko_kr.lang, 1.16.5 uses ko_kr.json). A mod wasm cannot ship its own lang file yet.

Vanilla names are overridden the same way, with the vanilla keys: the stone item is tile.stone.stone.name; tile.stone.name is not the stone item's name.

Recipes for blocks go in the same table with .recipes(&[…]); the result is "modid:blockname" (fields as in items.md).

Hooks

Only events listed in hooks reach block_hook. Compare h.ev against srvblock::ev::*. The return value is only looked at for USE: returning 1 means "handled", and the held item is not placed.

evWhena / b
ADDEDThe block was placedold state
REMOVEDThe block went awaynew state
USERight-clickplayer eid / face
NEIGHBORA neighbour changed
RANDOM_TICKRandom tick
SCHEDULED_TICKA tick you booked with srvblock::schedule
ENTITY_INSIDEA player overlaps the block (players only)eid
PLACED_BYWho placed iteid / face
HARVESTEDJust before it breakseid

h.x, h.y, h.z, h.meta give the position and state; h.blk is the combined registration number described above. Server state is only reachable inside a hook: calling srvblock functions anywhere else returns -1 or None. Reading and writing the world (get, set, schedule), redstone (power_*), tile bytes (te_get, te_set, te_sync), sounds, particles and drops are listed under srvblock in ../../reference.md.

There is a time budget: the server gives each mod about 2 ms per tick. Go over and the rest of that tick's hooks are skipped; keep going over and the mod is unloaded.

Doing it by hand, without a table

decl is a thin layer over the functions below. It uses the same imports (mc_reg, mc_block) and the same JSON bytes, so registering by hand gives the same result, and you can mix both styles in one mod. When you register by hand you have to count hook numbers yourself, in registration order.

#![no_std]
use mc189_mod_sdk::prelude::*;
use mc189_mod_sdk::srvblock::{self, ev, Hook};
use mc189_mod_sdk::block;

const LAMP: &str = r#"{"name":"moon_lamp","light":15,"hardness":0.3,"tool":"pickaxe","sound":"glass","hooks":["use"],"drops":[{"item":"self"}],"fallback":"minecraft:glowstone"}"#;

fn common() {
    // same order on both sides, no conditions
    reg::block_def(LAMP);
}

fn client() {
    // name, meta (None = every state), model file ("" = full cube), texture
    block::model("moon_lamp", None, "", "lamp.png");
}

fn on_block(h: &Hook) -> i32 {
    if h.ev == ev::USE {
        srvblock::sound(h.x as f32 + 0.5, h.y as f32 + 0.5, h.z as f32 + 0.5, "note.pling", 1.0, 1.4);
    }
    0
}

veil_mod! {
    id: "moon_lamp",
    name: "Moon lamp",
    version: "1.0.0",
    description: "A glowing block that chimes when right-clicked",
    authors: ["me"],
    groups: ["base", "content", "server"],
    common: common,
    client: client,
    block_hook: on_block,
    res: ["lamp.png" => include_bytes!("lamp.png")],
}

Numeric block and item ids are assigned by the server per world and sent to the client when it connects. Do not hard-code them; look them up by name (srvblock::num("moon_lamp") is this world's number).

Common pitfalls

  • Kicked on connect with "mod version differs from the server". The client and server wasm differ (they are compared by sha256), or registration produced different results on the two sides. Look for an if around registration.
  • Link refused ("... is in group ... but groups does not list it"). Add content or server to groups.
  • The texture is wrong or missing. The texture name must match the res: entry exactly, and may only use [a-z0-9_./-]: no capitals, no non-ASCII, no ...
  • Where do I get textures? Draw your own. Using vanilla assets is not allowed (../../rules.md). 16×16 is plenty.
  • Does it run in single player? Yes: single player uses the built-in Umbra by default (log line [isrv] v5 mods N: …). Only MC189RS_SERVER_KIND=vanilla/paper turns v5 mods off.
  • The hook never fires, or fires for the wrong block. Is the event listed in hooks? Is block_hook: in veil_mod!? Remember that blocks and items share one numbering.

Examples: easy_block (table, hook and a HUD hint in one mod), reg_empty (names only), blocks_basic (shapes and collision), blocks_logic (hooks, tile data, redstone), moon_furnace (a machine with slots).