diff --git a/crates/horizon-client/src/creative.rs b/crates/horizon-client/src/creative.rs index e1d1c262e..249e40b11 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,17 @@ 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 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(&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; @@ -314,11 +366,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 +815,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 +868,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 3fcddb9ac..0dfc21f1e 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -5334,22 +5334,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 }; @@ -5403,14 +5413,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); } } } @@ -9446,6 +9454,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; @@ -9515,9 +9528,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), @@ -9628,7 +9642,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 b84f13e4a..69c06d97e 100644 --- a/crates/horizon-client/src/game/commands.rs +++ b/crates/horizon-client/src/game/commands.rs @@ -444,7 +444,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/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 812c9ce07..0e385e25c 100644 --- a/crates/horizon-client/src/game/options.rs +++ b/crates/horizon-client/src/game/options.rs @@ -247,6 +247,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..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| self.pack.names.get(key).map(str::to_owned), + &|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 d3c14ffc7..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| self.pack.names.get(k).map(str::to_owned), + &|k| self.pack.names.display_get(k), ) }) { diff --git a/crates/horizon-client/src/game/remote.rs b/crates/horizon-client/src/game/remote.rs index 0e35438e0..1aca018d7 100644 --- a/crates/horizon-client/src/game/remote.rs +++ b/crates/horizon-client/src/game/remote.rs @@ -4906,6 +4906,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 5efc3dd0b..2f50ad9ab 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 9f0b3068d..bc9b1a6fb 100644 --- a/crates/horizon-client/src/game/storage.rs +++ b/crates/horizon-client/src/game/storage.rs @@ -273,7 +273,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); @@ -301,9 +302,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 94ec4b7ab..cb96cc373 100644 --- a/crates/horizon-client/src/lang.rs +++ b/crates/horizon-client/src/lang.rs @@ -138,6 +138,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 764abe0d9..3b2b8fd31 100644 --- a/crates/horizon-client/src/menu.rs +++ b/crates/horizon-client/src/menu.rs @@ -1001,7 +1001,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 18aec0bea..1986c5b1d 100644 --- a/crates/horizon-client/src/net.rs +++ b/crates/horizon-client/src/net.rs @@ -686,8 +686,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 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 { + 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())