From 4507ded0e480f1de9d6bbe8f7b2104e0c17cf06b Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sat, 24 Oct 2026 11:13:27 +0200 Subject: [PATCH] Read enchantment ids without a namespace as minecraft ones `/give @s wooden_sword[enchantments={knockback:2}]` (or an item saved that way) kept the key `knockback`, which no enchantment lookup matched: the sword showed no enchantment and knocked back like a plain one. Vanilla reads the keys as Identifiers, so `knockback` is `minecraft:knockback`. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/item_data.rs | 38 ++++++++++++++++---------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/crates/horizon-client/src/item_data.rs b/crates/horizon-client/src/item_data.rs index 1376dde98..c07e2f352 100644 --- a/crates/horizon-client/src/item_data.rs +++ b/crates/horizon-client/src/item_data.rs @@ -271,23 +271,15 @@ fn read_levels(t: Option<&Tag>) -> Levels { return Vec::new(); }; // Pre-1.21.5 worlds wrap the map in {levels: {...}}. - if let Some(Tag::Compound(inner)) = map.get(&JavaString::from("levels")) { - return inner - .iter() - .filter_map(|(k, v)| { - Some(( - Arc::from(k.to_string_lossy().as_str()), - int(v)?.clamp(1, 255) as u32, - )) - }) - .collect(); - } + let map = match map.get(&JavaString::from("levels")) { + Some(Tag::Compound(inner)) => inner, + _ => map, + }; + // The keys are enchantment Identifiers: `knockback` is `minecraft:knockback`. map.iter() .filter_map(|(k, v)| { - Some(( - Arc::from(k.to_string_lossy().as_str()), - int(v)?.clamp(1, 255) as u32, - )) + let id = horizon_world::datafix::dynamic::namespaced(&k.to_string_lossy()); + Some((Arc::from(id), int(v)?.clamp(1, 255) as u32)) }) .collect() } @@ -863,6 +855,22 @@ mod tests { assert_eq!(back.custom_name(), Some("Blade")); } + #[test] + fn enchantment_ids_without_a_namespace_are_minecraft_ones() { + let levels = Tag::compound([ + ("knockback", Tag::Int(2)), + ("minecraft:sharpness", Tag::Int(1)), + ]); + let components = Tag::compound([("minecraft:enchantments", levels)]); + let (_, extra) = decode_components(Some(&components)); + let stack = ItemStack { + extra, + ..ItemStack::new("minecraft:wooden_sword", 1) + }; + assert_eq!(stack.enchantment_level("minecraft:knockback"), 2); + assert_eq!(stack.enchantment_level("minecraft:sharpness"), 1); + } + #[test] fn custom_name_reads_the_extra_spans() { let name = Tag::compound([