Example mod · theonaris.examples.block-mover 1.0.0
Block Mover
A building tool that nudges the selected blocks by exact steps, including into the space of other blocks, for details the normal editor does not allow.
A small building tool that moves the selected blocks by exact steps along the creation's own axes, and lets them move into other blocks. That is how you build details the normal editor refuses: a pipe sunk halfway into a hull, overlapping armour plates, a light set into a wall.
| You will learn | Where |
|---|---|
| A toolbar tool with a window that opens and closes | building.addTool, BuildTool:setActive |
| Following the selection without polling | building.onSelectionChanged |
| Keys that are only bound while a window is open | input.bind / KeyBinding:off |
| Asking the server to change a creation | net.send("move", …) |
| Validating everything a client sends | net.handle with a schema and a rate in server.lua, then limits and snapping |
| Moving blocks past the overlap check | building.tryMoveInto (server, needs building.overlap) |
| Telling the player why a request was refused | return false, reason in the handler, net.on("denied", …) on the client |
| Choice settings | "type": "choice" in mod.json |
Try it
- Install, host or join a game with the mod, and allow the permissions.
- In the building editor, select one or more blocks and click ⇲ Mover.
- Pick a step (0.05 m is one lattice step; a block is 0.2 m) and press the arrows, or Numpad 4/6 (X), 1/7 (Y) and 2/8 (Z).
What building.moveInto does and does not allow
The server script calls building.tryMoveInto: the same move, but a refusal returns false and the reason instead of raising an error, and the script passes that reason back to the player on "denied".
- It runs only in server scripts, for a player you pass in. The game checks that the player owns the creation. A player cannot move someone else's blocks through your mod.
- The move goes through the game's normal block-move path, so it is saved and synchronised to every player like any other edit. What is skipped is the placement check, which is what refuses overlaps. The move is made by the server, so it does not go into the player's undo history; to undo, nudge back.
- The offset is in the creation's own directions, in metres, and is snapped to the build lattice (0.05 m).
The server script adds its own limits on top: at most 2 m per nudge, 20 nudges a second (net.handle's rate), and at most maxBlocks blocks at once, a server setting that belongs to the host. None of these values come from the client.
Files
mod.json
scripts/client.lua tool, window, selection, key bindings, request
scripts/server.lua net.handle, snapping, limits, building.tryMoveInto
ui/mover.uxml, ui/mover.uss
sounds/nudge.wav, overlap.wav, denied.wavAll files
| File | Size |
|---|---|
mod.json | 1 KB |
README.md | 3 KB |
scripts/client.lua | 4 KB |
scripts/server.lua | 2 KB |
sounds/denied.wav | 52 KB |
sounds/nudge.wav | 21 KB |
sounds/overlap.wav | 60 KB |
ui/mover.uss | 2 KB |
ui/mover.uxml | 1 KB |