Minecraft commands generated with JavaScript
MCJS is both a compiler and a file format:
.mcjs
files are .mcfunction
files wrapped with JavaScript..mcfunction
files from .mcjs
.MCJS requires Node.js to function, which can be downloaded from here. Once installed, open a terminal and run:
npm install -g @open-mapmaking/mcjs
MCJS is accessible from the terminal.
Compile a single file from .mcjs
to .mcfunction
:
mcjs filename.mcjs
Will generate filename.mcfunction
.
Pass a folder to compile each .mcjs
files it contains to .mcfunction
:
cd path/to/datapack
mcjs ./
With the watch
command, each .mcjs
file save will trigger a recompilation:
mcjs watch filename.mcjs
It also works with a whole folder:
cd path/to/datapack
mcjs watch ./
.mcjs
files contain regular JavaScript and, when compiled, are executed just like .js
files. They have access to the whole JavaScript syntax and to MCJS specific objects, which are specified here.
cmd
functionAt compilation, it is the cmd
function that outputs commands in the resulting .mcfunction
file. It takes a string as a parameter:
cmd('say Hello world!')
cmd('summon creeper ~ ~ ~')
Will result to a .mcfunction
file containing:
say Hello world!
summon creeper ~ ~ ~
cmd
is also a template tag, which can write multiple commands at once. It also enable access to ${expression}
placeholders:
let entity = 'creeper'
cmd`
summon ${entity} ~ ~ ~
execute as @e[type=${entity}] run say hello
`
Will result to:
summon creeper ~ ~ ~
execute as @e[type=creeper] run say hello