Example mod · theonaris.examples.gear-works 1.0.0
Gear Works
Two gear blocks made from data: a 96-tooth brass Great Wheel from a model, and a Clockwork Motor with its own settings, key and wire outputs. They mesh with every gear in the game. Teeth that jump under overload throw sparks.
Two gear blocks made from data: a brass Great Wheel 96 built from a model, and a Clockwork Motor with its own settings, key and wire outputs. They mesh with every gear in the game, and with every other mod's, because the game's gear system reads their teeth from the JSON. When overloaded teeth jump, the clients see sparks.
| You will learn | Where |
|---|---|
| Making any block a gear | "gear": { "kind": "spur", "size": 6 } in great-wheel.json |
| Gear models: metres, axis +Z, tooth 0 on +X | models/great-wheel.glb |
| Parts drawn turning on a gear's own axle | "spin": { "meshes": ["Wheel"] } (bolted to its part, as the Great Wheel is, the whole block turns with that part) |
| A whole mechanism declared in data | "mechanism" in clockwork.json: settings, a key, modes, wires |
| Rows that show only when they matter | "visibleWhen": { "Spring": "Run" } |
| Refining the game's placement guide | building.placement in client.lua, starting from q.suggested |
| Reacting to overloaded gears | kinetics.onTeethJumped in server.lua |
Try it
- Install and start a game. Gears turn on the Jolt physics engine (Settings → Physics → Physics Engine); on PhysX they are drawn but stay still.
- Open the building editor. Both blocks are in Movement.
- A game gear never turns by itself: it is bolted to the part it is built on. So put a Bearing on a plate and a Great Wheel 96 on the Bearing's turning face. Pick the Clockwork Motor and move the mouse round the wheel's rim, on the plate beside it (a Bearing is flat, so the two stand level): the guide shows where it meshes. Grey means the teeth would not touch; green means they mesh, and the label says how the two will turn ("×6 faster, opposite way") and ends in "· clockwork" — that part is this mod's guide.
- Leave the editor. The clockwork turns on its own axle at 30 rpm and drives the wheel, and the Bearing under it, at 5. (Mesh it with a wheel built straight onto the plate instead and neither can turn: the wheel is bolted to the part the clockwork stands on, so the clockwork's Jammed reads 1.)
- Open the clockwork's panel: Spring chooses Run, Hold or Coast. Speed and Torque show only when they apply. Bind Wind to a key and it runs only while you hold it — from a seat wired to it, or anywhere with Require Seat off.
- Wire the clockwork's RPM to a display, or a sensor's output into its Speed.
- Gears on different parts push on each other through their teeth. Put the wheel on a Servo's rotor instead (it is bolted to the rotor, and the servo holds its angle). A Servo is a cell tall, so the wheel now sits a cell above the plate: stand the clockwork on a one-cell block beside it to mesh them, and set the clockwork's Torque to 2000. The wheel's brass teeth give at 8 kN (
"strength": 8000) and the clockwork pushes 10 kN, so they jump: sparks and a click. (Gears on their own axles on one part share a gear train and cannot overload each other.) - Type
/gear-works.gearsin the developer console (the mod's own command) for a count of every shaft, gear and mesh, and whether gears are simulating. The game's own gears are hidden from the block palette for now:/gearsshows them, and they mesh with these two.
A gear in four lines
{
"id": "great-wheel", "name": "Great Wheel 96", "base": "Cube", "model": "/models/great-wheel.glb",
"gear": { "kind": "spur", "size": 6 },
"spin": { "meshes": ["Wheel"] }
}gear is what makes it one. From it the game works out everything a gear needs: its teeth (16 a size, so 96) and pitch radius (6 cells, 1.2 m), the game's geometry for that size (a box 13 cells square and one deep, faces on the cells its rim covers, only the cells its teeth reach occupied), and the Gear mechanism: no controls, bolted to the part it is built on, turning only when a servo, Bearing or wheel turns that part, with RPM, Angle and Jammed on wires. The Clockwork Motor below brings a mechanism of its own. Every grid size meshes with every other one wherever their rims meet on the build grid.
A gear's model is taken as it is, in metres, about its own origin (not fitted and centred like other models), because its teeth must sit exactly on the pitch circle the physics rolls. Model the axis along +Z with a tooth centred on +X.
A mechanism in data
The clockwork is based on the game's Gear 16, so it has that gear's shape and teeth. Its mechanism replaces the Gear mechanism with its own: four settings, a drive whose mode follows the Spring choice, and three values it reports on wires. The engine runs it natively every physics step — the mod has no per-step script, so a thousand clockworks cost what a thousand of the game's gears cost.
The panel also gets the rows every drive needs without declaring them: Toggle Mode and Require Seat for the Wind key, and Mount and Bearing Friction because it is a gear: unlike the game's Gear mechanism, a mechanism of a mod's own keeps the gear on its own axle, where its drive turns it (on Auto, a gear centred on a servo or Bearing turns with that instead).
All files
| File | Size |
|---|---|
content/blocks/clockwork.json | 2 KB |
content/blocks/great-wheel.json | 533 B |
icons/clockwork.png | 6 KB |
icons/great-wheel.png | 5 KB |
mod.json | 778 B |
models/great-wheel.glb | 831 KB |
README.md | 5 KB |
scripts/client.lua | 1 KB |
scripts/server.lua | 1 KB |
sounds/tooth-jump.wav | 21 KB |