목차

Your first mod in five minutes

The mc189 mod command creates a mod crate, builds it, checks it, installs it, and does all of that again every time you save.

mc189 mod new my_hud
cd my_hud
mc189 mod dev

Leave the game running while you work. mc189 is the game executable, but the mod subcommands never open a window.

You need Rust (rustup), the wasm target, and a checkout of this repository for the SDK source.

rustup target add wasm32-unknown-unknown

1. Create a mod

mc189 mod new my_hud                       # HUD template (the default)
mc189 mod new my_block --template block    # a block
mc189 mod new my_item  --template item     # an item
mc189 mod new my_srv   --template server   # a server command and event

The name becomes both the crate name and the mod id. It must match [a-z0-9_]{1,32} and must not start with a digit. Other options: --dir PARENT, --sdk SDK_DIR, --author NAME.

The SDK is looked up in this order: --sdk, then the MC189_MOD_SDK environment variable, then a mods-sdk/ folder found by walking up from the current directory or from the executable. If none is found the crate depends on mc189-mod-sdk = "0.5.1" and you get a warning. That version is not on crates.io yet, so point --sdk at the repository's mods-sdk folder.

TemplateWhat you getVeil version
hudAn FPS card you can toggle with a key, a typed settings table, a HUD layout part4
blockA glowing block that plays a sound when right-clicked (placeholder art in assets/glow.png)5
itemA charm item with a recipe and a right-click hook (assets/charm.png)5
serverA /hello command and a greeting when someone joins5

mc189 mod templates lists them. The generated files are:

  • Cargo.toml: a cdylib with a size-tuned release profile and an empty [workspace], so it never gets absorbed into a parent workspace.
  • .cargo/config.toml: sets build.target = wasm32-unknown-unknown, so a plain cargo build produces wasm.
  • .gitignore, src/lib.rs, and for blocks and items, assets/*.png (16×16 placeholders to draw over).

This is the src/lib.rs from the HUD template:

//! my hud — HUD mod template.
#![no_std]
use mc189_mod_sdk::prelude::*;

// Settings shown in the hub. The table is checked at compile time,
// and you read values through the same constants, so key typos cannot happen.
const SHOW: Check = Check::new("show", "Show", true);
const COLOR: Color = Color::new("color", "Text colour", 0xFFFFFF).tab(1);
const ALPHA: Slider = Slider::new("bg_alpha", "Background opacity", 0.0, 100.0, 5.0, 55.0).unit("%").tab(1);
const SETTINGS: Table = Table::new(Category::Hud, Icon::Gauge).tabs(&["General", "Look"]).items(&[SHOW.item(), COLOR.item(), ALPHA.item()]);

struct M {
    key: keys::KeyId,
    was: bool,
    on: bool,
}

impl Mod for M {
    fn init() -> Self {
        subscribe(sub::HUD | sub::TICK);
        M { key: keys::register("Toggle my hud", 0), was: false, on: true }
    }

    fn tick(&mut self) {
        let d = keys::is_down(self.key);
        if d && !self.was {
            self.on = !self.on;
        }
        self.was = d;
    }

    fn hud(&mut self, _partial: f32, _gw: u32, _gh: u32) {
        if !self.on || !SHOW.get() {
            return;
        }
        hud::part(0);
        let c = client();
        let a = (ALPHA.get() * 2.55) as u32;
        ui2::rect(2.0, 2.0, 74.0, 14.0, ui2::Radii::all(4.0), a << 24 | 0x10_1018);
        hud::text(6.0, 5.0, COLOR.argb(0xFF), true, &format!("FPS {}", c.fps));
    }
}

// No `abi` field: with only `main`, the macro picks version 4.
// The card uses ui2, so "ui" goes in groups.
veil_mod! {
    id: "my_hud",
    name: "my hud",
    version: "0.1.0",
    description: "my hud",
    authors: ["me"],
    main: M,
    groups: ["base", "ui"],
    settings: SETTINGS,
    hud_parts: ["main" = "my hud"],
}

What each piece does:

  • #![no_std] and use mc189_mod_sdk::prelude::*;. Mods run without the standard library. The prelude gives you format!, String, Vec, vec! and the SDK names you use all the time (Mod, hud, keys, ui2, Check, …). You no longer need extern crate alloc;.
  • veil_mod! { … } is the whole declaration. main: M is the client-side body, settings: is the settings table, hud_parts: names the pieces the HUD layout editor can move. Fields can come in any order.
  • There is no ABI version in the code. With only main, the macro picks 4. See abi.md.
  • Do not put " or \ in the name, description or authors. They are copied straight into a JSON section.

The block, item and server templates use the same veil_mod!. Adding fields such as content:, block_hook: or server_init: makes the macro pick version 5, one wasm that runs on both client and server.

2. The dev loop: mc189 mod dev

cd my_hud
mc189 mod dev

On every save it builds (cargo build --target wasm32-unknown-unknown --release), checks the result, and installs it into the mods folder as <id>.wasm. It also turns on hot reload, so the game picks up the new file within a second. Stop it with Ctrl+C. Use --to DIR to install somewhere else.

For one-off runs:

mc189 mod build              # build and check
mc189 mod check FILE.wasm    # check an existing wasm
mc189 mod install            # build, check and install

mc189 mod check reports the lowest ABI version your wasm actually needs. When something is wrong it says what to change, usually naming the veil_mod! field to fix.

The mods folder is the first of:

  1. the MC189RS_MODS_DIR environment variable;
  2. mods/ next to the options.txt that MC189RS_OPTIONS points at;
  3. the default: ~/.config/mc189rs/mods/ on Linux, %APPDATA%\mc189rs\mods\ on Windows.

3. See it in the game

  1. Open Mods from the title screen or the pause menu.
  2. Check that your mod is enabled. If it failed to load, the reason is shown in red.
  3. If hot reload is off, press Reload. The folder is polled once a second and a yellow notice tells you when something changed. Reloading restarts every mod from shutdown and then init.
  4. Keys your mod registers can be rebound under the Mods category in Controls.

Use log("…") for debug output. If you started the game from a terminal it appears on stderr with a [mod:my_hud] prefix. If your mod crashes, the in-game notice says where; see "Reading panic notices" in ../faq.md.

Without the mc189 mod command

mc189 mod runs an ordinary cargo build. If you made the crate by hand:

cargo build --target wasm32-unknown-unknown --release
bash <repo>/tools/mods-check.sh target/wasm32-unknown-unknown/release/my_hud.wasm
bash <repo>/tools/mkmod.sh ~/my_hud      # build, check and copy into the mods folder

Next