Skip to content
This repository was archived by the owner on Oct 6, 2025. It is now read-only.

Repository files navigation

mclua - Lua Compiler for Minecraft Datapacks

Up to now, the compiler does not have full Lua language support, and there is a variable scope problem, which cannot be used for large-scale projects.

If you can help with the development, please submit a Pull Request.

features

  • Variable defines (basic types)
  • Function defines (need define types for arguments)
  • Function calls
  • print/command functions (use command("") to execute Minecraft commands)
  • String combines (two strings one time)
  • For in/While/Repeat
  • If/Else
  • advanced math functions
  • better performance
  • variable local range ...

installation

on Linux/Mac OS:

python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt

on Windows (PowerShell):

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
python -m venv .venv
.venv\bin\activate.ps1
pip install -r requirements.txt

you need to delete print(val) to remove the debug output. ( at .venv/lib/python3.*/site-packages/luaparser/ast.py line 37)

usage

Build with:

# Compile *.lua to a datapack
# This toll won't zip the datapack, it only output a directory
python datapack.py "input file" "output dir" "pack id"

# Compile *.lua to some mcfunction files
python compile.py "input file" "output dir" "pack id" # pack id is optional

Run in minecraft:

/function mclua:util/init_stroage
/function mclua:util/init_score

/function output:main # replace "output" with your pack id

/function mclua:util/remove_stroage

examples

Image

a = "hello world!"
function hello( arg1__string )
    aa = "func:" + arg1
    print(aa)
    return aa
end
hello(a)
c = 123 % 5
if c == 3 then
    print("right!")
else
    print("wrong!")
end
for i=0,3,1 do
    j = str(i)
    j = "Counter: " + j
    print(j)
end
print("mclua demo end")

License: GPL-3.0

About

Lua Compiler for Minecraft Datapacks

Topics

Resources

Stars

2 stars

Watchers

1 watching

Forks

Contributors

Languages