4 releases
0.3.2 | Oct 26, 2023 |
---|---|
0.3.1 | Oct 26, 2023 |
0.3.0 | Oct 25, 2023 |
0.2.0 | Oct 25, 2023 |
#570 in WebAssembly
21 downloads per month
13KB
167 lines
mcinterface
Rust library for writing programs for Minecraft using wasmcraft2.
For a usage example, see https://github.com/arthomnix/mc_mandelbrot.
lib.rs
:
Wrapper library for wasmcraft2 datapacks written in Rust.
wasmcraft2 is a WebAssembly to Minecraft datapack
transpiler. This library provides safe access to wasmcraft's API, containing all functions present
in wasmcraft's mcinterface.h
as well as some additional helper functions and macros.
When writing programs for wasmcraft2, it is important to note its limitations - notably, floating
point operations are not supported, so using the fixed
crate is recommended if integers are not enough. Minecraft programs must be #![no_main]
and #![no_std]
; this
crate provides a Minecraft-compatible panic handler but there is no allocator. Decreasing the default
stack size is recommended - you can do this by adding the following to your .cargo/config
:
[target.wasm32-unknown-unknown]
rustflags = [ "-C", "link-args=-z stack-size=4096" ]
If more stack space is required, you can change 4096 to some greater number.
While you're in .cargo/config
, you should also set the default target to wasm32-unknown-unknown
[build]
target = "wasm32-unknown-unknown"
Enabling some optimisation even in debug builds is recommended, since Minecraft commands are not
the fastest compilation target ever - add the following to your Cargo.toml
:
[profile.dev]
opt-level = 1
wasmcraft2 does not support the main
function - your entrypoint must be declared as follows:
#[no_mangle]
pub extern fn _start() -> i32 {
// Your code goes here...
return 0;
}