From 11130e6ef7bf8d75ed006d3b7c63a81a9110422a Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Fri, 16 Oct 2026 09:43:29 +0200 Subject: [PATCH 1/3] LAN guest: command feedback names the guest and shows its numbers Feedback about the player (target_name) names the guest a command runs for. A client reading a server's chat now unwraps NbtOps' {"": value} wrapper of any bare value, not only strings, so translation arguments that are numbers show ("Replaced 1 slot(s)", the coordinates). horizon-ctl messages reads a server's chat too. Part of #435 Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/game.rs | 3 ++ crates/horizon-client/src/game/agent.rs | 2 +- crates/horizon-client/src/game/commands.rs | 14 +++++--- crates/horizon-client/src/game/lan_actions.rs | 2 ++ crates/horizon-client/src/game/remote.rs | 6 ++++ crates/horizon-protocol/src/text.rs | 35 +++++++++++++++++-- tools/lan_e2e.py | 23 ++++++++++-- 7 files changed, 73 insertions(+), 12 deletions(-) diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index d85489f3a..005d40b86 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -1030,6 +1030,8 @@ struct Game<'a> { /// have each chest open. lid_openers: HashMap<(i32, i32, i32), i32>, lan_acting: Option, + /// The name of the guest `lan_acting` acts for (`Player.getName`). + lan_acting_name: Option, /// Command feedback to forward to a guest. chat_capture: Option>, /// State of `/spectate`, `/posteffect`, `/debug`, `/waypoint` and friends. @@ -10179,6 +10181,7 @@ pub fn run() -> Result<()> { lan_entity_events: Vec::new(), lid_openers: HashMap::new(), lan_acting: None, + lan_acting_name: None, chat_capture: None, cmds: Default::default(), ui: Default::default(), diff --git a/crates/horizon-client/src/game/agent.rs b/crates/horizon-client/src/game/agent.rs index 62b4f8624..8f535b14e 100644 --- a/crates/horizon-client/src/game/agent.rs +++ b/crates/horizon-client/src/game/agent.rs @@ -630,7 +630,7 @@ impl Game<'_> { fn messages_value(&self, n: usize) -> Value { let titles = &self.titles; json!({ - "chat": self.ui.chat.recent_lines(n), + "chat": self.remote_chat(n).unwrap_or_else(|| self.ui.chat.recent_lines(n)), "order": "newest first", "title": (titles.time > 0).then(|| titles.title.as_ref().map(|t| t.plain())).flatten(), "subtitle": (titles.time > 0).then(|| titles.subtitle.as_ref().map(|t| t.plain())).flatten(), diff --git a/crates/horizon-client/src/game/commands.rs b/crates/horizon-client/src/game/commands.rs index a7385914b..e31c5ef3d 100644 --- a/crates/horizon-client/src/game/commands.rs +++ b/crates/horizon-client/src/game/commands.rs @@ -315,11 +315,15 @@ impl Game<'_> { /// Entity.getDisplayName. pub(super) fn target_name(&self, t: Target) -> Text { match t { - Target::Player => match self.score.board.players_team(PLAYER_NAME) { - // PlayerTeam.formatNameForTeam. - Some(team) => team.formatted_name(Text::literal(PLAYER_NAME)), - None => Text::literal(PLAYER_NAME), - }, + Target::Player => { + // A guest's commands name the guest. + let name = self.lan_acting_name.as_deref().unwrap_or(PLAYER_NAME); + match self.score.board.players_team(name) { + // PlayerTeam.formatNameForTeam. + Some(team) => team.formatted_name(Text::literal(name)), + None => Text::literal(name), + } + } Target::Item(id) => { let item = self .dropped diff --git a/crates/horizon-client/src/game/lan_actions.rs b/crates/horizon-client/src/game/lan_actions.rs index 52170de55..53d4a5906 100644 --- a/crates/horizon-client/src/game/lan_actions.rs +++ b/crates/horizon-client/src/game/lan_actions.rs @@ -154,9 +154,11 @@ impl Game<'_> { self.close_ender_chest(); std::mem::swap(&mut self.ender_items, &mut g.ender_items); self.lan_acting = Some(conn); + self.lan_acting_name = Some(g.name.clone()); let result = f(self); self.lan_acting = None; + self.lan_acting_name = None; // An ender chest the guest opened: the menu shows their inventory // itself (lan_open_container), not a stand-in block entity. self.close_ender_chest(); diff --git a/crates/horizon-client/src/game/remote.rs b/crates/horizon-client/src/game/remote.rs index db2cab0d0..2c5f2cb28 100644 --- a/crates/horizon-client/src/game/remote.rs +++ b/crates/horizon-client/src/game/remote.rs @@ -372,6 +372,12 @@ impl Game<'_> { } } + /// The server's last `n` chat lines, newest first. + pub(super) fn remote_chat(&self, n: usize) -> Option> { + let r = self.remote.as_ref()?; + Some(r.chat.iter().rev().take(n).map(|l| l.0.clone()).collect()) + } + /// Process everything the network thread received (once per frame, like /// the client's packet processor). pub(super) fn poll_remote(&mut self) -> Result<()> { diff --git a/crates/horizon-protocol/src/text.rs b/crates/horizon-protocol/src/text.rs index 7a23f16a8..cc44430fb 100644 --- a/crates/horizon-protocol/src/text.rs +++ b/crates/horizon-protocol/src/text.rs @@ -47,9 +47,10 @@ fn append(tag: &Tag, lang: &Language, out: &mut String, depth: usize) { Tag::Compound(_) => { if let Some(text) = get(tag, "text").and_then(string) { out.push_str(&text); - } else if let Some(text) = get(tag, "").and_then(string) { - // Mixed-list wrapper for a bare string. - out.push_str(&text); + } else if let Some(value) = get(tag, "") { + // NbtOps' wrapper for a bare value in a mixed list (a + // translation's number and string arguments). + append(value, lang, out, depth + 1); } else if let Some(key) = get(tag, "translate").and_then(string) { let args: Vec = match get(tag, "with") { Some(Tag::List(args)) => args @@ -154,6 +155,34 @@ mod tests { assert_eq!(format_java("100%% sure", &[]), "100% sure"); } + #[test] + fn unwraps_mixed_list_arguments() { + let mut lang = Language::new(); + lang.insert( + "commands.item.entity.set.success.single".into(), + "Replaced %s slot(s) on %s with %s".into(), + ); + // `with: [1, {text: "Alex"}, ...]` in NBT: the int comes wrapped. + let replaced = Tag::compound([ + ( + "translate", + Tag::String("commands.item.entity.set.success.single".into()), + ), + ( + "with", + Tag::List(vec![ + Tag::compound([("", Tag::Int(1))]), + Tag::compound([("text", Tag::String("Alex".into()))]), + Tag::compound([("", Tag::String("[Emerald]".into()))]), + ]), + ), + ]); + assert_eq!( + plain(&replaced, &lang), + "Replaced 1 slot(s) on Alex with [Emerald]" + ); + } + #[test] fn flattens_components() { let mut lang = Language::new(); diff --git a/tools/lan_e2e.py b/tools/lan_e2e.py index 37a220e52..4f6443485 100755 --- a/tools/lan_e2e.py +++ b/tools/lan_e2e.py @@ -18,7 +18,8 @@ address. The script then checks, from both sides, what a guest's game used to ge drowning and the void (then respawns); - pvp: the guest and the host hit each other with a sword; with the pvp game rule off, nothing; - containers: the guest's ender chest holds the guest's items, not the host's, and a double chest - opens as 9x6 with the right half first. + opens as 9x6 with the right half first; +- feedback: the guest's command feedback names the guest and shows the numbers. Each check is reported on its own (a failing one doesn't stop the others) and the screenshots of both sides go to --out (host-*.png, guest-*.png). @@ -45,7 +46,7 @@ from agent_control_e2e import Cli, Failed, game_env # noqa: E402 ROOT = Path(__file__).resolve().parents[1] GUEST_NAME = 'Guest' -CHECKS = ['tab', 'self', 'armour', 'nametags', 'chest', 'crafting', 'damage', 'mobs', 'hazards', 'pvp', 'containers'] +CHECKS = ['tab', 'self', 'armour', 'nametags', 'chest', 'crafting', 'damage', 'mobs', 'hazards', 'pvp', 'containers', 'feedback'] class Game: @@ -453,10 +454,26 @@ def check_containers(host, guest, out): return {'ender': ender, 'double': double, 'taken': taken} +def check_feedback(host, guest, out): + x, y, z = pos_of(guest) + guest('command', command='item replace entity @s weapon.mainhand with minecraft:stick') + guest('command', command=f'tp @s {x:.1f} {y:.1f} {z:.1f}') + guest.wait(10) + chat = guest.raw('messages', 5)['chat'] + guest.raw('key', 't', 'tap') + guest.wait(5) + guest.shot(out, 'feedback') + guest.raw('key', 'esc', 'tap') + replaced = f'Replaced 1 slot(s) on {GUEST_NAME} with [Stick]' + assert any(replaced in line for line in chat), f'no "{replaced}" in {chat}' + assert any(line.startswith(f'Teleported {GUEST_NAME} to {x:.6f}') for line in chat), f'teleport feedback: {chat}' + return chat + + CHECK_FNS = {'tab': check_tab, 'self': check_self, 'armour': check_armour, 'nametags': check_nametags, 'chest': check_chest, 'crafting': check_crafting, 'damage': check_damage, 'mobs': check_mobs, 'hazards': check_hazards, 'pvp': check_pvp, - 'containers': check_containers} + 'containers': check_containers, 'feedback': check_feedback} def run(ctl, out, resources, checks): From 984a06e582ef9c28a18c09fce4a5c0f19b2bb9f1 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Fri, 16 Oct 2026 10:24:07 +0200 Subject: [PATCH 2/3] tools/lan_e2e.py: feedback expects the rounded position and closes the chat Co-Authored-By: Claude Opus 5.5 --- tools/lan_e2e.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/lan_e2e.py b/tools/lan_e2e.py index 4f6443485..6f0a79b81 100755 --- a/tools/lan_e2e.py +++ b/tools/lan_e2e.py @@ -455,7 +455,7 @@ def check_containers(host, guest, out): def check_feedback(host, guest, out): - x, y, z = pos_of(guest) + x, y, z = (round(v, 1) for v in pos_of(guest)) guest('command', command='item replace entity @s weapon.mainhand with minecraft:stick') guest('command', command=f'tp @s {x:.1f} {y:.1f} {z:.1f}') guest.wait(10) @@ -464,9 +464,12 @@ def check_feedback(host, guest, out): guest.wait(5) guest.shot(out, 'feedback') guest.raw('key', 'esc', 'tap') + guest.wait(5) + screen = guest('state').get('screen') replaced = f'Replaced 1 slot(s) on {GUEST_NAME} with [Stick]' assert any(replaced in line for line in chat), f'no "{replaced}" in {chat}' assert any(line.startswith(f'Teleported {GUEST_NAME} to {x:.6f}') for line in chat), f'teleport feedback: {chat}' + assert screen in (None, 'playing'), f'the chat did not close: {screen}' return chat From 3e6052ac92b915c3af012c6ce331b386804e9334 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Fri, 16 Oct 2026 10:28:22 +0200 Subject: [PATCH 3/3] control: keys reach a server's chat input The control socket's key command went straight to key_pressed, so Escape paused the game instead of closing the chat a server connection opens (remote_chat_key handles the real keyboard). Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/game/control.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/crates/horizon-client/src/game/control.rs b/crates/horizon-client/src/game/control.rs index 921ca03db..bf4672140 100644 --- a/crates/horizon-client/src/game/control.rs +++ b/crates/horizon-client/src/game/control.rs @@ -580,6 +580,18 @@ impl Game<'_> { fn control_key_down(&mut self, key: KeyCode) -> Result<()> { self.physical_keys.insert(key); + // A server's chat input takes the keys first, as remote_chat_key does. + if self.remote_chat_open() { + use winit::keyboard::NamedKey; + let named = match key { + KeyCode::Escape => Some(NamedKey::Escape), + KeyCode::Enter | KeyCode::NumpadEnter => Some(NamedKey::Enter), + KeyCode::Backspace => Some(NamedKey::Backspace), + _ => None, + }; + self.remote_chat_input(named, None); + return Ok(()); + } if self.screen == Screen::Chat { self.chat_key_code(key, None); return Ok(());