From 5e9d45bc9afe0bf91feb22e49a5232cb00f38287 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Mon, 26 Oct 2026 00:11:39 +0100 Subject: [PATCH] /pregen: off unless the server turns it on Vanilla has no /pregen, so with it always registered /help and the command tree differed from vanilla's (the command_exec harness failed on /help). Horizon's own commands are now added to the game's tree only when the owner asks: `horizon-pregen=true` in server.properties (`horizon-pregen = true` under [properties] in server.toml) for a dedicated server, `--pregen` for the game (single player, LAN). Off, the trees are vanilla's own, unchanged. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/command/tests.rs | 18 ++++++++ crates/horizon-client/src/command/vanilla.rs | 45 ++++++++++++++------ crates/horizon-client/src/game.rs | 4 +- crates/horizon-client/src/game/dedicated.rs | 8 ++++ docs/hosting.md | 5 ++- docs/pregeneration.md | 6 +++ 6 files changed, 70 insertions(+), 16 deletions(-) diff --git a/crates/horizon-client/src/command/tests.rs b/crates/horizon-client/src/command/tests.rs index 2bdea1aba..d61fd8ae1 100644 --- a/crates/horizon-client/src/command/tests.rs +++ b/crates/horizon-client/src/command/tests.rs @@ -592,3 +592,21 @@ fn mod_commands_join_the_tree_for_every_player() { // The game's own tree is left as it was. assert!(vanilla::game_dispatcher().find("where").is_none()); } + +#[test] +fn horizon_commands_are_off_unless_the_server_turns_them_on() { + // By default the game runs vanilla's tree: /help lists no /pregen. + assert!(vanilla::game_dispatcher().find("pregen").is_none()); + for dev in [false, true] { + let vanilla_tree = vanilla::game_tree(dev, false); + assert!(vanilla_tree.find("pregen").is_none()); + let d = vanilla::game_tree(dev, true); + let parse = d.parse("pregen start 100 circle", ®()); + assert_eq!(parse.executable().unwrap().1, "pregen.start"); + // Vanilla's commands are the same with or without it. + assert_eq!( + d.nodes[0].children.len(), + vanilla_tree.nodes[0].children.len() + 1 + ); + } +} diff --git a/crates/horizon-client/src/command/vanilla.rs b/crates/horizon-client/src/command/vanilla.rs index cba5a5d5b..2ce892077 100644 --- a/crates/horizon-client/src/command/vanilla.rs +++ b/crates/horizon-client/src/command/vanilla.rs @@ -538,20 +538,39 @@ fn apply_vanilla_order(d: &mut Dispatcher) { } /// The tree the game runs: a release integrated server's, or with /// `HORIZON_DEV_COMMANDS` set the development one -/// (SharedConstants.DEBUG_DEV_COMMANDS), plus Horizon's own commands. +/// (SharedConstants.DEBUG_DEV_COMMANDS), plus Horizon's own commands when +/// the server turned them on (`set_horizon_commands`). pub fn game_dispatcher() -> &'static Dispatcher { - static DEV: std::sync::OnceLock = std::sync::OnceLock::new(); - static RELEASE: std::sync::OnceLock = std::sync::OnceLock::new(); - let (tree, dev) = if std::env::var_os("HORIZON_DEV_COMMANDS").is_some() { - (&DEV, true) - } else { - (&RELEASE, false) - }; - tree.get_or_init(|| { - let mut d = build_with(dev); - horizon_commands(&mut d, 0); - d - }) + game_tree( + std::env::var_os("HORIZON_DEV_COMMANDS").is_some(), + HORIZON_COMMANDS.load(std::sync::atomic::Ordering::Relaxed), + ) +} +/// Whether this process's server has Horizon's own commands (`/pregen`). Off +/// by default, so `/help` and the command tree are vanilla's; a dedicated +/// server turns them on with `horizon-pregen=true` in server.properties, the +/// game with `--pregen` (docs/pregeneration.md). +static HORIZON_COMMANDS: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false); +/// Turns Horizon's own commands on or off for the trees `game_dispatcher` +/// returns from now on. +pub fn set_horizon_commands(on: bool) { + HORIZON_COMMANDS.store(on, std::sync::atomic::Ordering::Relaxed); +} +/// The server.properties key that turns `/pregen` on (Horizon's own; vanilla +/// ignores keys it doesn't know). +pub const PREGEN_PROPERTY: &str = "horizon-pregen"; +pub(crate) fn game_tree(dev: bool, horizon: bool) -> &'static Dispatcher { + static HORIZON: [std::sync::OnceLock; 2] = + [const { std::sync::OnceLock::new() }; 2]; + match (dev, horizon) { + (true, false) => dispatcher(), + (false, false) => release_dispatcher(), + (dev, true) => HORIZON[usize::from(dev)].get_or_init(|| { + let mut d = build_with(dev); + horizon_commands(&mut d, 0); + d + }), + } } /// Commands vanilla doesn't have, after its own: `/pregen` /// (docs/pregeneration.md). diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index fa00e3804..08e1ff68b 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -360,7 +360,7 @@ impl Options { match arg.as_str() { "--help" | "-h" => { println!( - "Horizon — Minecraft Java Edition {} in Rust\n\n --resources PATH Prepared resources (horizon-prepare)\n --render-distance N Chunks, 2..64 (default 12)\n --world NAME World folder under saves/ (default \"New World\")\n --seed N World seed for new worlds (default 0)\n --width N, --height N Window size (default 1280 x 720)\n --creative Creative mode (default survival)\n --test-terrain Simple test terrain instead of vanilla generation\n --frames N Exit after N frames (testing)\n --world-frames N Exit after N frames drawn in the world (testing)\n --smoke-report PATH Write a JSON report on exit\n --benchmark SCENARIO Run a benchmark (standard, village, forest, ocean, mountain), write its report to benchmarks/ and quit\n --control Accept horizon-ctl commands on a local socket\n --control-socket PATH Control socket path (default $XDG_RUNTIME_DIR/horizon-control.sock)\n --server HOST[:PORT] Join a multiplayer server (offline mode) at start\n --name NAME Player name for multiplayer (default: generated once, kept in horizon-player.txt)\n --session-file PATH Signed-in account from the launcher (read once, then deleted)\n --dev-mod PATH A Horizon mod (.hmod or folder) to develop: always on, reloaded when rebuilt\n --in-frame Run single player's world in the frame, not on its server thread\n\nControls: mouse look, WASD move, Space jump, Left Shift sneak, Left Ctrl sprint,\nleft click break, right click place/use, 1-9/scroll hotbar, E inventory,\nQ drop, F3 debug, Esc pause.", + "Horizon — Minecraft Java Edition {} in Rust\n\n --resources PATH Prepared resources (horizon-prepare)\n --render-distance N Chunks, 2..64 (default 12)\n --world NAME World folder under saves/ (default \"New World\")\n --seed N World seed for new worlds (default 0)\n --width N, --height N Window size (default 1280 x 720)\n --creative Creative mode (default survival)\n --test-terrain Simple test terrain instead of vanilla generation\n --frames N Exit after N frames (testing)\n --world-frames N Exit after N frames drawn in the world (testing)\n --smoke-report PATH Write a JSON report on exit\n --benchmark SCENARIO Run a benchmark (standard, village, forest, ocean, mountain), write its report to benchmarks/ and quit\n --control Accept horizon-ctl commands on a local socket\n --control-socket PATH Control socket path (default $XDG_RUNTIME_DIR/horizon-control.sock)\n --server HOST[:PORT] Join a multiplayer server (offline mode) at start\n --name NAME Player name for multiplayer (default: generated once, kept in horizon-player.txt)\n --session-file PATH Signed-in account from the launcher (read once, then deleted)\n --dev-mod PATH A Horizon mod (.hmod or folder) to develop: always on, reloaded when rebuilt\n --in-frame Run single player's world in the frame, not on its server thread\n --pregen Add Horizon's /pregen command (docs/pregeneration.md)\n\nControls: mouse look, WASD move, Space jump, Left Shift sneak, Left Ctrl sprint,\nleft click break, right click place/use, 1-9/scroll hotbar, E inventory,\nQ drop, F3 debug, Esc pause.", horizon_core::VANILLA_VERSION ); return Ok(None); @@ -377,6 +377,8 @@ impl Options { "--control" => o.control = Some(horizon_client::control::default_path()), "--server-thread" => o.server_thread = true, "--in-frame" | "--no-server-thread" => o.server_thread = false, + // Horizon's own commands (/pregen), off by default as on vanilla. + "--pregen" => horizon_client::command::vanilla::set_horizon_commands(true), _ => { let value = args .next() diff --git a/crates/horizon-client/src/game/dedicated.rs b/crates/horizon-client/src/game/dedicated.rs index edea0e800..fa5365195 100644 --- a/crates/horizon-client/src/game/dedicated.rs +++ b/crates/horizon-client/src/game/dedicated.rs @@ -155,6 +155,14 @@ pub(super) fn preflight(options: &mut Options) -> Result { for w in &props.warnings { log("WARN", w); } + // Horizon's own commands are the owner's choice, off as on vanilla. + if props + .raw + .get(horizon_client::command::vanilla::PREGEN_PROPERTY) + .is_some_and(|v| v.trim().eq_ignore_ascii_case("true")) + { + horizon_client::command::vanilla::set_horizon_commands(true); + } props.store(&settings)?; let eula_file = PathBuf::from("eula.txt"); let agreed = match eula::agreed(&eula_file) { diff --git a/docs/hosting.md b/docs/hosting.md index 4c4c954bc..a9624dc2c 100644 --- a/docs/hosting.md +++ b/docs/hosting.md @@ -218,8 +218,9 @@ horizon-server rollback back to the release before While the server runs, `op`, `whitelist` and `cmd` go to the game's console, so they act exactly as vanilla's console commands do. While it's stopped, they edit vanilla's files directly. Any console command works through `cmd`: `horizon-server cmd ban Griefer`, `horizon-server cmd say Restarting in 5 minutes`. -To generate the world around spawn ahead of the players, Horizon has its own `pregen` command: -`horizon-server cmd pregen start 2500` ([pregeneration](pregeneration.md)). +To generate the world around spawn ahead of the players, Horizon has its own `pregen` command, off until +`server.toml` has `horizon-pregen = true` under `[properties]`: `horizon-server cmd pregen start 2500` +([pregeneration](pregeneration.md)). `config set` changes `server.toml` without opening it: `horizon-server config set world.difficulty=hard server.max_players=10`. Each key is a section and a name from the file (`properties.spawn-protection=0` for any diff --git a/docs/pregeneration.md b/docs/pregeneration.md index a8ca228b3..706527661 100644 --- a/docs/pregeneration.md +++ b/docs/pregeneration.md @@ -5,6 +5,12 @@ Chunky does on a Java server. It is Horizon's own command (vanilla has none), av with cheats on and to operators (level 2) on a server, from the chat or the server console (`horizon-server cmd pregen start 2500`). +It is off until you turn it on, so `/help` and the command tree stay vanilla's: + +- a server: `horizon-pregen = true` under `[properties]` in `server.toml` (or `horizon-pregen=true` in a + vanilla folder's `server.properties`), then restart it; +- single player and LAN: start the game with `--pregen`. + ```text /pregen start [square|circle] [ ] radius in blocks; the centre defaults to where you stand (the world spawn from the console)