List command usages in vanilla's registration order and run the release tree

Brigadier keeps children in registration order and /help prints them
that way; tools/generate_command_order.py records vanilla's order where
Horizon's tree differs. The game now runs the release integrated
server's tree; HORIZON_DEV_COMMANDS restores the development commands.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-11 16:41:43 +02:00
parent 8490e19ec0
commit d7e4a5a275
9 changed files with 140 additions and 7 deletions
+1
View File
@@ -18,6 +18,7 @@ pub mod tree_misc;
pub mod tree_scoreboard;
pub mod tree_world;
pub mod vanilla;
mod vanilla_order;
use crate::text::Text;
pub use args::{Arg, ArgType, Registries};
@@ -403,6 +403,7 @@ pub fn build_with(dev: bool) -> Dispatcher {
super::tree_misc::register(&mut d, root);
super::tree_world::register(&mut d, root);
super::tree_extra::register(&mut d, root);
apply_vanilla_order(&mut d);
d
}
@@ -506,6 +507,42 @@ pub fn game_modes() -> [&'static str; 4] {
GameMode::ALL.map(GameMode::name)
}
/// The shared vanilla tree.
/// Reorder node children as vanilla registers them (Brigadier keeps
/// children in registration order; smart usage lists them that way).
fn apply_vanilla_order(d: &mut Dispatcher) {
for (path, order) in super::vanilla_order::ORDER {
let mut node = Some(0usize);
for name in path.split(' ').filter(|n| !n.is_empty()) {
node = node.and_then(|n| {
d.nodes[n]
.children
.iter()
.copied()
.find(|&c| d.nodes[c].name() == name)
});
}
let Some(n) = node else { continue };
let mut children = d.nodes[n].children.clone();
let rank = |c: usize| {
order
.iter()
.position(|o| *o == d.nodes[c].name())
.unwrap_or(order.len())
};
children.sort_by_key(|&c| rank(c));
d.nodes[n].children = children;
}
}
/// The tree the game runs: a release integrated server's, or with
/// `HORIZON_DEV_COMMANDS` set the development one
/// (SharedConstants.DEBUG_DEV_COMMANDS).
pub fn game_dispatcher() -> &'static Dispatcher {
if std::env::var_os("HORIZON_DEV_COMMANDS").is_some() {
dispatcher()
} else {
release_dispatcher()
}
}
pub fn dispatcher() -> &'static Dispatcher {
static TREE: std::sync::OnceLock<Dispatcher> = std::sync::OnceLock::new();
TREE.get_or_init(build)
@@ -0,0 +1,36 @@
//! The order of node children in vanilla's command tree, for the nodes
//! where Horizon's tree registers them differently (path of node names
//! from the root, children in vanilla's order). Generated by
//! tools/generate_command_order.py; do not edit by hand.
pub const ORDER: &[(&str, &[&str])] = &[
("", &["advancement", "attribute", "execute", "bossbar", "clear", "clone", "compute", "damage", "data", "datapack", "debug", "defaultgamemode", "dialog", "difficulty", "effect", "me", "enchant", "experience", "xp", "fill", "fillbiome", "forceload", "function", "gamemode", "gamerule", "give", "help", "item", "kick", "kill", "list", "locate", "loot", "msg", "tell", "w", "swing", "particle", "place", "playsound", "posteffect", "random", "reload", "recipe", "fetchprofile", "return", "ride", "rotate", "say", "schedule", "scoreboard", "seed", "version", "setblock", "spawnpoint", "setworldspawn", "spectate", "spreadplayers", "stopsound", "stopwatch", "summon", "tag", "team", "teammsg", "tm", "teleport", "tp", "tellraw", "test", "tick", "time", "title", "trigger", "waypoint", "weather", "worldborder", "jfr", "publish", "unpublish"]),
("execute", &["run", "if", "unless", "as", "at", "store", "positioned", "rotated", "facing", "align", "anchored", "in", "summon", "on"]),
("execute if", &["block", "biome", "loaded", "dimension", "score", "blocks", "entity", "predicate", "function", "stopwatch", "data", "items", "slots"]),
("execute unless", &["block", "biome", "loaded", "dimension", "score", "blocks", "entity", "predicate", "function", "stopwatch", "data", "items", "slots"]),
("execute facing", &["entity", "pos"]),
("datapack", &["enable", "disable", "list", "create"]),
("datapack enable name", &["after", "before", "last", "first"]),
("gamerule", &["spawn_wandering_traders", "minecraft:spawn_wandering_traders", "players_nether_portal_creative_delay", "minecraft:players_nether_portal_creative_delay", "allow_entering_nether_using_portals", "minecraft:allow_entering_nether_using_portals", "players_sleeping_percentage", "minecraft:players_sleeping_percentage", "universal_anger", "minecraft:universal_anger", "locator_bar", "minecraft:locator_bar", "lava_source_conversion", "minecraft:lava_source_conversion", "ender_pearls_vanish_on_death", "minecraft:ender_pearls_vanish_on_death", "mob_griefing", "minecraft:mob_griefing", "spread_vines", "minecraft:spread_vines", "max_command_forks", "minecraft:max_command_forks", "spawner_blocks_work", "minecraft:spawner_blocks_work", "advance_time", "minecraft:advance_time", "mob_explosion_drop_decay", "minecraft:mob_explosion_drop_decay", "elytra_movement_check", "minecraft:elytra_movement_check", "fall_damage", "minecraft:fall_damage", "log_admin_commands", "minecraft:log_admin_commands", "natural_health_regeneration", "minecraft:natural_health_regeneration", "spawn_monsters", "minecraft:spawn_monsters", "projectiles_can_break_blocks", "minecraft:projectiles_can_break_blocks", "keep_inventory", "minecraft:keep_inventory", "advance_weather", "minecraft:advance_weather", "random_tick_speed", "minecraft:random_tick_speed", "max_block_modifications", "minecraft:max_block_modifications", "global_sound_events", "minecraft:global_sound_events", "spawn_phantoms", "minecraft:spawn_phantoms", "block_explosion_drop_decay", "minecraft:block_explosion_drop_decay", "forgive_dead_players", "minecraft:forgive_dead_players", "reduced_debug_info", "minecraft:reduced_debug_info", "tnt_explosion_drop_decay", "minecraft:tnt_explosion_drop_decay", "player_movement_check", "minecraft:player_movement_check", "max_command_sequence_length", "minecraft:max_command_sequence_length", "spectators_generate_chunks", "minecraft:spectators_generate_chunks", "command_blocks_work", "minecraft:command_blocks_work", "freeze_damage", "minecraft:freeze_damage", "send_command_feedback", "minecraft:send_command_feedback", "show_death_messages", "minecraft:show_death_messages", "limited_crafting", "minecraft:limited_crafting", "max_snow_accumulation_height", "minecraft:max_snow_accumulation_height", "block_drops", "minecraft:block_drops", "tnt_explodes", "minecraft:tnt_explodes", "water_source_conversion", "minecraft:water_source_conversion", "fire_damage", "minecraft:fire_damage", "fire_spread_radius_around_player", "minecraft:fire_spread_radius_around_player", "pvp", "minecraft:pvp", "raids", "minecraft:raids", "mob_drops", "minecraft:mob_drops", "command_block_output", "minecraft:command_block_output", "immediate_respawn", "minecraft:immediate_respawn", "show_advancement_messages", "minecraft:show_advancement_messages", "spawn_patrols", "minecraft:spawn_patrols", "spawn_mobs", "minecraft:spawn_mobs", "entity_drops", "minecraft:entity_drops", "drowning_damage", "minecraft:drowning_damage", "spawn_wardens", "minecraft:spawn_wardens", "players_nether_portal_default_delay", "minecraft:players_nether_portal_default_delay", "respawn_radius", "minecraft:respawn_radius", "max_entity_cramming", "minecraft:max_entity_cramming"]),
("item", &["replace", "fill", "override", "modify"]),
("item replace entity target slots", &["from", "with"]),
("item fill entity target slots", &["from", "with"]),
("item override entity target slots", &["from", "with"]),
("loot replace entity entities slot", &["fish", "loot", "kill", "mine", "count"]),
("loot replace entity entities slot fish loot_table pos", &["tool", "mainhand", "offhand"]),
("loot replace entity entities slot mine pos", &["tool", "mainhand", "offhand"]),
("loot replace entity entities slot count fish loot_table pos", &["tool", "mainhand", "offhand"]),
("loot replace entity entities slot count mine pos", &["tool", "mainhand", "offhand"]),
("loot replace block targetPos slot", &["fish", "loot", "kill", "mine", "count"]),
("loot replace block targetPos slot fish loot_table pos", &["tool", "mainhand", "offhand"]),
("loot replace block targetPos slot mine pos", &["tool", "mainhand", "offhand"]),
("loot replace block targetPos slot count fish loot_table pos", &["tool", "mainhand", "offhand"]),
("loot replace block targetPos slot count mine pos", &["tool", "mainhand", "offhand"]),
("loot insert targetPos fish loot_table pos", &["tool", "mainhand", "offhand"]),
("loot insert targetPos mine pos", &["tool", "mainhand", "offhand"]),
("loot give players fish loot_table pos", &["tool", "mainhand", "offhand"]),
("loot give players mine pos", &["tool", "mainhand", "offhand"]),
("loot spawn targetPos fish loot_table pos", &["tool", "mainhand", "offhand"]),
("loot spawn targetPos mine pos", &["tool", "mainhand", "offhand"]),
("scoreboard players", &["list", "set", "get", "add", "remove", "reset", "enable", "display", "operation"]),
];