Merge pull request #1546 from ludovic111/fix/kb1-enchantment-ids
This commit is contained in:
@@ -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([
|
||||
|
||||
Reference in New Issue
Block a user