Merge pull request #1251 from rdbtCVS/t3/fix-firework-tooltip-display

🤖 Agent: merged after verify passed and the wave 2 integration run on the desktop (main + 16 contributor PRs, tree 71afc562: workspace tests 1887/0, launcher 113, naga translations 0 failures, parity --changed 304/0).
This commit is contained in:
Ludovic Marie
2026-10-22 22:01:25 +02:00
committed by GitHub
4 changed files with 67 additions and 4 deletions
@@ -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<dyn Error>> {
@@ -12,8 +12,9 @@ fn main() -> Result<(), Box<dyn Error>> {
.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")?;
+2
View File
@@ -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.")
+59
View File
@@ -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");
+2 -1
View File
@@ -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)