From 4d477067c3204e1152b1b46c319b6dead85ebf15 Mon Sep 17 00:00:00 2001 From: masa-masa-0314 <348336850+masa-masa-0314@users.noreply.github.com> Date: Wed, 28 Oct 2026 22:52:46 +0800 Subject: [PATCH] Chat and books: open a show_dialog click event's dialog A server may put a show_dialog click event on a chat line or a book page; ClickEvent.Action.SHOW_DIALOG allows it from a server, and vanilla opens the dialog through Screen.defaultHandleGameClickEvent. Horizon dropped the click event while parsing the component (no arm for it in component.rs, no ClickEvent variant to carry it), so clicking the text did nothing. The dialog now survives as ClickEvent::ShowDialog (a registry id or the inline dialog), parses from click_event, round-trips back out, and both click handlers (chat and BookViewScreen) open it with show_dialog_ref, the same path a server's show_dialog packet takes. Co-Authored-By: ZCode --- crates/horizon-client-core/src/component.rs | 5 +++++ crates/horizon-client-core/src/text.rs | 8 ++++++++ crates/horizon-client/src/game/books.rs | 3 +++ crates/horizon-client/src/game/chat.rs | 3 +++ crates/horizon-client/src/game/dialogs.rs | 2 +- 5 files changed, 20 insertions(+), 1 deletion(-) diff --git a/crates/horizon-client-core/src/component.rs b/crates/horizon-client-core/src/component.rs index 248c78617..0826245f0 100644 --- a/crates/horizon-client-core/src/component.rs +++ b/crates/horizon-client-core/src/component.rs @@ -195,6 +195,11 @@ fn object_style(o: &serde_json::Map) -> Style { Some("copy_to_clipboard") => { text("value").map(crate::text::ClickEvent::CopyToClipboard) } + // ClickEvent.ShowDialog.CODEC: a `minecraft:dialog` registry id or + // the dialog itself; the server may send it (isAllowedFromServer). + Some("show_dialog") => e.get("dialog").map(|dialog| { + crate::text::ClickEvent::ShowDialog(crate::scoreboard::json_to_tag(dialog)) + }), _ => None, }; } diff --git a/crates/horizon-client-core/src/text.rs b/crates/horizon-client-core/src/text.rs index 243a3ae3c..12cc196d9 100644 --- a/crates/horizon-client-core/src/text.rs +++ b/crates/horizon-client-core/src/text.rs @@ -50,6 +50,9 @@ pub enum ClickEvent { /// `ClickEvent.RunCommand`: the command, with or without its `/`. RunCommand(String), CopyToClipboard(String), + /// `ClickEvent.ShowDialog`: a `minecraft:dialog` registry id, or the + /// dialog itself as the component carried it. + ShowDialog(horizon_world::nbt::Tag), /// A local file to open with the system handler. /// Only allow this in locally constructed messages, never server/LAN text. OpenFile(String), @@ -557,6 +560,11 @@ fn style_json(style: &Style) -> Vec<(String, Value)> { ClickEvent::RunCommand(command) => { json!({ "action": "run_command", "command": command }) } + // ClickEvent.ShowDialog.CODEC: the dialog the server sent it with. + ClickEvent::ShowDialog(dialog) => json!({ + "action": "show_dialog", + "dialog": crate::scoreboard::tag_to_json(dialog), + }), ClickEvent::OpenFile(path) => json!({ "action": "open_file", "path": path }), }; out.push(("click_event".to_owned(), event)); diff --git a/crates/horizon-client/src/game/books.rs b/crates/horizon-client/src/game/books.rs index 4c1a03129..18616ac57 100644 --- a/crates/horizon-client/src/game/books.rs +++ b/crates/horizon-client/src/game/books.rs @@ -151,6 +151,9 @@ impl Game<'_> { use horizon_client::clipboard::Clipboard; self.clipboard.set(&value); } + // BookViewScreen.handleClickEvent: the rest is + // Screen.defaultHandleGameClickEvent's. + ClickEvent::ShowDialog(dialog) => self.show_dialog_ref(&dialog), _ => {} } } diff --git a/crates/horizon-client/src/game/chat.rs b/crates/horizon-client/src/game/chat.rs index 4ed7a0571..568bd848e 100644 --- a/crates/horizon-client/src/game/chat.rs +++ b/crates/horizon-client/src/game/chat.rs @@ -786,6 +786,9 @@ impl Game<'_> { } } Some(ClickEvent::RunCommand(command)) => self.click_command(&command), + // Screen.defaultHandleGameClickEvent: the dialog opens over the + // screen, and closes back to it. + Some(ClickEvent::ShowDialog(dialog)) => self.show_dialog_ref(&dialog), // Screen.defaultHandleClickEvent: a page link means nothing in chat. Some(ClickEvent::ChangePage(_)) | None => {} } diff --git a/crates/horizon-client/src/game/dialogs.rs b/crates/horizon-client/src/game/dialogs.rs index 4928b0aa8..9a8a23017 100644 --- a/crates/horizon-client/src/game/dialogs.rs +++ b/crates/horizon-client/src/game/dialogs.rs @@ -163,7 +163,7 @@ impl Game<'_> { } /// A `show_dialog` click event's dialog: a registry id or the dialog itself. - fn show_dialog_ref(&mut self, dialog: &Tag) { + pub(super) fn show_dialog_ref(&mut self, dialog: &Tag) { match dialog { Tag::String(id) => { let id = id.to_string_lossy();