From 89d6e1c2a50112cb6d65de4cbfbe8af094ea5952 Mon Sep 17 00:00:00 2001 From: vlesmentie <129341611+vlesmentie@users.noreply.github.com> Date: Sun, 25 Oct 2026 16:34:39 -0300 Subject: [PATCH] Structure chests keep the enchantments their loot rolled The loot rolls carry enchantments and potions (horizon_world::loot runs enchant_with_levels, enchant_randomly and set_potion), but chests filled when a structure is placed, and mineshaft chest minecarts, turned each LootStack into an item with loot_item, which keeps only the item, count, damage and exploration map. End city gear came out bare. Both now use loot_item_with_components, as vaults, trial spawners and decorated pots already do. Fixes #1437. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/structure_blocks.rs | 53 +++++++++++++++---- 1 file changed, 44 insertions(+), 9 deletions(-) diff --git a/crates/horizon-client/src/structure_blocks.rs b/crates/horizon-client/src/structure_blocks.rs index 1e1906f6d..427323c23 100644 --- a/crates/horizon-client/src/structure_blocks.rs +++ b/crates/horizon-client/src/structure_blocks.rs @@ -165,14 +165,10 @@ pub fn block_entities( .iter_mut() .zip(loot.fill(&table, seed, 27, Some(biome))) { - *slot = stack.map(|s| { - let mut item = loot_item(&s); - // An ominous bottle's level (the default, 0, is no component). - if let Some(level) = s.ominous_amplifier.filter(|l| *l > 0) { - item.data_mut().ominous_amplifier = Some(level.clamp(0, 4) as u8); - } - item - }); + // With what the rolls put on them: enchantments + // (enchant_with_levels in End city chests), potions and an + // ominous bottle's level. + *slot = stack.map(|s| loot_item_with_components(&s)); } } out.push(((x, y, z), entity)); @@ -211,7 +207,7 @@ pub fn unpack_entity_loot( let slots: Vec> = loot .fill(&table, seed, 27, Some(biome)) .into_iter() - .map(|s| s.map(|s| loot_item(&s))) + .map(|s| s.map(|s| loot_item_with_components(&s))) .collect(); nbt.remove(&JavaString::from("LootTable")); nbt.remove(&JavaString::from("LootTableSeed")); @@ -224,6 +220,45 @@ mod tests { use super::*; use horizon_world::loot::{ExplorationMap, LootStack}; + #[test] + fn placed_chest_loot_keeps_its_enchantments_and_potions() { + let stack = + |item: &str, enchantments: Vec<(String, i32)>, potion: Option<&str>| LootStack { + item: item.into(), + count: 1, + damage: 0, + enchantments, + potion: potion.map(str::to_owned), + map: false, + exploration: None, + ominous_amplifier: None, + }; + // An End city chest's enchant_with_levels roll. + let boots = loot_item_with_components(&stack( + "minecraft:diamond_boots", + vec![ + ("minecraft:protection".into(), 3), + ("minecraft:unbreaking".into(), 2), + ], + None, + )); + assert_eq!(boots.enchantments().len(), 2); + // A book's go into stored_enchantments. + let book = loot_item_with_components(&stack( + "minecraft:enchanted_book", + vec![("minecraft:mending".into(), 1)], + None, + )); + assert!(book.enchantments().is_empty()); + assert_eq!(book.stored_enchantments().len(), 1); + let arrow = loot_item_with_components(&stack( + "minecraft:tipped_arrow", + Vec::new(), + Some("minecraft:slowness"), + )); + assert_eq!(arrow.potion(), Some("minecraft:slowness")); + } + #[test] fn exploration_maps_wait_in_custom_data_until_searched() { let mut stack = LootStack {