From 239755edd8973236fc3d0e70e005245fb9cb3896 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Fri, 9 Oct 2026 13:29:47 +0200 Subject: [PATCH] Show the recipe unlocked toast Unlocking recipes through advancement rewards now shows the "New Recipe(s) Unlocked!" toast with the recipe's result item and "Check your recipe book" underneath, one toast for a burst of unlocks. Co-Authored-By: Claude Sonnet 5.5 --- .../horizon-client/src/game/advancements.rs | 39 ++++++++++++++++++- crates/horizon-client/src/game/recipe_book.rs | 25 ++++++++++++ 2 files changed, 62 insertions(+), 2 deletions(-) diff --git a/crates/horizon-client/src/game/advancements.rs b/crates/horizon-client/src/game/advancements.rs index 50382bb9d..1b12491b0 100644 --- a/crates/horizon-client/src/game/advancements.rs +++ b/crates/horizon-client/src/game/advancements.rs @@ -20,6 +20,26 @@ pub(super) struct Toast { frame: Frame, title: Text, shown: Option, + /// A `RecipeToast`: the icon is a recipe result. + recipe: bool, +} +impl Toast { + pub(super) fn is_recipe(&self) -> bool { + self.recipe + } + pub(super) fn was_shown(&self) -> bool { + self.shown.is_some() + } + /// `RecipeToast`: "New Recipe(s) Unlocked!" with the recipe's result. + pub(super) fn recipe(icon: &str) -> Self { + Self { + icon: icon.to_owned(), + frame: Frame::Task, + title: Text::literal(""), + shown: None, + recipe: true, + } + } } #[derive(Default)] pub(super) struct AdvState { @@ -27,7 +47,7 @@ pub(super) struct AdvState { pub(super) progress: Progress, loaded: bool, pub(super) recipes: BTreeSet, - toasts: VecDeque, + pub(super) toasts: VecDeque, /// Awards skip the toast (`/advancement grant ... everything`). pub(super) quiet: bool, /// The inventory last seen by `inventory_changed`. @@ -339,6 +359,7 @@ impl Game<'_> { frame: d.frame, title: text_of(&d.title), shown: None, + recipe: false, }); } if d.announce && self.ui.rules.bool("show_advancement_messages") { @@ -354,6 +375,7 @@ impl Game<'_> { )); } } + self.recipe_toast(&unlocked); for r in unlocked { self.trigger("minecraft:recipe_unlocked", |c, _| { c["recipes"].as_str() == Some(r.as_str()) @@ -576,7 +598,20 @@ impl Game<'_> { } else { 1.0 }; - let (title, frame, icon) = (t.title.clone(), t.frame, t.icon.clone()); + let (title, frame, icon, recipe) = (t.title.clone(), t.frame, t.icon.clone(), t.recipe); + if recipe { + // RecipeToast: black description under a purple title. + let atlas = &self.res.atlas; + let x = batch.width - 160.0 * slide; + batch.sprite(atlas, "gui/sprites/toast/recipe", x, 0.0); + let title = self.translate("recipe.toast.title", "New Recipe(s) Unlocked!"); + let description = self.translate("recipe.toast.description", "Check your recipe book"); + let atlas = &self.res.atlas; + batch.text(atlas, &title, x + 30.0, 7.0, 0xFF50_0050, false); + batch.text(atlas, &description, x + 30.0, 18.0, 0xFF00_0000, false); + self.draw_item(batch, &ItemStack::new(&icon, 1), x + 8.0, 8.0); + return; + } if frame == Frame::Challenge && ms < 50.0 { self.audio .play("minecraft:ui.toast.challenge_complete", None, 1.0, 1.0); diff --git a/crates/horizon-client/src/game/recipe_book.rs b/crates/horizon-client/src/game/recipe_book.rs index 995b2704c..658db4ada 100644 --- a/crates/horizon-client/src/game/recipe_book.rs +++ b/crates/horizon-client/src/game/recipe_book.rs @@ -173,6 +173,31 @@ impl Game<'_> { search.reset_blink(); } + /// The toast for newly unlocked recipes: one for a burst of unlocks. + pub(super) fn recipe_toast(&mut self, recipes: &[String]) { + if recipes.is_empty() || self.adv.quiet { + return; + } + self.ensure_book(); + let icon = self + .recipe_ui + .book + .as_ref() + .and_then(|b| recipes.iter().find_map(|id| b.entry(id))) + .map(|e| e.result.item.to_string()); + let Some(icon) = icon else { return }; + let fresh = self + .adv + .toasts + .back() + .is_some_and(|t| t.is_recipe() && !t.was_shown()); + if !fresh { + self.adv + .toasts + .push_back(super::advancements::Toast::recipe(&icon)); + } + } + // ---- recipes and what can be crafted ---- /// The grid size of the open crafting menu.