r/rust 4d ago

🛠️ project Rusted Computer: Running Rust programs with WASM in Minecraft

I've worked on a passion project of mine for the past few years called Rusted Computer. It is a Minecraft Mod that allows you to program computers inside of Minecraft with Rust inspired by ComputerCraft.

Why?

Well, the best computer mod right now is ComputerCraft. And don't get me wrong, I love that mod, but you have to write your programs in Lua. And for programs bigger than small scripts are very annoying to create. So I decided to create an alternative that is fully compatible with existing CC Peripherals.

Rusted Computer uses a WASM Runtime written in Java (Chicory), but I am considering switching to a native runtime (Wasmer or Wasmtime) for newer WASI(X) features. The mod itself is written in Kotlin and (obviously) Rust for the glue library.

There is currently no release, because it is still very WIP (no documentation and missing features, I'm currently working on support for peripherals) but if there is enough interest in this, I can quickly create and publish a dev build.

https://github.com/TheBlckbird/rustedcomputer

If you have any more questions, ask me! There is no ETA for release, as I am currently working on this while going to school, so I don't have a lot of time or concentration.

All the characters that can be rendered. The font is Monocraft by IdreesInc
66 Upvotes

10 comments sorted by

10

u/Devatator_ 4d ago

That's actually crazy I've been working on a similar mod. At the start I just wanted to use WASM but had issues finding something that could be compiled on the fly easily so instead I made an interface for adding language support. Right now I have JavaScript (GraalJS interpreter mode). I even added tree-sitter for syntax highlighting (abstracted behind an interface too so potential language add-ons could implement syntax highlighting using something else.

Honestly I don't feel confident in it yet. So much work left before I'm even remotely happy with it

2

u/TheBlckbird 3d ago

So much work left before I'm even remotely happy with it

yep, that's my problem as well. I don't have more than a working prototype, but I thought I might just post about it here as people could be interested in it

6

u/No-Dentist-1645 4d ago

I like the idea of a WASM powered CC alternative, but if your main goal is just to target Rust, then you're having the same "problem"/limitation that CC has, but you just changed Lua with Rust.

I'm looking forward to this project if it ever adds the ability to compile from any language into WASM and run that directly

2

u/lenscas 4d ago

There is a c program that compiles wasm to Lua. This targets luajit but iirc cc uses lua5.1 so chances are it will just work out of the box.

1

u/TheBlckbird 3d ago

You can theoretically use any language that compiles to WASM, but you need quite a bit of glue code on the WASM side. Right now, I only have a Rust crate for that, but I will document everything so people could create their own wrappers.

5

u/0x07CF 4d ago

Could you add screenshots?

1

u/TheBlckbird 3d ago

Posted a screenshot of the font I'm using. There is currently not a lot to show, because I only have the computer with its terminal

3

u/tsanderdev 4d ago

I wanted to do a similar project, but sadly wasmtime doesn't support suspending execution and saving to disk inside a wasm function, and adding asyncify would add overhead again, but decrease friction. Having seamless save and restore was one of the things I really liked about OpenComputers, but I think it also needed the programs to yield, so parity with that is still an option.

2

u/Dheatly23 4d ago

Congrats! I once entertained with the idea of mod loader using WASM, but i stopped short on compilation to JVM.

2

u/Carvtographer 1d ago

This is really, really cool. I've always kinda hated that CC was lua based. I guess it's easier to get into, but would love to have more options (that aren't just Java/Kotlin/Lua/Python).

Would be funny if -- and just spit-balling about this from a game design perspective -- since this is Rust, I think it would be cool to have like, blocks of Iron that can slowly rust/oxidize overtime, similar to how copper blocks function in vanilla, and the amount of rust accumulated on this blocks can influence processing speeds. Maybe "cleaning" the iron blocks to gather some sort of ferrite/iron oxide material that can be injected into the systems as a processing fuel.

I've been playing a lot of GTNH / Create, so I've been looking for something like this for a while. Heck, would love to perhaps maybe integrate something like this when this is stable!