Files
Matt c699dcc77b pack: KubeJS tidying + admin commands, bump to 0.20.0
Tidying pass on the KubeJS suite before plot system V1 lands. Sets up
the file structure + conventions + diagnostics so the larger plot
system has a clean foundation.

Changes:

1. NEW kubejs/README.md
   File layout doc + conventions: logging prefix [bns/<module>],
   persistent-data key naming (bns* prefix), one concern per file,
   performance discipline (O(1) lookups, no polling).

2. Split economy_policy.js -> recipes_waystones.js + recipes_numismatics.js
   Single-concern files. recipes_waystones removes ALL waystones
   crafting (welcome.js distributes the only allowed waystone instead).
   recipes_numismatics removes the 5 coin-denomination crafts.

3. NEW kubejs/server_scripts/bns_admin.js
   /bns admin subcommands for OP diagnostics:
     - info                       calling player's flags+counts
     - waystone-count <player>    read stored count
     - waystone-set <player> <n>  override stored count
     - reset-welcome <player>     clear bnsWelcomeGranted -- replays
                                  the welcome grant on next login
   Registered via ServerEvents.commandRegistry with Brigadier tree,
   permission level 2 (OP). No performance cost (operator-triggered only).

4. Logging added to waystones_policy.js + welcome.js
   Every action prints `[bns/<module>] ...` so server logs can be
   filtered with `journalctl ... | grep '\[bns/'`.

Performance discipline applied:
- All event-handler lookups use Set.has (O(1)), not Array.includes
- No periodic tick polling anywhere
- No network calls in event handlers
- console.info is cheap (no string format unless logged)

Bumps to 0.20.0. Plot system V1 follows in v0.21.x as a separate
multi-file submodule under server_scripts/plots/.
2026-05-23 15:39:59 +00:00

62 lines
2.7 KiB
Markdown

# Brass & Sigil KubeJS scripts
All custom server behaviour lives here. Files in this tree ship via the
modpack manifest (see `scripts/Build-Pack.ps1``kubejs/` is in
`managedRoots`), get synced to both server and client installs, and are
loaded by KubeJS on startup.
## File layout
```
kubejs/
├── README.md this file
├── server_scripts/ Loaded by the SERVER's KubeJS on world load.
│ ├── recipes_<x>.js Crafting-recipe overhauls per mod.
│ ├── waystones_policy.js Waystones placement gating (1/player + bans).
│ ├── welcome.js First-join grant: waystone + manual book.
│ ├── cc_recipes.js Full ComputerCraft recipe overhaul.
│ └── bns_admin.js /bns admin <subcommand> for OP diagnostics.
└── client_scripts/ Loaded by the CLIENT's KubeJS on game load.
└── jei_hides.js Hide specific items from the JEI ingredient list.
```
## Conventions
- **Logging prefix**: every console line uses `[bns/<module>]` so server
logs can be filtered with `journalctl -u brass-sigil-server.service |
grep '\[bns/'`. Keeps our output separate from mod output.
- **One concern per file**. Recipe overhauls live in `recipes_<modname>`.
Block/item policy goes in a `<thing>_policy.js`. Don't mix recipe
removal with event listeners in the same file.
- **Persistent player data** keys are prefixed `bns` to avoid clashing
with other mods' use of `player.persistentData`. Currently used keys:
- `bnsWaystoneCount` (int) — see `waystones_policy.js`
- `bnsWelcomeGranted` (bool) — see `welcome.js`
- **Performance**: hot-path event handlers (BlockEvents.placed/broken,
PlayerEvents.loggedIn) must stay O(1). Use `Set` for ID lookups, never
Array.includes inside an event handler. Avoid Modrinth/network calls
in event handlers — never. No periodic-tick polling unless absolutely
necessary.
- **Server commands** are registered under the `/bns` namespace
(`/bns admin ...`, future: `/bns plot ...`). See `bns_admin.js` for
the registration pattern.
## Diagnostics
When something looks wrong in-game, first port of call:
1. `/bns admin info` — prints active flags + counts for the running player
2. `/bns admin waystone-count <player>` — read stored count
3. `/bns admin reset-welcome <player>` — re-trigger the first-join grant
4. Server log: `journalctl -u brass-sigil-server.service -f | grep '\[bns/'`
## See also
- `pack/overrides/defaultconfigs/` — first-run mod configs (auto-copied
to `config/` by NeoForge on first launch only)
- `scripts/Check-Deps.ps1` — pre-flight dep check, runs before any
Deploy-Brass `-Stage Pack` deploy
- The memory file `project-mc-player-economy.md` for the broader plan