From 1ee64ded5547bd16971650e4cd10e64e3b3e6d09 Mon Sep 17 00:00:00 2001 From: Cosmic <84875247+Online5277@users.noreply.github.com> Date: Fri, 16 Oct 2026 12:10:45 -0400 Subject: [PATCH 1/3] Show equipment attributes in hover tooltips --- crates/horizon-client/src/game/stations.rs | 28 +++++ crates/horizon-client/src/item_tooltip.rs | 130 ++++++++++++++++++--- 2 files changed, 140 insertions(+), 18 deletions(-) diff --git a/crates/horizon-client/src/game/stations.rs b/crates/horizon-client/src/game/stations.rs index d8a5d1416..c6cfd6d82 100644 --- a/crates/horizon-client/src/game/stations.rs +++ b/crates/horizon-client/src/game/stations.rs @@ -1977,6 +1977,34 @@ impl Game<'_> { } } } + if let Some(info) = self.res.items.get(&stack.item) { + let base = |name: &str, default| { + self.player + .as_ref() + .and_then(|player| { + let key = player.attributes.key(name)?; + let handle = player.attributes.lookup(Some(&key))?; + player + .attributes + .instance(&handle) + .ok() + .map(|value| value.base_value()) + }) + .unwrap_or(default) + }; + let player_base = [ + base("minecraft:attack_damage", 1.0), + base( + "minecraft:attack_speed", + horizon_client::attack_strength::BASE_ATTACK_SPEED, + ), + ]; + lines.extend(horizon_client::item_tooltip::attribute_lines( + &info.modifiers, + Some(player_base), + &translate, + )); + } if let Some(info) = self.res.items.get(&stack.item) && info.max_damage > 0 && stack.damage > 0 diff --git a/crates/horizon-client/src/item_tooltip.rs b/crates/horizon-client/src/item_tooltip.rs index cd827d411..dc669e5ea 100644 --- a/crates/horizon-client/src/item_tooltip.rs +++ b/crates/horizon-client/src/item_tooltip.rs @@ -1,8 +1,9 @@ -//! The lines of an item's tooltip as `ItemStack.getTooltipLines` writes them -//! without a player and without advanced tooltips, for stacks as recipes -//! produce them. The recipe book's search tree matches them, so recipes of -//! tools and armour answer to "attack speed" or "when on head". -use crate::items::{ItemInfo, ItemStack}; +//! Item tooltip formatting: equipment modifiers with a player's base values, +//! and lines without player context for the recipe book's search tree. +use crate::{ + hud::rgba, + items::{ItemInfo, ItemStack}, +}; /// `EquipmentSlotGroup` in declaration order, the order tooltips list them in. const SLOT_GROUPS: [&str; 11] = [ @@ -25,6 +26,7 @@ fn modifier_line( attribute: &str, amount: f64, operation: usize, + total: bool, ) -> Option { let text = |key: &str| translate(key).unwrap_or_else(|| key.to_owned()); let scale = match operation { @@ -32,7 +34,9 @@ fn modifier_line( 0 => 1.0, _ => 100.0, }; - let (kind, shown) = if amount > 0.0 { + let (kind, shown) = if total { + ("equals", amount * scale) + } else if amount > 0.0 { ("plus", amount * scale) } else if amount < 0.0 { ("take", -amount * scale) @@ -47,22 +51,27 @@ fn modifier_line( ) } -/// `ItemStack.addAttributeTooltips` for the item's own modifiers: per slot -/// group an empty line, the group's heading and a line per modifier. -fn attribute_lines(info: &ItemInfo, translate: &dyn Fn(&str) -> Option) -> Vec { +/// `ItemStack.addAttributeTooltips`: slot groups, colors and optional player +/// attack damage/speed bases. Recipe search has no player context. +pub fn attribute_lines( + modifiers: &[(String, String, f64, String, String)], + player_base: Option<[f64; 2]>, + translate: &dyn Fn(&str) -> Option, +) -> Vec<(String, u32)> { let mut lines = Vec::new(); for group in SLOT_GROUPS { let mut first = true; - for (attribute, _, amount, operation, slot) in &info.modifiers { + for (attribute, modifier, amount, operation, slot) in modifiers { if slot != group { continue; } if std::mem::take(&mut first) { - lines.push(String::new()); - lines.push( + lines.push((String::new(), u32::MAX)); + lines.push(( translate(&format!("item.modifiers.{group}")) .unwrap_or_else(|| format!("item.modifiers.{group}")), - ); + rgba(170, 170, 170, 255), + )); } let id = match operation.as_str() { "add_multiplied_base" => 1, @@ -70,7 +79,27 @@ fn attribute_lines(info: &ItemInfo, translate: &dyn Fn(&str) -> Option) _ => 0, }; let path = attribute.strip_prefix("minecraft:").unwrap_or(attribute); - lines.extend(modifier_line(translate, path, *amount, id)); + let base = player_base.and_then(|[damage, speed]| match modifier.as_str() { + "minecraft:base_attack_damage" => Some(damage), + "minecraft:base_attack_speed" => Some(speed), + _ => None, + }); + if let Some(line) = modifier_line( + translate, + path, + amount + base.unwrap_or(0.0), + id, + base.is_some(), + ) { + let (line, color) = if base.is_some() { + (format!(" {line}"), rgba(0, 170, 0, 255)) + } else if *amount > 0.0 { + (line, rgba(85, 85, 255, 255)) + } else { + (line, rgba(255, 85, 85, 255)) + }; + lines.push((line, color)); + } } } lines @@ -211,6 +240,7 @@ pub fn detail_lines( attribute, amount * (*amplifier + 1) as f64, operation, + false, ) }) .collect(); @@ -242,7 +272,11 @@ pub fn detail_lines( lines.push(text("item.dyed")); } if let Some(info) = info { - lines.extend(attribute_lines(info, translate)); + lines.extend( + attribute_lines(&info.modifiers, None, translate) + .into_iter() + .map(|(line, _)| line), + ); } lines } @@ -335,6 +369,66 @@ mod tests { assert_eq!(format_amount(0.375), "0.38"); } + #[test] + fn equipment_attributes_use_player_totals_and_slot_group_colors() { + let modifiers = [ + ("attack_damage", "base_attack_damage", 6.0, "mainhand"), + ("attack_speed", "base_attack_speed", -2.4, "mainhand"), + ("armor", "armor", 3.0, "head"), + ] + .map(|(attribute, id, amount, slot)| { + ( + format!("minecraft:{attribute}"), + format!("minecraft:{id}"), + amount, + "add_value".to_owned(), + slot.to_owned(), + ) + }); + let lang = |key: &str| { + Some( + match key { + "item.modifiers.mainhand" => "When in Main Hand:", + "item.modifiers.head" => "When on Head:", + "attribute.modifier.equals.0" => "%s %s", + "attribute.modifier.plus.0" => "+%s %s", + "attribute.modifier.take.0" => "-%s %s", + "attribute.name.attack_damage" => "Attack Damage", + "attribute.name.attack_speed" => "Attack Speed", + "attribute.name.armor" => "Armor", + _ => return None, + } + .to_owned(), + ) + }; + let green = rgba(0, 170, 0, 255); + let gray = rgba(170, 170, 170, 255); + let blue = rgba(85, 85, 255, 255); + let red = rgba(255, 85, 85, 255); + assert_eq!( + attribute_lines(&modifiers, Some([1.0, 4.0]), &lang), + [ + (String::new(), u32::MAX), + ("When in Main Hand:".into(), gray), + (" 7 Attack Damage".into(), green), + (" 1.6 Attack Speed".into(), green), + (String::new(), u32::MAX), + ("When on Head:".into(), gray), + ("+3 Armor".into(), blue), + ] + ); + let recipe = attribute_lines(&modifiers, None, &lang); + assert_eq!(recipe[2], ("+6 Attack Damage".into(), blue)); + assert_eq!(recipe[3], ("-2.4 Attack Speed".into(), red)); + let custom_base = attribute_lines(&modifiers, Some([2.0, 6.0]), &lang); + assert_eq!(custom_base[2].0, " 8 Attack Damage"); + assert_eq!(custom_base[3].0, " 3.6 Attack Speed"); + assert_eq!( + modifier_line(&lang, "attack_damage", 0.0, 0, true).as_deref(), + Some("0 Attack Damage") + ); + } + #[test] fn modifier_lines_follow_the_sign_and_operation() { let lang = |k: &str| { @@ -349,13 +443,13 @@ mod tests { ) }; assert_eq!( - modifier_line(&lang, "movement_speed", 0.2, 2).as_deref(), + modifier_line(&lang, "movement_speed", 0.2, 2, false).as_deref(), Some("+20% Speed") ); assert_eq!( - modifier_line(&lang, "movement_speed", -0.6, 2).as_deref(), + modifier_line(&lang, "movement_speed", -0.6, 2, false).as_deref(), Some("-60% Speed") ); - assert_eq!(modifier_line(&lang, "movement_speed", 0.0, 2), None); + assert_eq!(modifier_line(&lang, "movement_speed", 0.0, 2, false), None); } } From 3db9a250bec7465defe041ef391c651df7244db9 Mon Sep 17 00:00:00 2001 From: Cosmic <84875247+Online5277@users.noreply.github.com> Date: Fri, 16 Oct 2026 14:45:14 -0400 Subject: [PATCH 2/3] Keep equipment attribute tooltip translations at runtime --- crates/horizon-client/src/enchant.rs | 2 + crates/horizon-client/src/item_tooltip.rs | 81 ++++++++++++++++++----- 2 files changed, 67 insertions(+), 16 deletions(-) diff --git a/crates/horizon-client/src/enchant.rs b/crates/horizon-client/src/enchant.rs index c62a67a07..86bdbe562 100644 --- a/crates/horizon-client/src/enchant.rs +++ b/crates/horizon-client/src/enchant.rs @@ -185,6 +185,8 @@ impl Enchantments { .into_iter() .filter(|(k, _)| { k.starts_with("enchantment.") + || k.starts_with("attribute.") + || k.starts_with("item.modifiers.") || k.starts_with("effect.") || k.starts_with("item.minecraft.potion") || k.starts_with("item.minecraft.splash_potion") diff --git a/crates/horizon-client/src/item_tooltip.rs b/crates/horizon-client/src/item_tooltip.rs index dc669e5ea..db561d6c4 100644 --- a/crates/horizon-client/src/item_tooltip.rs +++ b/crates/horizon-client/src/item_tooltip.rs @@ -385,22 +385,34 @@ mod tests { slot.to_owned(), ) }); - let lang = |key: &str| { - Some( - match key { - "item.modifiers.mainhand" => "When in Main Hand:", - "item.modifiers.head" => "When on Head:", - "attribute.modifier.equals.0" => "%s %s", - "attribute.modifier.plus.0" => "+%s %s", - "attribute.modifier.take.0" => "-%s %s", - "attribute.name.attack_damage" => "Attack Damage", - "attribute.name.attack_speed" => "Attack Speed", - "attribute.name.armor" => "Armor", - _ => return None, - } - .to_owned(), - ) - }; + let root = std::env::temp_dir().join(format!( + "horizon-tooltip-language-{}-{}", + std::process::id(), + std::time::SystemTime::now() + .duration_since(std::time::UNIX_EPOCH) + .unwrap() + .as_nanos(), + )); + let dir = root.join("assets/minecraft/lang"); + std::fs::create_dir_all(&dir).unwrap(); + std::fs::write( + dir.join("en_us.json"), + serde_json::to_vec(&serde_json::json!({ + "item.modifiers.mainhand": "When in Main Hand:", + "item.modifiers.head": "When on Head:", + "attribute.modifier.equals.0": "%s %s", + "attribute.modifier.plus.0": "+%s %s", + "attribute.modifier.take.0": "-%s %s", + "attribute.name.attack_damage": "Attack Damage", + "attribute.name.attack_speed": "Attack Speed", + "attribute.name.armor": "Armor", + })) + .unwrap(), + ) + .unwrap(); + let enchantments = crate::enchant::Enchantments::load(&root); + std::fs::remove_dir_all(&root).unwrap(); + let lang = |key: &str| enchantments.translate(key).map(str::to_owned); let green = rgba(0, 170, 0, 255); let gray = rgba(170, 170, 170, 255); let blue = rgba(85, 85, 255, 255); @@ -429,6 +441,43 @@ mod tests { ); } + #[test] + #[ignore = "requires prepared items/language in HORIZON_TEST_RESOURCES"] + fn equipment_attributes_with_prepared_items_and_language() { + let root = std::path::PathBuf::from( + std::env::var_os("HORIZON_TEST_RESOURCES").expect("HORIZON_TEST_RESOURCES"), + ); + let items = crate::items::Items::catalog(&root).unwrap(); + let enchantments = crate::enchant::Enchantments::load(&root); + let translate = |key: &str| enchantments.translate(key).map(str::to_owned); + for (item, expected) in [ + ( + "minecraft:diamond_sword", + [ + "", + "When in Main Hand:", + " 7 Attack Damage", + " 1.6 Attack Speed", + ], + ), + ( + "minecraft:diamond_helmet", + ["", "When on Head:", "+3 Armor", "+2 Armor Toughness"], + ), + ] { + let info = items.get(item).unwrap(); + let lines = attribute_lines(&info.modifiers, Some([1.0, 4.0]), &translate); + assert_eq!( + lines + .iter() + .map(|(text, _)| text.as_str()) + .collect::>(), + expected, + "{item}" + ); + } + } + #[test] fn modifier_lines_follow_the_sign_and_operation() { let lang = |k: &str| { From e5fcdaaec658693744e5ca82e5133529e58f9ae9 Mon Sep 17 00:00:00 2001 From: Cosmic <84875247+Online5277@users.noreply.github.com> Date: Fri, 16 Oct 2026 18:26:12 -0400 Subject: [PATCH 3/3] Show full equipment tooltips in Creative item tabs --- crates/horizon-client/src/game.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index 7072abeb5..c65c00d25 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -7999,7 +7999,7 @@ impl Game<'_> { self.creative_screen.search_focused.elapsed().as_millis(), ); } - let mut hovered: Option = None; + let mut hovered: Option = None; if tab.inventory { self.draw_player_preview( batch, @@ -8049,7 +8049,7 @@ impl Game<'_> { && self.cursor.1 < y + 16.0 { batch.fill(&self.res.atlas, x, y, 16.0, 16.0, rgba(255, 255, 255, 128)); - hovered = Some(stack.item.to_string()); + hovered = Some(stack.clone()); } } } @@ -8064,7 +8064,7 @@ impl Game<'_> { && self.cursor.1 >= y && self.cursor.1 < y + 16.0 { - hovered = Some(stack.item.to_string()); + hovered = Some(stack); } } let scrollable = self.creative_screen.rows(&self.res.names) > 5; @@ -8100,8 +8100,8 @@ impl Game<'_> { } else if self.carried.is_none() && let Some(item) = hovered { - let name = self.res.names.item(&item); - self.tooltip(batch, &name, self.cursor.0, self.cursor.1); + let lines = self.stack_tooltip(&item); + self.draw_tooltip_lines(batch, &lines, self.cursor.0, self.cursor.1); } self.draw_inventory_effects(batch, (ox, oy), Creative::WIDTH as i32); }