diff --git a/crates/horizon-items/src/bundle.rs b/crates/horizon-items/src/bundle.rs index 42473729f..efce3c822 100644 --- a/crates/horizon-items/src/bundle.rs +++ b/crates/horizon-items/src/bundle.rs @@ -322,14 +322,7 @@ mod tooltip_tests { /// The prepared resources, when they are on this machine: the tooltip /// asks the item registry whether a stack is a bundle. fn items() -> Option { - let root = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")) - .join("../../.local/horizon-client/26.3"); - if !root.join("items.json").exists() { - return None; - } - let assets = crate::assets::Assets::load(&root).ok()?; - let facts = crate::blocks::BlockFacts::load(&root, assets.registry).ok()?; - Items::load(&root, assets.registry, &facts).ok() + crate::items::prepared_items() } fn bundle_with(counts: &[(&str, u32)]) -> ItemStack { diff --git a/crates/horizon-items/src/items.rs b/crates/horizon-items/src/items.rs index ecf3b9d63..ef8b9c810 100644 --- a/crates/horizon-items/src/items.rs +++ b/crates/horizon-items/src/items.rs @@ -1619,6 +1619,22 @@ mod bucket_use_tests { } } +/// The items of the prepared resources, when they are on this machine, for +/// tests: the block registry and facts as the client's `Assets::load` reads them. +#[cfg(test)] +pub(crate) fn prepared_items() -> Option { + let root = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")) + .join("../../.local/horizon-client/26.3"); + if !root.join("items.json").exists() { + return None; + } + let (registry, _) = + BlockRegistry::from_facts_json_with_flags(fs::File::open(root.join("facts.json")).ok()?) + .ok()?; + let facts = BlockFacts::load(&root, ®istry).ok()?; + Items::load(&root, ®istry, &facts).ok() +} + #[cfg(test)] mod tests { use super::*; @@ -1641,22 +1657,6 @@ mod tests { } } - /// The items of the prepared resources, when they are on this machine - /// (the block registry and facts as the client's `Assets::load` reads them). - fn prepared_items() -> Option { - let root = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")) - .join("../../.local/horizon-client/26.3"); - if !root.join("items.json").exists() { - return None; - } - let (registry, _) = BlockRegistry::from_facts_json_with_flags( - std::fs::File::open(root.join("facts.json")).ok()?, - ) - .ok()?; - let facts = BlockFacts::load(&root, ®istry).ok()?; - Items::load(&root, ®istry, &facts).ok() - } - #[test] fn fortune_silk_touch_and_looting() { let items = Items::for_tests(HashMap::new()); @@ -1746,7 +1746,7 @@ mod tests { /// `EnchantRandomlyFunction`) put their enchantments on the stack. #[test] fn loot_enchant_functions_enchant_the_rolled_item() { - let Some(items) = prepared_items() else { + let Some(items) = super::prepared_items() else { return; }; let props = BTreeMap::new(); @@ -1807,7 +1807,7 @@ mod tests { /// Mending book, then `set_count` uniform 1..64, is 46. #[test] fn a_single_level_enchantment_draws_no_level() { - let Some(items) = prepared_items() else { + let Some(items) = super::prepared_items() else { return; }; let props = BTreeMap::new();