From b457f6382a76b2bfa64077fee92a5bbaa9feca61 Mon Sep 17 00:00:00 2001 From: JasonGu <1456970218@qq.com> Date: Sun, 25 Oct 2026 21:41:56 +0800 Subject: [PATCH 1/3] Localization: names, container titles, death text and search follow the language - item and block names in tooltips, held labels, command feedback and the creative tabs read the selected language; the pinned English map stays for logic and search - Game::translate resolves through lang::get_or, so station titles follow the language screen - container titles and Inventory labels for chests, hoppers, furnaces, smokers, blast furnaces, crafters, shulkers and mounts are translated - server-resolved components (menu titles, death messages, command suggestion tooltips) load the selected language over en_us, and follow a language change while a world is open - death messages always reach the death screen translated; the chat broadcast still obeys showDeathMessages - creative search matches the localized display name - sign editors use sign.edit and hanging_sign.edit Co-Authored-By: OpenCode DeepSeek V4.1 Flash --- crates/horizon-client/src/creative.rs | 86 ++++++++++++++++++- crates/horizon-client/src/game.rs | 57 ++++++++---- crates/horizon-client/src/game/commands.rs | 2 +- crates/horizon-client/src/game/lan_actions.rs | 50 +++++------ crates/horizon-client/src/game/machines.rs | 50 +++++++---- .../src/game/machines/crafter.rs | 3 +- crates/horizon-client/src/game/mount_menu.rs | 3 +- crates/horizon-client/src/game/options.rs | 1 + crates/horizon-client/src/game/packs.rs | 1 + crates/horizon-client/src/game/potions.rs | 2 +- crates/horizon-client/src/game/recipe_book.rs | 2 +- crates/horizon-client/src/game/remote.rs | 9 ++ crates/horizon-client/src/game/sign_edit.rs | 11 +-- crates/horizon-client/src/game/stations.rs | 33 ++++--- crates/horizon-client/src/game/storage.rs | 6 +- crates/horizon-client/src/game/titles.rs | 2 +- crates/horizon-client/src/game/tweaks.rs | 2 +- crates/horizon-client/src/lang.rs | 5 ++ crates/horizon-client/src/menu.rs | 2 +- crates/horizon-client/src/net.rs | 12 +-- 20 files changed, 236 insertions(+), 103 deletions(-) diff --git a/crates/horizon-client/src/creative.rs b/crates/horizon-client/src/creative.rs index e1d1c262e..593aad61d 100644 --- a/crates/horizon-client/src/creative.rs +++ b/crates/horizon-client/src/creative.rs @@ -71,10 +71,52 @@ impl Names { .cloned() .unwrap_or_else(|| path.replace('_', " ")) } + /// An item's display name in the selected language: `item.*` then + /// `block.*`, then the pinned English map (`Names::item`). + pub fn display_item(&self, id: &str) -> String { + let (namespace, path) = id.split_once(':').unwrap_or(("minecraft", id)); + if let Some(lang) = crate::lang::current() { + for prefix in ["item", "block"] { + if let Some(name) = lang.get(&format!("{prefix}.{namespace}.{path}")) { + return name.to_owned(); + } + } + } + self.item(id) + } + /// A translation key's text in the selected language, else the pinned + /// English map (`HoverName` and tooltip keys such as potion names). + pub fn display_get(&self, key: &str) -> Option { + crate::lang::current() + .and_then(|lang| lang.get(key).map(str::to_owned)) + .or_else(|| self.get(key).map(str::to_owned)) + } pub fn get(&self, key: &str) -> Option<&str> { self.map.get(key).map(String::as_str) } } + +/// `CreativeModeTabs`' key for an exported tab id (`itemGroup.*`); the +/// export's `title` is the English fallback. +pub fn item_group_key(id: &str) -> Option<&'static str> { + Some(match id.trim_start_matches("minecraft:") { + "building_blocks" => "itemGroup.buildingBlocks", + "colored_blocks" => "itemGroup.coloredBlocks", + "natural_blocks" => "itemGroup.natural", + "functional_blocks" => "itemGroup.functional", + "redstone_blocks" => "itemGroup.redstone", + "hotbar" => "itemGroup.hotbar", + "search" => "itemGroup.search", + "tools_and_utilities" => "itemGroup.tools", + "combat" => "itemGroup.combat", + "food_and_drinks" => "itemGroup.foodAndDrink", + "ingredients" => "itemGroup.ingredients", + "spawn_eggs" => "itemGroup.spawnEggs", + "op_blocks" => "itemGroup.op", + "inventory" => "itemGroup.inventory", + _ => return None, + }) +} impl Creative { pub const WIDTH: f32 = 195.0; pub const HEIGHT: f32 = 136.0; @@ -303,7 +345,11 @@ impl Creative { .collect(); } // FullTextSearchTree: tooltip lines, and the item id after a colon. + // The export's lines are English (they come from the vanilla jars); + // the display name in the selected language is matched too, so a + // localized search finds the item. let text = java_lower(term); + let localized = |i: usize| java_lower(&names.display_item(&self.search_items[i].item)); all.filter(|&i| { let e = &self.search_index[i]; let fallback; @@ -314,11 +360,15 @@ impl Creative { &e.lines }; match text.split_once(':') { - None => any(lines.iter().map(String::as_str), &text), + None => { + any(lines.iter().map(String::as_str), &text) || localized(i).contains(&text) + } Some((ns, path)) => { let (ns, path) = (java_trim(ns), java_trim(path)); e.namespace.contains(ns) - && (e.path.contains(path) || any(lines.iter().map(String::as_str), path)) + && (e.path.contains(path) + || any(lines.iter().map(String::as_str), path) + || localized(i).contains(path)) } } }) @@ -759,6 +809,24 @@ mod tests { assert_eq!(q("#craft"), Vec::::new()); } + #[test] + fn search_matches_the_display_name_in_the_selected_language() { + let c = creative(0); + let names = Names { + map: HashMap::from([ + ("item.minecraft.anvil".to_owned(), "铁砧".to_owned()), + ("item.minecraft.wooden_hoe".to_owned(), "木锄".to_owned()), + ]), + }; + let q = |s: &str| c.search_results(s, &names); + assert_eq!(q("铁砧"), [0]); + assert_eq!(q("木锄"), [2]); + // The English tooltip lines the export indexed still match. + assert_eq!(q("anvil"), [0]); + // A colon's path searches the display name too. + assert_eq!(q("minecraft:铁砧"), [0]); + } + #[test] fn scrollbar_drag_follows_the_mouse_while_held() { let mut c = creative(90); @@ -794,6 +862,20 @@ mod tests { assert!(!c.scrolling); } + #[test] + fn creative_tab_titles_have_vanilla_keys() { + assert_eq!( + item_group_key("minecraft:building_blocks"), + Some("itemGroup.buildingBlocks") + ); + assert_eq!( + item_group_key("minecraft:food_and_drinks"), + Some("itemGroup.foodAndDrink") + ); + assert_eq!(item_group_key("minecraft:hotbar"), Some("itemGroup.hotbar")); + assert_eq!(item_group_key("minecraft:nonsense"), None); + } + #[test] fn wheel_moves_one_row_per_notch() { let mut c = creative(90); diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index 653a1d038..6bd8f88cb 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -5296,22 +5296,32 @@ impl Game<'_> { Some(BlockEntity::Chest(_)) if self.draw_machine_screen(batch, ox, oy) => {} Some(BlockEntity::Chest(_)) => self.draw_chest_screen(batch, ox, oy), Some(BlockEntity::Furnace(f)) => { - let (tex, title) = match f.kind { + let (tex, key, fallback) = match f.kind { horizon_client::containers::FurnaceKind::Furnace => { - ("gui/container/furnace", "Furnace") - } - horizon_client::containers::FurnaceKind::BlastFurnace => { - ("gui/container/blast_furnace", "Blast Furnace") + ("gui/container/furnace", "container.furnace", "Furnace") } + horizon_client::containers::FurnaceKind::BlastFurnace => ( + "gui/container/blast_furnace", + "container.blast_furnace", + "Blast Furnace", + ), horizon_client::containers::FurnaceKind::Smoker => { - ("gui/container/smoker", "Smoker") + ("gui/container/smoker", "container.smoker", "Smoker") } }; part(batch, tex, 0.0, 0.0, 176.0, 166.0, ox, oy); - let title = &self.container_title(title.to_owned()); - let tw = HudBatch::text_width(atlas, title); - batch.text(atlas, title, ox + (176.0 - tw) / 2.0, oy + 6.0, grey, false); - batch.text(atlas, "Inventory", ox + 8.0, oy + 72.0, grey, false); + let title = self.container_title(self.translate(key, fallback)); + let tw = HudBatch::text_width(atlas, &title); + batch.text( + atlas, + &title, + ox + (176.0 - tw) / 2.0, + oy + 6.0, + grey, + false, + ); + let inventory = self.translate("container.inventory", "Inventory"); + batch.text(atlas, &inventory, ox + 8.0, oy + 72.0, grey, false); if f.lit_remaining > 0 { // AbstractFurnaceScreen: flame height ceil(lit * 13) + 1. let total = if f.lit_total == 0 { 200 } else { f.lit_total }; @@ -5365,14 +5375,12 @@ impl Game<'_> { "gui/container/inventory" }; part(batch, texture, 0.0, 0.0, 176.0, 166.0, ox, oy); - let (title, tx) = if self.craft_size == 3 { - ("Crafting", 29.0) - } else { - ("Crafting", 97.0) - }; - batch.text(atlas, title, ox + tx, oy + 6.0, grey, false); + let title = self.translate("container.crafting", "Crafting"); + let tx = if self.craft_size == 3 { 29.0 } else { 97.0 }; + batch.text(atlas, &title, ox + tx, oy + 6.0, grey, false); if self.craft_size == 3 { - batch.text(atlas, "Inventory", ox + 8.0, oy + 72.0, grey, false); + let inventory = self.translate("container.inventory", "Inventory"); + batch.text(atlas, &inventory, ox + 8.0, oy + 72.0, grey, false); } } } @@ -9402,6 +9410,11 @@ impl Game<'_> { fn creative_origin(batch: &HudBatch) -> (f32, f32) { batch.centered_origin(Creative::WIDTH, Creative::HEIGHT) } + /// A creative tab's title: `itemGroup.*`, else the export's English title. + fn creative_tab_title(&self, tab: &horizon_client::creative::Tab) -> String { + horizon_client::creative::item_group_key(&tab.id) + .map_or_else(|| tab.title.clone(), |key| self.translate(key, &tab.title)) + } /// Vanilla tooltip: dark box with a purple gradient border. fn tooltip(&self, batch: &mut HudBatch, text: &str, x: f32, y: f32) { let atlas = &self.gui.atlas; @@ -9471,9 +9484,10 @@ impl Game<'_> { } let atlas = &self.gui.atlas; if !tab.inventory { + let title = self.creative_tab_title(&tab); batch.text( atlas, - &tab.title, + &title, ox + 8.0, oy + 6.0, rgba(64, 64, 64, 255), @@ -9584,7 +9598,12 @@ impl Game<'_> { && self.cursor.1 >= oy + ty && self.cursor.1 < oy + ty + 32.0 { - self.tooltip(batch, &t.title, self.cursor.0, self.cursor.1); + self.tooltip( + batch, + &self.creative_tab_title(t), + self.cursor.0, + self.cursor.1, + ); } } self.draw_carried(batch); diff --git a/crates/horizon-client/src/game/commands.rs b/crates/horizon-client/src/game/commands.rs index 2e551f440..1bb468a7f 100644 --- a/crates/horizon-client/src/game/commands.rs +++ b/crates/horizon-client/src/game/commands.rs @@ -439,7 +439,7 @@ impl Game<'_> { .find(|i| i.id == id) .map(|i| i.stack.item.to_string()) .unwrap_or_default(); - Text::literal(self.pack.names.item(&item)) + Text::literal(self.pack.names.display_item(&item)) } Target::Mob(id) if self diff --git a/crates/horizon-client/src/game/lan_actions.rs b/crates/horizon-client/src/game/lan_actions.rs index 2c7019c73..03bb15b65 100644 --- a/crates/horizon-client/src/game/lan_actions.rs +++ b/crates/horizon-client/src/game/lan_actions.rs @@ -1791,33 +1791,33 @@ impl Game<'_> { // ServerPlayer.die: dropAllDeathLoot unless a spectator, from the eyes less 0.3. let drops = (g.game_mode != SPECTATOR) .then(|| [at[0], at[1] + g.eye_height() - 0.3, at[2]]); + // ServerPlayer.die: the death screen always shows the message; + // chat only when the rule allows and the team does not hide it. let cause = host.play.get_mut(&conn).and_then(|p| p.death_cause.take()); - let message = match cause { - // ServerPlayer.die: the death message, to everyone unless - // the player's team hides it. - Some(key) if self.ui.rules.bool("show_death_messages") => { - let text = horizon_client::text::Text::translate( - &key, - &[self.player_text(&name, uuid)], - ); - let message = horizon_client::lan::data::component_nbt(&text.component()); - let team = self.score.board.players_team(&name); - if horizon_client::scoreboard::own_death_message_shown(team) { - host.hub.system_message(message.clone()); - if self.options.dedicated.is_some() { - super::dedicated::log( - "INFO", - &format!("System chat: {}", text.plain()), - ); - } else if self.player.is_some() { - self.system_message(text); - } - } - message + let key = cause.unwrap_or_else(|| { + if at[1] < f64::from(horizon_client::chunk::MIN_Y - 64) { + "death.attack.outOfWorld".into() + } else { + "death.attack.generic".into() } - Some(_) => literal(""), - None => literal(&format!("{name} died")), - }; + }); + let text = + horizon_client::text::Text::translate(&key, &[self.player_text(&name, uuid)]); + let message = horizon_client::lan::data::component_nbt(&text.component()); + if self.ui.rules.bool("show_death_messages") { + let team = self.score.board.players_team(&name); + if horizon_client::scoreboard::own_death_message_shown(team) { + host.hub.system_message(message.clone()); + if self.options.dedicated.is_some() { + super::dedicated::log( + "INFO", + &format!("System chat: {}", text.plain()), + ); + } else if self.player.is_some() { + self.system_message(text); + } + } + } host.hub.send_to( conn, &C::PlayerCombatKill(play::PlayerCombatKill { id, message }), diff --git a/crates/horizon-client/src/game/machines.rs b/crates/horizon-client/src/game/machines.rs index 8ce1940c9..6866552c1 100644 --- a/crates/horizon-client/src/game/machines.rs +++ b/crates/horizon-client/src/game/machines.rs @@ -889,13 +889,31 @@ impl Game<'_> { let key_is_cart = self .container .is_some_and(|k| k.1 == super::minecarts::CART_KEY_Y); - let (texture, height, title) = match screen { - Screen::Hopper if key_is_cart => { - ("gui/container/hopper", 133.0, "Minecart with Hopper") - } - Screen::Hopper => ("gui/container/hopper", 133.0, "Item Hopper"), - Screen::Dispenser => ("gui/container/dispenser", 166.0, "Dispenser"), - Screen::Dropper => ("gui/container/dispenser", 166.0, "Dropper"), + let (texture, height, key, fallback) = match screen { + Screen::Hopper if key_is_cart => ( + "gui/container/hopper", + 133.0, + "entity.minecraft.hopper_minecart", + "Minecart with Hopper", + ), + Screen::Hopper => ( + "gui/container/hopper", + 133.0, + "container.hopper", + "Item Hopper", + ), + Screen::Dispenser => ( + "gui/container/dispenser", + 166.0, + "container.dispenser", + "Dispenser", + ), + Screen::Dropper => ( + "gui/container/dispenser", + 166.0, + "container.dropper", + "Dropper", + ), }; if let Some(mut r) = atlas.sprites.get(texture).copied() { let dv = (r.v1 - r.v0) / r.h as f32; @@ -905,23 +923,17 @@ impl Game<'_> { batch.rect_uv(ox, oy, 176.0, height, r, u32::MAX); } let grey = horizon_client::hud::rgba(64, 64, 64, 255); - let title = &self + let title = self .remote_menu_title() - .unwrap_or_else(|| self.container_title(title.to_owned())); + .unwrap_or_else(|| self.container_title(self.translate(key, fallback))); let title_x = if screen == Screen::Hopper { 8.0 } else { - (176.0 - horizon_client::hud::HudBatch::text_width(atlas, title)) / 2.0 + (176.0 - horizon_client::hud::HudBatch::text_width(atlas, &title)) / 2.0 }; - batch.text(atlas, title, ox + title_x, oy + 6.0, grey, false); - batch.text( - atlas, - "Inventory", - ox + 8.0, - oy + height - 94.0, - grey, - false, - ); + batch.text(atlas, &title, ox + title_x, oy + 6.0, grey, false); + let inventory = self.translate("container.inventory", "Inventory"); + batch.text(atlas, &inventory, ox + 8.0, oy + height - 94.0, grey, false); true } } diff --git a/crates/horizon-client/src/game/machines/crafter.rs b/crates/horizon-client/src/game/machines/crafter.rs index 0fe66f7c8..b76bafd64 100644 --- a/crates/horizon-client/src/game/machines/crafter.rs +++ b/crates/horizon-client/src/game/machines/crafter.rs @@ -256,7 +256,8 @@ impl Game<'_> { grey, false, ); - batch.text(atlas, "Inventory", ox + 8.0, oy + 72.0, grey, false); + let inventory = self.translate("container.inventory", "Inventory"); + batch.text(atlas, &inventory, ox + 8.0, oy + 72.0, grey, false); self.paint_screen(batch, ox, oy, rest, true); } /// `gui.togglable_slot` over an empty, enabled grid slot. diff --git a/crates/horizon-client/src/game/mount_menu.rs b/crates/horizon-client/src/game/mount_menu.rs index e9e1e380b..c80c900f9 100644 --- a/crates/horizon-client/src/game/mount_menu.rs +++ b/crates/horizon-client/src/game/mount_menu.rs @@ -470,7 +470,8 @@ impl Game<'_> { None => String::new(), }; batch.text(atlas, &title, ox + 8.0, oy + 6.0, grey, false); - batch.text(atlas, "Inventory", ox + 8.0, oy + 72.0, grey, false); + let inventory = self.translate("container.inventory", "Inventory"); + batch.text(atlas, &inventory, ox + 8.0, oy + 72.0, grey, false); if let Some(m) = self.mobs.iter().find(|m| m.id == open.mob) { self.draw_mob_preview( batch, diff --git a/crates/horizon-client/src/game/options.rs b/crates/horizon-client/src/game/options.rs index d947f91d0..bb78b8bf8 100644 --- a/crates/horizon-client/src/game/options.rs +++ b/crates/horizon-client/src/game/options.rs @@ -246,6 +246,7 @@ impl Game<'_> { pub(super) fn load_language(&mut self, code: &str) { let root = self.options.resources.clone(); lang::set(lang::Language::load(&[&root], code)); + self.refresh_remote_language(); self.ui.chat.rescale(&self.gui.atlas); } /// Settings that Horizon applies beyond render distance, volume and GUI scale. diff --git a/crates/horizon-client/src/game/packs.rs b/crates/horizon-client/src/game/packs.rs index 7629a5d25..733b19649 100644 --- a/crates/horizon-client/src/game/packs.rs +++ b/crates/horizon-client/src/game/packs.rs @@ -203,6 +203,7 @@ impl Game<'_> { horizon_client::mobs::villager_hats::VillagerHats::load(root); horizon_client::ui::load_metadata(root); lang::set(lang::Language::load(&[&root.to_path_buf()], &lang::code())); + self.refresh_remote_language(); self.audio.reload(root); self.clear_lod(); self.streaming.reload_resources(&mut self.world, context); diff --git a/crates/horizon-client/src/game/potions.rs b/crates/horizon-client/src/game/potions.rs index b17316e08..49e171ce1 100644 --- a/crates/horizon-client/src/game/potions.rs +++ b/crates/horizon-client/src/game/potions.rs @@ -755,7 +755,7 @@ impl Game<'_> { image_width, &self.potions.effects.list, self.clock.rate(), - &|key| self.pack.names.get(key).map(str::to_owned), + &|key| Some(horizon_client::lang::get(key)), &|text| self.gui.atlas.font.width(text).ceil() as i32, ); if let Some(lines) = inventory_effects::paint( diff --git a/crates/horizon-client/src/game/recipe_book.rs b/crates/horizon-client/src/game/recipe_book.rs index d3c14ffc7..f68460b7d 100644 --- a/crates/horizon-client/src/game/recipe_book.rs +++ b/crates/horizon-client/src/game/recipe_book.rs @@ -502,7 +502,7 @@ impl Game<'_> { horizon_client::item_tooltip::lines( stack, self.res.items().get(&stack.item), - &|k| self.pack.names.get(k).map(str::to_owned), + &|k| Some(horizon_client::lang::get(k)), ) }) { diff --git a/crates/horizon-client/src/game/remote.rs b/crates/horizon-client/src/game/remote.rs index 5a71b13a8..e7be063e6 100644 --- a/crates/horizon-client/src/game/remote.rs +++ b/crates/horizon-client/src/game/remote.rs @@ -4990,6 +4990,15 @@ impl Game<'_> { pub(super) fn remote_menu_title(&self) -> Option { self.remote.as_ref()?.menu_title.clone() } + /// A language change reaches the server-sent components too: their titles + /// are resolved when the packet arrives, with the session's language. + pub(super) fn refresh_remote_language(&mut self) { + if let Some(lang) = horizon_client::lang::current() + && let Some(r) = self.remote.as_mut() + { + r.lang = Arc::new(lang.map().clone()); + } + } /// A server's chest-like menu (`MenuType.GENERIC_9xN`): its rows and title. pub(super) fn remote_chest_menu(&self) -> Option<(usize, String)> { let r = self.remote.as_ref()?; diff --git a/crates/horizon-client/src/game/sign_edit.rs b/crates/horizon-client/src/game/sign_edit.rs index 5a26e3e69..e8ee0a94d 100644 --- a/crates/horizon-client/src/game/sign_edit.rs +++ b/crates/horizon-client/src/game/sign_edit.rs @@ -248,13 +248,14 @@ impl Game<'_> { let atlas = &self.gui.atlas; let (w, h) = (batch.width, batch.height); batch.fill(atlas, 0.0, 0.0, w, h, rgba(16, 16, 16, 160)); - let title = if sign.hanging { - "Edit Hanging Sign Message" + let (key, fallback) = if sign.hanging { + ("hanging_sign.edit", "Edit Hanging Sign Message") } else { - "Edit Sign Message" + ("sign.edit", "Edit Sign Message") }; - let tw = HudBatch::text_width(atlas, title); - batch.text(atlas, title, (w - tw) / 2.0, 40.0, u32::MAX, true); + let title = self.translate(key, fallback); + let tw = HudBatch::text_width(atlas, &title); + batch.text(atlas, &title, (w - tw) / 2.0, 40.0, u32::MAX, true); let name = self .res .facts() diff --git a/crates/horizon-client/src/game/stations.rs b/crates/horizon-client/src/game/stations.rs index ffe56d699..2501e892d 100644 --- a/crates/horizon-client/src/game/stations.rs +++ b/crates/horizon-client/src/game/stations.rs @@ -277,15 +277,10 @@ fn argb(c: i32) -> u32 { } impl Game<'_> { - fn data(&self) -> &stations::StationData { - self.res.stations() - } + /// `Component.translatable`: the selected language (which `lang` layers + /// over `en_us`), the caller's English text last. pub(super) fn translate(&self, key: &str, fallback: &str) -> String { - self.data() - .enchantments - .translate(key) - .unwrap_or(fallback) - .to_owned() + horizon_client::lang::get_or(key, fallback) } fn brewing_open(&self) -> bool { matches!(self.container_kind(), Some(BlockEntity::Brewing(_))) @@ -421,7 +416,8 @@ impl Game<'_> { pub(super) fn anvil_item_name(&self, s: &Station) -> String { match &s.inputs[0] { Some(input) - if input.custom_name().is_none() && s.name == self.pack.names.item(&input.item) => + if input.custom_name().is_none() + && s.name == self.pack.names.display_item(&input.item) => { String::new() } @@ -462,7 +458,7 @@ impl Game<'_> { let name = self.anvil_item_name(&s); let hover = s.inputs[0] .as_ref() - .map(|i| stations::hover_name(&|id| self.pack.names.item(id), i)) + .map(|i| stations::hover_name(&|id| self.pack.names.display_item(id), i)) .unwrap_or_default(); s.anvil = stations::anvil_result( &data.enchantments, @@ -895,7 +891,7 @@ impl Game<'_> { s.anvil_last = s.inputs[0].clone(); s.name = s.inputs[0] .as_ref() - .map(|i| stations::hover_name(&|id| self.pack.names.item(id), i)) + .map(|i| stations::hover_name(&|id| self.pack.names.display_item(id), i)) .unwrap_or_default(); } self.station_changed(); @@ -1648,28 +1644,29 @@ impl Game<'_> { let name = if let Some(n) = stack.custom_name() { n.to_owned() } else if stack.data().is_some_and(|d| d.ominous_banner) { - e.translate("block.minecraft.ominous_banner") - .map_or_else(|| "Ominous Banner".to_owned(), str::to_owned) + self.translate("block.minecraft.ominous_banner", "Ominous Banner") } else if stack.data().and_then(|d| d.potion.as_ref()).is_some() || stack.item.ends_with("potion") || &*stack.item == "minecraft:tipped_arrow" { let key = brewing::potion_name_key(&stack.item, stack.potion()); - e.translate(&key) - .map_or_else(|| self.pack.names.item(&stack.item), str::to_owned) + self.pack + .names + .display_get(&key) + .unwrap_or_else(|| self.pack.names.display_item(&stack.item)) } else { - self.pack.names.item(&stack.item) + self.pack.names.display_item(&stack.item) }; let display = horizon_client::item_tooltip::TooltipDisplay::for_stack(stack); let mut lines = Vec::new(); if display.name_visible(self.screen == Screen::Creative) { lines.push((name, color)); } - let translate = |k: &str| e.translate(k).map(str::to_owned); + let translate = |k: &str| self.pack.names.display_get(k); // ItemContainerContents.addToTooltip. let hover_name = |s: &ItemStack| { s.custom_name() - .map_or_else(|| self.pack.names.item(&s.item), str::to_owned) + .map_or_else(|| self.pack.names.display_item(&s.item), str::to_owned) }; if display.shows("minecraft:container") { for line in diff --git a/crates/horizon-client/src/game/storage.rs b/crates/horizon-client/src/game/storage.rs index 9b28ce26b..bc05b546f 100644 --- a/crates/horizon-client/src/game/storage.rs +++ b/crates/horizon-client/src/game/storage.rs @@ -227,7 +227,8 @@ impl Game<'_> { ); let title = self.translate("container.shulkerBox", "Shulker Box"); batch.text(atlas, &title, ox + 8.0, oy + 6.0, grey, false); - batch.text(atlas, "Inventory", ox + 8.0, oy + 73.0, grey, false); + let inventory = self.translate("container.inventory", "Inventory"); + batch.text(atlas, &inventory, ox + 8.0, oy + 73.0, grey, false); return; } let rows = self.chest_rows().unwrap_or(3); @@ -255,9 +256,10 @@ impl Game<'_> { grey, false, ); + let inventory = self.translate("container.inventory", "Inventory"); batch.text( atlas, - "Inventory", + &inventory, ox + 8.0, oy + 114.0 + rows as f32 * 18.0 - 94.0, grey, diff --git a/crates/horizon-client/src/game/titles.rs b/crates/horizon-client/src/game/titles.rs index 70ade5595..cbae1f6b4 100644 --- a/crates/horizon-client/src/game/titles.rs +++ b/crates/horizon-client/src/game/titles.rs @@ -30,7 +30,7 @@ impl Game<'_> { Some(HeldName { item: stack.item.to_string(), hover_name: Text::literal(item_tooltip::name_line(stack, &|key| { - self.pack.names.get(key).map(str::to_owned) + self.pack.names.display_get(key) })), rarity_color: match rarity { "uncommon" => text::YELLOW, diff --git a/crates/horizon-client/src/game/tweaks.rs b/crates/horizon-client/src/game/tweaks.rs index 681368cab..cec83e248 100644 --- a/crates/horizon-client/src/game/tweaks.rs +++ b/crates/horizon-client/src/game/tweaks.rs @@ -399,7 +399,7 @@ impl Game<'_> { } let views: Vec> = slots.iter().map(|&s| self.slot_view(s)).collect(); let clicks = { - let names = |id: &str| self.pack.names.item(id); + let names = |id: &str| self.pack.names.display_item(id); let rank = |s: &ItemStack| { let order = self.creative_screen.order_of(s).unwrap_or(usize::MAX); (order, hover_name(&names, s)) diff --git a/crates/horizon-client/src/lang.rs b/crates/horizon-client/src/lang.rs index 15f47285a..79a06229d 100644 --- a/crates/horizon-client/src/lang.rs +++ b/crates/horizon-client/src/lang.rs @@ -117,6 +117,11 @@ impl Language { pub fn get(&self, key: &str) -> Option<&str> { self.map.get(key).map(String::as_str) } + /// The resolved map, for `horizon_protocol::text::plain`: a server's + /// components carry keys, and the network layer resolves them with this. + pub fn map(&self) -> &HashMap { + &self.map + } pub fn len(&self) -> usize { self.map.len() } diff --git a/crates/horizon-client/src/menu.rs b/crates/horizon-client/src/menu.rs index 07e4ba2b9..912d4498c 100644 --- a/crates/horizon-client/src/menu.rs +++ b/crates/horizon-client/src/menu.rs @@ -995,7 +995,7 @@ impl Menu { fn anvil_result(&mut self, env: &Env) { let hover = self.containers[MAIN][0] .as_ref() - .map(|i| crate::stations::hover_name(&|id| env.names.item(id), i)) + .map(|i| crate::stations::hover_name(&|id| env.names.display_item(id), i)) .unwrap_or_default(); let out = crate::stations::anvil_result( env.enchantments, diff --git a/crates/horizon-client/src/net.rs b/crates/horizon-client/src/net.rs index 9cce9e1c6..2b314f2a8 100644 --- a/crates/horizon-client/src/net.rs +++ b/crates/horizon-client/src/net.rs @@ -597,12 +597,14 @@ pub fn json_text(v: &serde_json::Value, lang: &Language) -> String { } } -/// en_us.json from the prepared resources. +/// The language a session resolves server-sent components with: the client's +/// selected language, layered over `en_us` (`ClientLanguage.loadFrom`), so a +/// menu title the server sends as a key follows the language screen. pub fn load_language(resources: &std::path::Path) -> Language { - std::fs::read(resources.join("assets/minecraft/lang/en_us.json")) - .ok() - .and_then(|b| serde_json::from_slice(&b).ok()) - .unwrap_or_default() + let root = resources.to_path_buf(); + crate::lang::Language::load(&[&root], &crate::lang::code()) + .map() + .clone() } /// Ask a server for its status (ServerStatusPinger): MOTD, players and the From df23e1bfed0c2fde5d9c319ccae18fed3c6b036b Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sun, 25 Oct 2026 17:27:41 +0100 Subject: [PATCH 2/3] Keep vanilla's death screen message; resolve with the loaded language - Leave ServerPlayer.die's message as it was: with showDeathMessages off vanilla sends CommonComponents.EMPTY to the death screen, and #1858 reworks the death message from the combat record. - The effects panel and recipe book tooltips use Names::display_get, so a key missing from the language still falls back instead of showing the key. - net::load_language reuses the language lang already loaded (packs included) instead of reading it from disk again. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/game/lan_actions.rs | 48 +++++++++---------- crates/horizon-client/src/game/potions.rs | 2 +- crates/horizon-client/src/game/recipe_book.rs | 2 +- crates/horizon-client/src/net.rs | 18 ++++--- 4 files changed, 37 insertions(+), 33 deletions(-) diff --git a/crates/horizon-client/src/game/lan_actions.rs b/crates/horizon-client/src/game/lan_actions.rs index 03bb15b65..2c7019c73 100644 --- a/crates/horizon-client/src/game/lan_actions.rs +++ b/crates/horizon-client/src/game/lan_actions.rs @@ -1791,33 +1791,33 @@ impl Game<'_> { // ServerPlayer.die: dropAllDeathLoot unless a spectator, from the eyes less 0.3. let drops = (g.game_mode != SPECTATOR) .then(|| [at[0], at[1] + g.eye_height() - 0.3, at[2]]); - // ServerPlayer.die: the death screen always shows the message; - // chat only when the rule allows and the team does not hide it. let cause = host.play.get_mut(&conn).and_then(|p| p.death_cause.take()); - let key = cause.unwrap_or_else(|| { - if at[1] < f64::from(horizon_client::chunk::MIN_Y - 64) { - "death.attack.outOfWorld".into() - } else { - "death.attack.generic".into() - } - }); - let text = - horizon_client::text::Text::translate(&key, &[self.player_text(&name, uuid)]); - let message = horizon_client::lan::data::component_nbt(&text.component()); - if self.ui.rules.bool("show_death_messages") { - let team = self.score.board.players_team(&name); - if horizon_client::scoreboard::own_death_message_shown(team) { - host.hub.system_message(message.clone()); - if self.options.dedicated.is_some() { - super::dedicated::log( - "INFO", - &format!("System chat: {}", text.plain()), - ); - } else if self.player.is_some() { - self.system_message(text); + let message = match cause { + // ServerPlayer.die: the death message, to everyone unless + // the player's team hides it. + Some(key) if self.ui.rules.bool("show_death_messages") => { + let text = horizon_client::text::Text::translate( + &key, + &[self.player_text(&name, uuid)], + ); + let message = horizon_client::lan::data::component_nbt(&text.component()); + let team = self.score.board.players_team(&name); + if horizon_client::scoreboard::own_death_message_shown(team) { + host.hub.system_message(message.clone()); + if self.options.dedicated.is_some() { + super::dedicated::log( + "INFO", + &format!("System chat: {}", text.plain()), + ); + } else if self.player.is_some() { + self.system_message(text); + } } + message } - } + Some(_) => literal(""), + None => literal(&format!("{name} died")), + }; host.hub.send_to( conn, &C::PlayerCombatKill(play::PlayerCombatKill { id, message }), diff --git a/crates/horizon-client/src/game/potions.rs b/crates/horizon-client/src/game/potions.rs index 49e171ce1..b28c2fb4d 100644 --- a/crates/horizon-client/src/game/potions.rs +++ b/crates/horizon-client/src/game/potions.rs @@ -755,7 +755,7 @@ impl Game<'_> { image_width, &self.potions.effects.list, self.clock.rate(), - &|key| Some(horizon_client::lang::get(key)), + &|key| self.pack.names.display_get(key), &|text| self.gui.atlas.font.width(text).ceil() as i32, ); if let Some(lines) = inventory_effects::paint( diff --git a/crates/horizon-client/src/game/recipe_book.rs b/crates/horizon-client/src/game/recipe_book.rs index f68460b7d..fd44041e5 100644 --- a/crates/horizon-client/src/game/recipe_book.rs +++ b/crates/horizon-client/src/game/recipe_book.rs @@ -502,7 +502,7 @@ impl Game<'_> { horizon_client::item_tooltip::lines( stack, self.res.items().get(&stack.item), - &|k| Some(horizon_client::lang::get(k)), + &|k| self.pack.names.display_get(k), ) }) { diff --git a/crates/horizon-client/src/net.rs b/crates/horizon-client/src/net.rs index 2b314f2a8..8acfa7ec9 100644 --- a/crates/horizon-client/src/net.rs +++ b/crates/horizon-client/src/net.rs @@ -597,14 +597,18 @@ pub fn json_text(v: &serde_json::Value, lang: &Language) -> String { } } -/// The language a session resolves server-sent components with: the client's -/// selected language, layered over `en_us` (`ClientLanguage.loadFrom`), so a -/// menu title the server sends as a key follows the language screen. +/// The language a session resolves server-sent components with: the selected +/// one as `lang` loaded it (`en_us` under it, packs included), so a menu title +/// the server sends as a key follows the language screen. A process with no +/// language set (a dedicated server's log) reads en_us.json. pub fn load_language(resources: &std::path::Path) -> Language { - let root = resources.to_path_buf(); - crate::lang::Language::load(&[&root], &crate::lang::code()) - .map() - .clone() + if let Some(lang) = crate::lang::current() { + return lang.map().clone(); + } + std::fs::read(resources.join("assets/minecraft/lang/en_us.json")) + .ok() + .and_then(|b| serde_json::from_slice(&b).ok()) + .unwrap_or_default() } /// Ask a server for its status (ServerStatusPinger): MOTD, players and the From bdbc816486ea2bc8aa3362a8547be73af897a9a1 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sun, 25 Oct 2026 18:53:20 +0100 Subject: [PATCH 3/3] Creative search: match the localized hover name, not the item's base name The base name (Tipped Arrow, Potion, White Banner) matched where vanilla's first tooltip line (Arrow of Poison, Water Bottle, Ominous Banner) doesn't: the creative harness found extra results for 'e', 'potion', 'tipped' and 'white'. name_line builds the full hover name through display_get. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/creative.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/crates/horizon-client/src/creative.rs b/crates/horizon-client/src/creative.rs index 593aad61d..249e40b11 100644 --- a/crates/horizon-client/src/creative.rs +++ b/crates/horizon-client/src/creative.rs @@ -346,10 +346,16 @@ impl Creative { } // FullTextSearchTree: tooltip lines, and the item id after a colon. // The export's lines are English (they come from the vanilla jars); - // the display name in the selected language is matched too, so a - // localized search finds the item. + // the hover name in the selected language is matched too, so a + // localized search finds the item. It is the whole name (a tipped + // arrow's potion, the ominous banner), as the first line is. let text = java_lower(term); - let localized = |i: usize| java_lower(&names.display_item(&self.search_items[i].item)); + let localized = |i: usize| { + java_lower(&crate::item_tooltip::name_line( + &self.search_items[i], + &|k| names.display_get(k), + )) + }; all.filter(|&i| { let e = &self.search_index[i]; let fallback;