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);