diff --git a/crates/horizon-client/examples/firework_tooltip_fixture.rs b/crates/horizon-client/examples/firework_tooltip_fixture.rs index 196fa9955..7f10278b7 100644 --- a/crates/horizon-client/examples/firework_tooltip_fixture.rs +++ b/crates/horizon-client/examples/firework_tooltip_fixture.rs @@ -1,7 +1,7 @@ //! Firework tooltip companion for tools/test_firework_tooltip_parity.py: the //! lines `item_tooltip::firework_lines` gives each stack (SNBT, one per line; //! the `#resources` line names the prepared resources for en_us). -use horizon_client::{item_data::parse_stack, item_tooltip::firework_lines, lang::Language}; +use horizon_client::{enchant::Enchantments, item_data::parse_stack, item_tooltip::firework_lines}; use std::{error::Error, fmt::Write, path::PathBuf}; fn main() -> Result<(), Box> { @@ -12,8 +12,9 @@ fn main() -> Result<(), Box> { .find_map(|l| l.strip_prefix("#resources ")) .map(PathBuf::from) .ok_or("no #resources line")?; - let language = Language::load(&[&root], "en_us"); - let translate = |key: &str| language.get(key).map(str::to_owned); + // Use the inventory's filtered translations so missing tooltip keys are caught. + let enchantments = Enchantments::load(&root); + let translate = |key: &str| enchantments.translate(key).map(str::to_owned); let mut output = String::new(); for line in input.lines().filter(|l| !l.starts_with('#')) { let stack = parse_stack(line)?.ok_or("empty stack")?; diff --git a/crates/horizon-client/src/enchant.rs b/crates/horizon-client/src/enchant.rs index 039ea658f..ca2ea6f5c 100644 --- a/crates/horizon-client/src/enchant.rs +++ b/crates/horizon-client/src/enchant.rs @@ -193,6 +193,8 @@ impl Enchantments { || k.starts_with("item.minecraft.splash_potion") || k.starts_with("item.minecraft.lingering_potion") || k.starts_with("item.minecraft.tipped_arrow") + || k.starts_with("item.minecraft.firework_rocket.") + || k.starts_with("item.minecraft.firework_star.") || k.starts_with("trim_") || k.starts_with("potion.") || k.starts_with("container.") diff --git a/crates/horizon-client/src/item_tooltip.rs b/crates/horizon-client/src/item_tooltip.rs index bf398edfc..ca6ff481b 100644 --- a/crates/horizon-client/src/item_tooltip.rs +++ b/crates/horizon-client/src/item_tooltip.rs @@ -609,6 +609,65 @@ mod tests { assert!(container_lines(&ItemStack::new("minecraft:chest", 1), &name, &lang).is_empty()); } + #[test] + fn fireworks_use_loaded_tooltip_translations() { + let root = std::env::temp_dir().join(format!( + "horizon-firework-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.minecraft.firework_rocket.flight_duration": "Flight Duration: %s", + "item.minecraft.firework_rocket.multiple_stars": "%s x %s", + "item.minecraft.firework_star.shape.small_ball": "Small Ball", + "item.minecraft.firework_star.red": "Red", + "item.minecraft.firework_star.custom_color": "Custom", + "item.minecraft.firework_star.fade_to": "Fade to", + "item.minecraft.firework_star.trail": "Trail", + "item.minecraft.firework_star.flicker": "Twinkle", + })) + .unwrap(), + ) + .unwrap(); + let enchantments = crate::enchant::Enchantments::load(&root); + std::fs::remove_dir_all(&root).unwrap(); + let translate = |key: &str| enchantments.translate(key).map(str::to_owned); + let mut rocket = ItemStack::new("minecraft:firework_rocket", 1); + assert_eq!(firework_lines(&rocket, &translate), ["Flight Duration: 1"]); + let explosion = crate::particles::FireworkExplosion { + colors: vec![0xB3312C], + fade: vec![0x123456], + trail: true, + twinkle: true, + ..Default::default() + }; + rocket.data_mut().fireworks = Some((3, vec![explosion.clone(), explosion.clone()])); + assert_eq!( + firework_lines(&rocket, &translate), + [ + "Flight Duration: 3", + "2 x Small Ball", + " Red", + " Fade to Custom", + " Trail", + " Twinkle", + ] + ); + let mut star = ItemStack::new("minecraft:firework_star", 1); + star.data_mut().firework_explosion = Some(explosion); + assert_eq!( + firework_lines(&star, &translate), + ["Small Ball", "Red", "Fade to Custom", "Trail", "Twinkle"] + ); + } + #[test] fn amounts_use_two_decimals_at_most() { assert_eq!(format_amount(8.0), "8"); diff --git a/tools/test_firework_tooltip_parity.py b/tools/test_firework_tooltip_parity.py index e6cea9925..b3114c01a 100644 --- a/tools/test_firework_tooltip_parity.py +++ b/tools/test_firework_tooltip_parity.py @@ -67,6 +67,7 @@ if __name__ == '__main__': 'firework-tooltip-parity', 'VanillaFireworkTooltipOracle', 'firework_tooltip_fixture', cases, 'Firework rocket and star tooltip lines: flight duration, explosions (counted runs), colours, fade, trail, ' 'twinkle, defaults and tooltip_display', - sources=[lab.ROOT / 'crates/horizon-client/src/item_tooltip.rs', lab.ROOT / 'crates/horizon-client/src/item_data.rs', + sources=[lab.ROOT / 'crates/horizon-client/src/enchant.rs', + lab.ROOT / 'crates/horizon-client/src/item_tooltip.rs', lab.ROOT / 'crates/horizon-client/src/item_data.rs', lab.ROOT / 'crates/horizon-client/src/particles.rs'], expected_lines=COUNT)