From 8c611e677b6e84f27116cd0c486f2f64703e1568 Mon Sep 17 00:00:00 2001 From: some-du6e <103129948+some-du6e@users.noreply.github.com> Date: Sat, 24 Oct 2026 14:44:17 -0600 Subject: [PATCH 1/5] Advancement titles and descriptions show a whole text component A server's custom advancements often name themselves with an empty text and the words in its siblings ({"text":"","extra":[...]}); only the top-level text or translate key was read, so their tooltips were blank. Read them as the component they are (ComponentSerialization), with siblings, styles, translation arguments and fallbacks. Co-Authored-By: Claude Opus 5.5 --- .../horizon-client/src/game/advancements.rs | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/crates/horizon-client/src/game/advancements.rs b/crates/horizon-client/src/game/advancements.rs index b0f948c5d..20d54d290 100644 --- a/crates/horizon-client/src/game/advancements.rs +++ b/crates/horizon-client/src/game/advancements.rs @@ -1051,17 +1051,10 @@ impl Game<'_> { } } } -/// A text component from advancement JSON (`translate` or `text`). +/// An advancement's title or description: a whole component (ComponentSerialization.CODEC), +/// with its siblings and styles, as a plugin's `{"text":"","extra":[...]}` needs. pub(super) fn text_of(v: &Value) -> Text { - if let Some(key) = v["translate"].as_str() { - Text::translate(key, &[]) - } else if let Some(s) = v["text"].as_str() { - Text::literal(s) - } else if let Some(s) = v.as_str() { - Text::literal(s) - } else { - Text::empty() - } + horizon_client::scoreboard::comp_text(v) } #[cfg(test)] @@ -1095,6 +1088,20 @@ mod tests { (seen, None) } + #[test] + fn titles_keep_their_siblings_and_styles() { + let title = text_of(&serde_json::json!({ + "text": "", + "extra": [{"text": "Quest ", "color": "gold"}, "Board"], + })); + assert_eq!(title.plain(), "Quest Board"); + assert_eq!(title.spans[0].style.color, Some(horizon_client::text::GOLD)); + assert_eq!( + text_of(&serde_json::json!({"translate": "advancements.story.root.title"})), + Text::translate("advancements.story.root.title", &[]) + ); + } + #[test] fn toasts_slide_in_squared_and_out_after_five_seconds() { let mut toast = recipes(1); From 3dc14b6eda81e87b88676c87c277a910babad7fa Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sun, 25 Oct 2026 01:29:12 +0200 Subject: [PATCH 2/5] Advancement chat names: the description goes after the title's siblings Advancement.decorateName appends a new line and the description to the title's copy; adv_name replaced the title's extra list, so a title built from siblings (a plugin's {"text":"","extra":[...]}) reached clients as just the description. Co-Authored-By: Claude Opus 5.5 --- .../horizon-client/src/game/advancements.rs | 37 ++++++++++++++++--- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/crates/horizon-client/src/game/advancements.rs b/crates/horizon-client/src/game/advancements.rs index 20d54d290..c6f3a2410 100644 --- a/crates/horizon-client/src/game/advancements.rs +++ b/crates/horizon-client/src/game/advancements.rs @@ -886,14 +886,15 @@ pub(super) fn adv_name(a: &adv::Advancement) -> Text { _ => text::GREEN, }; // Advancement.decorateName: the title in the frame's colour (styles - // merged into it), a new line and the description. + // merged into it), then a new line and the description after the + // title's own siblings. let coloured = text_of(&d.title).with_color(color); let mut component = coloured.component(); if let Some(o) = component.as_object_mut() { - o.insert( - "extra".into(), - serde_json::json!(["\n", text_of(&d.description).component()]), - ); + let extra = o.entry("extra").or_insert_with(|| serde_json::json!([])); + if let Some(extra) = extra.as_array_mut() { + extra.extend(["\n".into(), text_of(&d.description).component()]); + } } let tooltip = coloured .append("\n") @@ -1102,6 +1103,32 @@ mod tests { ); } + #[test] + fn chat_hover_keeps_the_titles_siblings_before_the_description() { + let a = adv::Advancement { + id: "quests:board".into(), + parent: None, + display: Some(adv::Display { + icon: "minecraft:book".into(), + title: serde_json::json!({"text": "", "extra": ["Quest ", "Board"]}), + description: serde_json::json!("Open the board"), + frame: Frame::Task, + background: None, + show_toast: true, + announce: true, + hidden: false, + }), + criteria: Vec::new(), + requirements: Vec::new(), + rewards: adv::Rewards::default(), + }; + // The JSON a client receives, not just the local spans. + let name = adv_name(&a).component(); + let hover = &name["with"][0]["hover_event"]["value"]; + let sent = horizon_client::scoreboard::comp_text(hover); + assert_eq!(sent.plain(), "Quest Board\nOpen the board"); + } + #[test] fn toasts_slide_in_squared_and_out_after_five_seconds() { let mut toast = recipes(1); From 7a7bfdde7963809848d03b7749637bdf7f5c5a96 Mon Sep 17 00:00:00 2001 From: some-du6e <103129948+some-du6e@users.noreply.github.com> Date: Sat, 24 Oct 2026 18:39:57 -0600 Subject: [PATCH 3/5] Advancement chat hover: the description takes the title's own style Advancement.decorateName merges the frame colour under the title's own style and appends the description after its siblings. Built from the parsed Text, a styled root with siblings had its style moved down a level, so the description showed in the frame colour instead of the title's (a gold, bold title gave a green description). The hover is now built on the title's JSON, and the local spans are decoded from that JSON, so an in-frame player sees the description coloured as a client does. Co-Authored-By: Claude Opus 5.5 --- .../horizon-client/src/game/advancements.rs | 124 +++++++++++++----- 1 file changed, 92 insertions(+), 32 deletions(-) diff --git a/crates/horizon-client/src/game/advancements.rs b/crates/horizon-client/src/game/advancements.rs index c6f3a2410..62b931040 100644 --- a/crates/horizon-client/src/game/advancements.rs +++ b/crates/horizon-client/src/game/advancements.rs @@ -881,31 +881,40 @@ pub(super) fn adv_name(a: &adv::Advancement) -> Text { let Some(d) = &a.display else { return Text::literal(a.id.clone()); }; - let color = match d.frame { - Frame::Challenge => text::DARK_PURPLE, - _ => text::GREEN, - }; - // Advancement.decorateName: the title in the frame's colour (styles - // merged into it), then a new line and the description after the - // title's own siblings. - let coloured = text_of(&d.title).with_color(color); - let mut component = coloured.component(); - if let Some(o) = component.as_object_mut() { - let extra = o.entry("extra").or_insert_with(|| serde_json::json!([])); - if let Some(extra) = extra.as_array_mut() { - extra.extend(["\n".into(), text_of(&d.description).component()]); - } - } - let tooltip = coloured - .append("\n") - .append(text_of(&d.description)) - .with_component(component); + let color = frame_color(d.frame); let title = text_of(&d.title).with_style(&Style { - hover: Some(Box::new(tooltip)), + hover: Some(Box::new(decorate_name(d))), ..Style::default() }); Text::translate("chat.square_brackets", &[title]).with_color(color) } +fn frame_color(frame: Frame) -> u32 { + match frame { + Frame::Challenge => text::DARK_PURPLE, + _ => text::GREEN, + } +} +/// `Advancement.decorateName`: a copy of the title with the frame's colour +/// under its own style (mergeStyles), then a new line and the description +/// after the title's own siblings, so both inherit the title's root style. +/// Built on the title's JSON: a parsed Text moves a styled root's style down +/// a level once it has siblings. +fn decorate_name(d: &adv::Display) -> Text { + let mut component = match &d.title { + Value::Object(_) => d.title.clone(), + Value::String(s) => serde_json::json!({ "text": s }), + other => text_of(other).component(), + }; + if let Some(o) = component.as_object_mut() { + let frame = Text::empty().with_color(frame_color(d.frame)).component(); + o.entry("color").or_insert_with(|| frame["color"].clone()); + let extra = o.entry("extra").or_insert_with(|| serde_json::json!([])); + if let Some(extra) = extra.as_array_mut() { + extra.extend(["\n".into(), d.description.clone()]); + } + } + text_of(&component).with_component(component) +} impl Game<'_> { /// `AdvancementCommands.Action.GRANT` on one advancement (or one of /// its criteria): false when nothing changed. @@ -1096,22 +1105,27 @@ mod tests { "extra": [{"text": "Quest ", "color": "gold"}, "Board"], })); assert_eq!(title.plain(), "Quest Board"); - assert_eq!(title.spans[0].style.color, Some(horizon_client::text::GOLD)); + assert_eq!(title.spans[0].style.color, Some(text::GOLD)); + assert_eq!(title.spans[1].style.color, None); + let vanilla = text_of(&serde_json::json!({"translate": "advancements.story.root.title"})); assert_eq!( - text_of(&serde_json::json!({"translate": "advancements.story.root.title"})), + vanilla, Text::translate("advancements.story.root.title", &[]) ); + assert_eq!( + vanilla.translation_key(), + Some("advancements.story.root.title") + ); } - #[test] - fn chat_hover_keeps_the_titles_siblings_before_the_description() { - let a = adv::Advancement { + fn announced(title: Value, description: Value) -> adv::Advancement { + adv::Advancement { id: "quests:board".into(), parent: None, display: Some(adv::Display { icon: "minecraft:book".into(), - title: serde_json::json!({"text": "", "extra": ["Quest ", "Board"]}), - description: serde_json::json!("Open the board"), + title, + description, frame: Frame::Task, background: None, show_toast: true, @@ -1121,12 +1135,58 @@ mod tests { criteria: Vec::new(), requirements: Vec::new(), rewards: adv::Rewards::default(), - }; - // The JSON a client receives, not just the local spans. - let name = adv_name(&a).component(); - let hover = &name["with"][0]["hover_event"]["value"]; - let sent = horizon_client::scoreboard::comp_text(hover); + } + } + /// The chat hover: the JSON a client receives, and the spans drawn here. + fn hover(a: &adv::Advancement) -> (Value, Text) { + let local = decorate_name(a.display.as_ref().unwrap()); + let sent = adv_name(a).component()["with"][0]["hover_event"]["value"].clone(); + (sent, local) + } + + #[test] + fn chat_hover_keeps_the_titles_siblings_before_the_description() { + let a = announced( + serde_json::json!({"text": "", "extra": [{"text": "Quest ", "color": "gold"}, "Board"]}), + serde_json::json!("Open the board"), + ); + let (sent, local) = hover(&a); + let sent = horizon_client::scoreboard::comp_text(&sent); assert_eq!(sent.plain(), "Quest Board\nOpen the board"); + let colors = |t: &Text| t.spans.iter().map(|s| s.style.color).collect::>(); + let (gold, green) = (Some(text::GOLD), Some(text::GREEN)); + assert_eq!(colors(&sent), [gold, green, green, green]); + assert_eq!(colors(&local), colors(&sent)); + } + + #[test] + fn chat_hover_description_takes_a_styled_titles_own_style() { + // mergeStyles keeps the title's gold; the description inherits it. + let a = announced( + serde_json::json!({"text": "Quest", "color": "gold", "bold": true, "extra": [" Board"]}), + serde_json::json!("Open the board"), + ); + let (sent, local) = hover(&a); + let sent = horizon_client::scoreboard::comp_text(&sent); + let last = &sent.spans.last().unwrap().style; + assert_eq!((last.color, last.bold), (Some(text::GOLD), Some(true))); + assert_eq!(local.spans.last().unwrap().style, *last); + } + + #[test] + fn chat_hover_of_a_vanilla_advancement() { + let a = announced( + serde_json::json!({"translate": "advancements.story.root.title"}), + serde_json::json!({"translate": "advancements.story.root.description"}), + ); + assert_eq!( + hover(&a).0, + serde_json::json!({ + "translate": "advancements.story.root.title", + "color": "green", + "extra": ["\n", {"translate": "advancements.story.root.description"}], + }) + ); } #[test] From 9f1a8809518bd6070d7f97f92b64c4673ff83c65 Mon Sep 17 00:00:00 2001 From: some-du6e <103129948+some-du6e@users.noreply.github.com> Date: Sat, 24 Oct 2026 18:43:58 -0600 Subject: [PATCH 4/5] Advancement chat hover: a title in list form keeps its first element's style A component list is its first element with the rest as siblings, so decorateName merges the frame colour under that element's style. The parsed list moved a styled first element down a level, which gave the description the frame colour instead of the title's. Co-Authored-By: Claude Opus 5.5 --- .../horizon-client/src/game/advancements.rs | 43 ++++++++++++++----- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/crates/horizon-client/src/game/advancements.rs b/crates/horizon-client/src/game/advancements.rs index 62b931040..bb50e79bf 100644 --- a/crates/horizon-client/src/game/advancements.rs +++ b/crates/horizon-client/src/game/advancements.rs @@ -900,11 +900,7 @@ fn frame_color(frame: Frame) -> u32 { /// Built on the title's JSON: a parsed Text moves a styled root's style down /// a level once it has siblings. fn decorate_name(d: &adv::Display) -> Text { - let mut component = match &d.title { - Value::Object(_) => d.title.clone(), - Value::String(s) => serde_json::json!({ "text": s }), - other => text_of(other).component(), - }; + let mut component = root_component(&d.title); if let Some(o) = component.as_object_mut() { let frame = Text::empty().with_color(frame_color(d.frame)).component(); o.entry("color").or_insert_with(|| frame["color"].clone()); @@ -915,6 +911,25 @@ fn decorate_name(d: &adv::Display) -> Text { } text_of(&component).with_component(component) } +/// A component's JSON as one object whose root keeps its own style: a list is +/// its first element with the rest appended to its siblings. +fn root_component(v: &Value) -> Value { + match v { + Value::Object(_) => v.clone(), + Value::String(s) => serde_json::json!({ "text": s }), + Value::Array(list) if !list.is_empty() => { + let mut root = root_component(&list[0]); + if let Some(o) = root.as_object_mut() { + let extra = o.entry("extra").or_insert_with(|| serde_json::json!([])); + if let Some(extra) = extra.as_array_mut() { + extra.extend(list[1..].iter().cloned()); + } + } + root + } + other => text_of(other).component(), + } +} impl Game<'_> { /// `AdvancementCommands.Action.GRANT` on one advancement (or one of /// its criteria): false when nothing changed. @@ -1156,6 +1171,7 @@ mod tests { let colors = |t: &Text| t.spans.iter().map(|s| s.style.color).collect::>(); let (gold, green) = (Some(text::GOLD), Some(text::GREEN)); assert_eq!(colors(&sent), [gold, green, green, green]); + // The spans drawn here come from the same JSON a client receives. assert_eq!(colors(&local), colors(&sent)); } @@ -1166,11 +1182,18 @@ mod tests { serde_json::json!({"text": "Quest", "color": "gold", "bold": true, "extra": [" Board"]}), serde_json::json!("Open the board"), ); - let (sent, local) = hover(&a); - let sent = horizon_client::scoreboard::comp_text(&sent); - let last = &sent.spans.last().unwrap().style; - assert_eq!((last.color, last.bold), (Some(text::GOLD), Some(true))); - assert_eq!(local.spans.last().unwrap().style, *last); + let list = announced( + serde_json::json!([{"text": "Quest", "color": "gold", "bold": true}, " Board"]), + serde_json::json!("Open the board"), + ); + for a in [a, list] { + let (sent, local) = hover(&a); + let sent = horizon_client::scoreboard::comp_text(&sent); + assert_eq!(sent.plain(), "Quest Board\nOpen the board"); + let last = &sent.spans.last().unwrap().style; + assert_eq!((last.color, last.bold), (Some(text::GOLD), Some(true))); + assert_eq!(local.spans.last().unwrap().style, *last); + } } #[test] From f66c257ae595d0316802db4b5f6d5765b0ea2da2 Mon Sep 17 00:00:00 2001 From: some-du6e <103129948+some-du6e@users.noreply.github.com> Date: Sat, 24 Oct 2026 18:46:24 -0600 Subject: [PATCH 5/5] Advancement chat hover: normalise the title with canonical_component scoreboard::canonical_component already re-encodes a component as vanilla does, list form included, so decorate_name uses it instead of its own copy. Co-Authored-By: Claude Opus 5.5 --- .../horizon-client/src/game/advancements.rs | 33 +++++-------------- 1 file changed, 9 insertions(+), 24 deletions(-) diff --git a/crates/horizon-client/src/game/advancements.rs b/crates/horizon-client/src/game/advancements.rs index bb50e79bf..0f76d0ca9 100644 --- a/crates/horizon-client/src/game/advancements.rs +++ b/crates/horizon-client/src/game/advancements.rs @@ -897,10 +897,14 @@ fn frame_color(frame: Frame) -> u32 { /// `Advancement.decorateName`: a copy of the title with the frame's colour /// under its own style (mergeStyles), then a new line and the description /// after the title's own siblings, so both inherit the title's root style. -/// Built on the title's JSON: a parsed Text moves a styled root's style down -/// a level once it has siblings. +/// Built on the title's JSON (a list as its first element with the rest as +/// siblings): a parsed Text moves a styled root's style down a level once it +/// has siblings. fn decorate_name(d: &adv::Display) -> Text { - let mut component = root_component(&d.title); + let mut component = match horizon_client::scoreboard::canonical_component(&d.title) { + Value::String(s) => serde_json::json!({ "text": s }), + c => c, + }; if let Some(o) = component.as_object_mut() { let frame = Text::empty().with_color(frame_color(d.frame)).component(); o.entry("color").or_insert_with(|| frame["color"].clone()); @@ -911,25 +915,6 @@ fn decorate_name(d: &adv::Display) -> Text { } text_of(&component).with_component(component) } -/// A component's JSON as one object whose root keeps its own style: a list is -/// its first element with the rest appended to its siblings. -fn root_component(v: &Value) -> Value { - match v { - Value::Object(_) => v.clone(), - Value::String(s) => serde_json::json!({ "text": s }), - Value::Array(list) if !list.is_empty() => { - let mut root = root_component(&list[0]); - if let Some(o) = root.as_object_mut() { - let extra = o.entry("extra").or_insert_with(|| serde_json::json!([])); - if let Some(extra) = extra.as_array_mut() { - extra.extend(list[1..].iter().cloned()); - } - } - root - } - other => text_of(other).component(), - } -} impl Game<'_> { /// `AdvancementCommands.Action.GRANT` on one advancement (or one of /// its criteria): false when nothing changed. @@ -1178,7 +1163,7 @@ mod tests { #[test] fn chat_hover_description_takes_a_styled_titles_own_style() { // mergeStyles keeps the title's gold; the description inherits it. - let a = announced( + let object = announced( serde_json::json!({"text": "Quest", "color": "gold", "bold": true, "extra": [" Board"]}), serde_json::json!("Open the board"), ); @@ -1186,7 +1171,7 @@ mod tests { serde_json::json!([{"text": "Quest", "color": "gold", "bold": true}, " Board"]), serde_json::json!("Open the board"), ); - for a in [a, list] { + for a in [object, list] { let (sent, local) = hover(&a); let sent = horizon_client::scoreboard::comp_text(&sent); assert_eq!(sent.plain(), "Quest Board\nOpen the board");