Setting up
Lesson 9.1
Part 1 taught you the Lua language. Now you put it to work inside the game. In this lesson you install the tools, make a new mod and look at what is inside it.
What you need
- Celestial itself. The download from the Celestial website is a folder with
Celestial.exein it. - The CLight SDK. It ships with Celestial, in the
clight-sdkfolder next toCelestial.exe. CLight is the name of the modding system, and the SDK is its toolbox. - A text editor. Any editor works. Visual Studio Code with the free Lua extension by sumneko is a good choice, because it understands the annotations the SDK comes with.
Lua mods need nothing else: no compiler and no build step.
Put the clight tool on your PATH
The SDK’s command-line tool is clight-sdk/bin/clight.exe. Add that bin folder to your PATH so you can type clight in any terminal:
- Press the Windows key and search for Edit environment variables for your account.
- Select Path, click Edit, then New, and paste the full path of the
binfolder, for exampleC:\Games\Celestial\clight-sdk\bin. - Click OK and open a new terminal window.
Check that it works:
> clight --version
clight 0.1.0 (API 1.24, wasi-sdk-34)
clight doctor checks the rest of the installation. For Lua mods, the lines that matter are the SDK folder and Celestial:
> clight doctor
CLight SDK 0.1.0 (API 1.24)
ok SDK folder C:\Games\Celestial\clight-sdk
ok clight.h C:\Games\Celestial\clight-sdk\include
MISSING wasi-sdk (C/C++ mods) run `clight setup`
ok Celestial C:\Games\Celestial\Celestial.exe
Lua mods need nothing else.
The wasi-sdk line is only for mods written in C or C++. You can ignore it.
Make a new mod
Go to the folder where you keep your projects and run clight new:
> clight new lua my_mod
created C:\Projects\my_mod (lua, 4 files)
next: cd my_mod && clight build && clight run
my_mod is the mod’s id. Every mod has one, and it has to be unique. The rules: lowercase letters, digits and _, starting with a letter, 2 to 64 characters. ruby_tools is fine, RubyTools and 2cool are not.
The display name is made from the id (my_mod becomes “My Mod”). Pick another with --name:
> clight new lua ruby_tools --name "Ruby Tools"
What’s inside
my_mod/
clight.mod.json the manifest: id, version, name, licence, ...
scripts/
main.lua your code starts here
assets/
my_mod/
lang/
en_us.json texts players see, by language
.gitignore
A bigger mod adds more folders next to these:
| Folder | What goes in it |
|---|---|
scripts/ |
Lua files. main.lua runs first; other files are loaded with require. |
assets/<id>/ |
Resource-pack files: textures, models, sounds, language files, GUI files. |
datapack/<id>/ |
Data-pack files: recipes, loot tables, tags. |
icon.png |
The mod’s icon, square, 64 to 256 pixels. |
LICENSE |
The licence text. |
build/ |
Made by clight. Packed mods end up here. Don’t edit it. |
data/ |
The mod’s own saved files while it runs. Not part of the package. |
Your first script
Open scripts/main.lua. The template already does something useful:
-- When a player joins, say hello.
cl.on("player.join", function(event)
local player = event.player
player:send_message("Welcome, " .. player.name .. "!")
end)
cl.log(mod.id, mod.version, "loaded")
Two names are there without you creating them:
clis the game API. Everything the game lets your mod do is a function insidecl.modis your mod:mod.idis"my_mod",mod.versionis"1.0.0".
The rest is the Lua you know: a function stored in a table, a call with a string and a function, string joining with ... cl.on says “when this happens, run this function”. You will meet it properly in Listening to events.
The sandbox
Your script runs in a sandbox. It sees cl, mod and the safe parts of the standard library, and nothing else: no io, no os.execute, no loading native code. A mod can’t read your other files or start programs. That is why players can install mods without worrying.
Editor help
The SDK has a file with a description of every API function: clight-sdk/lua/clight.d.lua. Point your editor’s Lua extension at it and you get completion and parameter hints for cl.. In VS Code, add this to .vscode/settings.json in your mod folder (change the path to yours):
{
"Lua.runtime.version": "Lua 5.4",
"Lua.workspace.library": ["C:/Games/Celestial/clight-sdk/lua"],
"Lua.diagnostics.globals": ["cl", "mod"]
}
Try it
Make a mod called hello_world with the display name “Hello World”. Change the welcome message so it also says the mod’s version, for example “Welcome, Alex! Hello World 1.0.0 is installed.”
Show a solution
> clight new lua hello_world --name "Hello World"
cl.on("player.join", function(event)
local player = event.player
player:send_message("Welcome, " .. player.name .. "! Hello World " .. mod.version .. " is installed.")
end)
mod.version comes from the version field in clight.mod.json, so it stays right when you release a new version.
Recap: put clight-sdk/bin on your PATH, make a mod with clight new lua <id>, and write your code in scripts/main.lua using cl and mod.