Skip to content
botBehaviorPublic

About

Programmable computers and turtles for Horizon-Rust Minecraft. Every computer is a sandboxed WebAssembly machine: Lua built in, Rust and C compiled in.

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

wasmCraft

Programmable computers and turtles for Horizon.
Every computer is a sandboxed WebAssembly machine. Lua comes built in. Everything else compiles to it.

A wasmCraft base: a monitor showing a live fleet dashboard, GPS towers, and a turtle building a stone tower

wasmCraft adds computers, turtles, monitors, disk drives and wireless modems to Horizon, the Rust rebuild of Minecraft: Java Edition 26.3. Place a computer and it boots into a Lua shell with an editor, so you can type turtle.forward() and watch a robot move. If you've played ComputerCraft, the APIs will be familiar.

Underneath, each computer is a WebAssembly machine. The Lua OS is just the program it runs by default. Write a program in Rust or C, build it to wasm32 on your desktop, and it runs on the same hardware with the same turtle, modem and monitor APIs. Other languages work too, if their compiler can produce a standalone module without WASI; the machine interface says what that takes. Use Lua for quick scripts and Rust for the long-running, complex programs that run your base.

See it work

A fleet on one network

Three turtles work a lakeside base while a monitor tracks them

Three turtles work a lakeside base: one digs a quarry, one builds a tower, one fells a row of trees. Each finds its position with GPS and reports progress over rednet to a control computer, which draws the fleet on a 5 × 4 monitor wall.

The dashboard and the quarry turtle are Rust programs. The builder and the lumberjack are Lua scripts. All four speak the same rednet protocol, so the dashboard can't tell which is which. Footage at 2× speed. The code is in examples/fleet.

Doom, on a computer

Walking up to a computer, typing "wasm doom.wasm" and playing Doom

The same machine runs DoomGeneric, compiled from C to WebAssembly. Walk up to a computer, run wasm doom.wasm, and play. Programs can draw full images on the terminal with display.present, and they get keyboard input the same way a Lua program does. Build it yourself with examples/doom. The footage uses Freedoom.

What's in the box

Computers A 51 × 19 colour terminal, a shell with aliases and history, a full-screen editor with Lua syntax colouring, and a Lua prompt. Each computer has 1 MB of storage.
Turtles 16-slot robots that move, dig, place, attack, drop, pick up, refuel and craft. They equip tools, wireless modems and crafting tables. A turtle keeps running while it moves. Break one and it keeps its ID, label, files, fuel and tools; its inventory drops.
Monitors Up to 8 × 6 blocks, joined from single blocks automatically. Text scales from 0.5 to 5, and touches report the character that was touched.
Disk drives Floppy disks with 125 KB of storage and a label, mounted as disk, disk2, and so on. Carry programs between computers.
Wireless modems 64-block range, 65,535 channels, rednet, GPS and repeaters.
Redstone Digital and analog input and output on all six sides.
WebAssembly Run your own WebAssembly programs with wasm program.wasm. A Rust SDK covers the terminal, events, turtles, peripherals, rednet and GPS.
Sandboxing Each computer runs in Wasmtime on its own thread, with a 64 MiB memory cap, a storage quota, no Internet access, and a watchdog that stops programs that never yield.

Install

wasmCraft is a native Horizon mod. The Horizon launcher compiles it on your machine against the exact game build it pins, so you need the launcher and an instance on that build (game version 26.3, Horizon revision f1bb66f).

  1. In the Horizon launcher, open Mods, search for wasmCraft, and install it into an instance. Or choose Add from GitHub and paste this repository's address. The first native mod you install asks you to allow native code. wasmCraft itself runs outside Horizon's mod sandbox; the programs your computers run stay inside wasmCraft's.
  2. Start the instance and make a world.

To play on a server, the server needs wasmCraft in its engine build and every player needs the same version. See Running a server.

First steps

Craft a computer from seven stone, a redstone dust and a glass pane:

Stone   Stone       Stone
Stone   Redstone    Stone
Stone   Glass Pane  Stone

Place it and right-click it. Then try:

> help
> programs
> edit hello.lua
> hello

edit opens the editor; press Ctrl for its menu (Save, Run, Exit). To stop a program, hold Ctrl+T for a second. Hold Ctrl+R to reboot and Ctrl+S to shut down.

For a turtle, put a computer in the middle of seven iron ingots with a chest below it. Craft that turtle with a diamond pickaxe to get a Mining Turtle. Right-click it, put coal in its inventory, then type:

> refuel
> tunnel 16

Getting started covers every recipe and control.

Programs in Rust

use wasmcraft_sdk::{print, turtle};

wasmcraft_sdk::main!(|| {
    turtle::refuel();
    let mut dug = 0;
    while turtle::dig_down() && turtle::down() {
        dug += 1;
    }
    print(&format!("Dug {dug} blocks down."));
});
cargo build --release --target wasm32-unknown-unknown

Copy the .wasm file into the computer's folder in the world save (wasmcraft/computer/<id>/) or onto a floppy disk, then run wasm dig.wasm in game. Writing programs in Rust covers the SDK, events, rednet, and building programs that run for hours.

Documentation

Guide
Getting started Recipes, controls, the shell, the editor, your first turtle
Lua reference Every API and event, and how they differ from ComputerCraft
Turtles Movement, fuel, tools, inventory, crafting, bundled programs
Peripherals Monitors, disk drives, floppies, redstone
Networking Modems, channels, rednet, GPS, repeaters
Writing programs in Rust The SDK, building, deploying, Rust and Lua together
The machine interface The WebAssembly ABI, for C and other languages
Running a server Installing, storage, limits, security
Building from source Toolchains, tests, packaging

Status

This is an alpha. Everything above works and is covered by tests, but expect rough edges, and expect saved data formats to change before 1.0. Known issues are in the changelog.

Not yet: speakers, pocket computers, printers, wired modems and HTTP. Computers have no Internet access by design.

License and credits

wasmCraft is licensed under the Apache License 2.0. If you redistribute it, or a mod or modpack built from it, keep the NOTICE file with it.

  • The Lua OS runs on rilua (MIT or Apache-2.0), vendored in guest/vendor/rilua with one fix for wasm32.
  • The Doom example's adapter is GPL-2.0-or-later, like DoomGeneric. See examples/doom/COPYING. Its build fetches DoomGeneric and contains no game data.

wasmCraft is an independent project. It is not affiliated with or endorsed by ComputerCraft, CC: Tweaked, Mojang Studios or Microsoft, and it is not an official Minecraft product.

About

Programmable computers and turtles for Horizon-Rust Minecraft. Every computer is a sandboxed WebAssembly machine: Lua built in, Rust and C compiled in.

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages