Files
horizon-airdef/tools/generate_command_suggestions.py
T
Ludovic Marie 5411923887 Join guests as PlayerList.placeNewPlayer does and send vanilla's command tree
Send the join packets in vanilla's order with the permission level entity
event, recipe book, server data, ticking state and post effects; announce
the newcomer only to the others; list players with every info action;
use vanilla's level key order and border warning time; sync the game time
every 20 ticks without clocks and the overworld clock only when it jumps.
Build the command tree from the commands report for the player's
permission level and server kind, with vanilla's suggestion providers
(VanillaCommandSuggestionsExporter), and answer command suggestions.
The tree matches what a vanilla integrated server sends node for node.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-10 22:23:05 +02:00

43 lines
1.9 KiB
Python

#!/usr/bin/env python3
"""Generate crates/horizon-client/src/lan/command_suggestions.rs: the argument
nodes of vanilla's command tree that have a custom suggestion provider, and
the provider's network name (ClientboundCommandsPacket sends it; the commands
report does not). The list comes from VanillaCommandSuggestionsExporter run
against the pinned client jar:
javac --release 25 -proc:none -sourcepath mods/horizon/src/test/java -cp CLIENT_CP \\
-d BUILD mods/horizon/src/test/java/dev/horizonlab/parity/VanillaCommandSuggestionsExporter.java
java -cp BUILD:CLIENT_CP dev.horizonlab.parity.VanillaCommandSuggestionsExporter suggestions.tsv
generate_command_suggestions.py suggestions.tsv
"""
import argparse
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
def main():
parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument("tsv", type=Path)
parser.add_argument("--out", type=Path, default=ROOT / "crates/horizon-client/src/lan/command_suggestions.rs")
args = parser.parse_args()
rows = sorted(tuple(line.split("\t")) for line in args.tsv.read_text().splitlines() if line.strip())
if len(rows) < 50:
raise SystemExit(f"only {len(rows)} nodes")
lines = [
"//! Argument nodes of vanilla's command tree with a custom suggestion",
"//! provider (path of node names from the root, provider network name).",
"//! Generated by tools/generate_command_suggestions.py from",
"//! VanillaCommandSuggestionsExporter; do not edit by hand.",
"",
"pub const SUGGESTIONS: &[(&str, &str)] = &[",
]
lines += [f' ("{path}", "{provider}"),' for path, provider in rows]
lines += ["];", ""]
args.out.write_text("\n".join(lines))
print(f"wrote {len(rows)} nodes to {args.out}")
if __name__ == "__main__":
main()