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.
| Template | What you get | Veil version |
|---|---|---|
hud | An FPS card you can toggle with a key, a typed settings table, a HUD layout part | 4 |
block | A glowing block that plays a sound when right-clicked (placeholder art in assets/glow.png) | 5 |
item | A charm item with a recipe and a right-click hook (assets/charm.png) | 5 |
server | A /hello command and a greeting when someone joins | 5 |
mc189 mod templates lists them. The generated files are:
Cargo.toml: acdylibwith a size-tuned release profile and an empty[workspace], so it never gets absorbed into a parent workspace..cargo/config.toml: setsbuild.target = wasm32-unknown-unknown, so a plaincargo buildproduces 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]anduse mc189_mod_sdk::prelude::*;. Mods run without the standard library. The prelude gives youformat!,String,Vec,vec!and the SDK names you use all the time (Mod,hud,keys,ui2,Check, …). You no longer needextern crate alloc;.veil_mod! { … }is the whole declaration.main: Mis 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:
- the
MC189RS_MODS_DIRenvironment variable; mods/next to theoptions.txtthatMC189RS_OPTIONSpoints at;- the default:
~/.config/mc189rs/mods/on Linux,%APPDATA%\mc189rs\mods\on Windows.
3. See it in the game
- Open Mods from the title screen or the pause menu.
- Check that your mod is enabled. If it failed to load, the reason is shown in red.
- 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
shutdownand theninit. - 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
- Pick a guide for the thing you want to build: guides/hud.md, guides/blocks.md, guides/items.md, guides/server.md.
- The full function list is ../reference.md.