[MD]
# levilamina-mod-template-rs
A template for writing [LeviLamina](https://github.com/LiteLDev/LeviLamina)
mods for Minecraft Bedrock Dedicated Server **in Rust**, no C++ toolchain
required.
This template targets
[**levilamina-rust-loader**](https://github.com/Maskviva/levilamina-rust-loader),
the loader mod that teaches LeviLamina to load Rust `cdylib`s as first-class
mods. Install it on your server before this mod will do anything.
[中文说明](README.zh.md)
## What's in here
`src/lib.rs` is a complete, working mod (not an empty skeleton) that
demonstrates the full v0.1 API surface: logging, event subscription with
cancellation, a custom command, scheduled tasks, and console command
execution. Read through it, then strip out what you don't need.
## Usage
1. Click **Use this template** above to generate a new repository, then clone it.
2. Rename the crate:
- `Cargo.toml` → `[package] name = "..."`
- `manifest.json` → `"name"` (must match the folder you install into) and
`"entry"` (cargo's output DLL name — hyphens in the crate name become
underscores, e.g. `my-mod` → `my_mod.dll`)
- `src/lib.rs` → rename the `HelloWorld` struct and its log/command strings
to match
3. Write your mod. Delete whichever of the four demonstrated pieces
(event subscription, custom command, scheduled task, command execution)
you don't need.
4. Build and deploy:
```shell
cargo build --release
```
Copy `target/release/<your_crate>.dll` and `manifest.json` into
`<server>/plugins/<your-mod-name>/` (or see the CI workflow in this template
for an automated build+zip on every push/release).
## API at a glance
```rust
use levilamina::prelude::*;
struct MyMod;
impl LeviMod for MyMod {
fn on_load(ctx: &ModContext) -> Result<Self> {
ctx.logger().info("hello from Rust!");
Ok(MyMod)
}
fn on_enable(&mut self, ctx: &ModContext) -> Result<()> {
let server = ctx.server();
server.register_command("hello", "Say hello", CommandPermission::Any, |inv| {
inv.success(&format!("Hello, {}!", inv.origin));
})?;
server
.subscribe_event("PlayerChatEvent", EventPriority::Normal, |ev| {
if ev.snbt().contains("creeper") {
ev.cancel();
}
})?
.forget();
Ok(())
}
}
levilamina::register_mod!(MyMod);
```
Every lifecycle hook and callback (events, commands, scheduled tasks) runs on
the **server thread**. `Server::get()` + `Server::schedule`/`schedule_after`
are the thread-safe entry points for background threads (Tokio tasks, etc.)
to marshal work back into the game. Full contract:
[`levilamina-rust-loader`'s DESIGN.md](https://github.com/Maskviva/levilamina-rust-loader/blob/main/docs/DESIGN.md).
## Prerequisites
- Rust (`x86_64-pc-windows-msvc` target — the default on Windows)
- [LeviLamina](https://lamina.levimc.org/) + `levilamina-rust-loader` installed
on the target server
## Contributing
Ask questions by creating an issue. PRs accepted.
Found a bug in the loader itself, or want a new API primitive (world access,
player handles, ...)? That lives in
[levilamina-rust-loader](https://github.com/Maskviva/levilamina-rust-loader),
not here — this repo is just the starting skeleton.
## License
CC0-1.0 — public domain. Do whatever you want with the starter code; no
attribution needed.
---
*Not affiliated with Mojang, Microsoft, or LeviMC. Minecraft is a trademark of
Mojang Synergies AB.*
[/MD]