Minecraft: Java Edition 26.3 rewritten from scratch in Rust, checked against vanilla with 281 differential harnesses. Get it with the Horizon launcher.
Rust differential-testinggame-enginegamedevlinuxminecraftminecraft-javareimplementationrustvoxelvulkanwgpu
A refused code declaration leaves out only the content mod whose file item needed it
Federico Taglianif79819342817
diff --git a/crates/horizon-client/src/game/mods.rs b/crates/horizon-client/src/game/mods.rsindex 65d946881..a00bde7fd 100644--- a/crates/horizon-client/src/game/mods.rs+++ b/crates/horizon-client/src/game/mods.rs@@ -137,6 +137,11 @@ pub(super) fn content_root(for e in mod_content::accept_declared(&mut mods, blocks, items, known) {log::warn!("Horizon: {e}");}+ // A file item's remainder named a code-declared item that was refused: that mod+ // alone is left out, not every content mod through the overlay's check.+ for e in mod_content::drop_dangling_remainders(&mut mods) {+ log::warn!("Horizon: {e}");+ }}}match mod_content::resource_root(root, &mods, &here.join(".horizon-cache")) {diff --git a/crates/horizon-client/src/mod_content.rs b/crates/horizon-client/src/mod_content.rsindex 86aa558c5..17242b45e 100644--- a/crates/horizon-client/src/mod_content.rs+++ b/crates/horizon-client/src/mod_content.rs@@ -34,6 +34,31 @@ pub struct ContentMod {pub content: Content,}+/// Leaves out a mod with an item whose `crafting_remainder` names an item the mod does not have:+/// a file item that named a code-declared one the declaration check then refused. Left in, the+/// overlay would fail on it and no content mod at all would load. Returns what was left out.+pub fn drop_dangling_remainders(mods: &mut Vec<ContentMod>) -> Vec<String> {+ let mut dropped = Vec::new();+ mods.retain(|m| {+ let ids: BTreeSet<&str> = m.content.items.iter().map(|i| i.id.as_str()).collect();+ let dangling = m.content.items.iter().find(|i| {+ i.crafting_remainder+ .as_deref()+ .is_some_and(|r| !r.starts_with("minecraft:") && !ids.contains(r))+ });+ if let Some(item) = dangling {+ dropped.push(format!(+ "mod {} content not loaded: {}: crafting_remainder {:?} is not one of its items",+ m.id,+ item.id,+ item.crafting_remainder.as_deref().unwrap_or_default()+ ));+ }+ dangling.is_none()+ });+ dropped+}+/// The mods' mob effects in registry order: by id, as items are. Their/// network ids follow vanilla's in this order.pub fn mob_effects(mods: &[ContentMod]) -> Vec<&MobEffect> {diff --git a/crates/horizon-client/src/mod_content_tests.rs b/crates/horizon-client/src/mod_content_tests.rsindex 42fe968aa..208042f5a 100644--- a/crates/horizon-client/src/mod_content_tests.rs+++ b/crates/horizon-client/src/mod_content_tests.rs@@ -3541,3 +3541,41 @@ fn blocks_and_items_declared_in_code_get_ids() {assert_ne!(fs::read(root.join(STAMP)).unwrap(), stamp);let _ = fs::remove_dir_all(&scratch);}++#[test]+fn a_file_item_whose_remainder_was_refused_takes_only_its_mod_out() {+ use horizon_mods::content::Item;+ let item = |id: &str, remainder: Option<&str>| Item {+ id: id.into(),+ template: "minecraft:diamond".into(),+ crafting_remainder: remainder.map(str::to_owned),+ ..Item::default()+ };+ let make = |id: &str, items: Vec<Item>| {+ let mut content = Content::declared(id);+ content.items = items;+ ContentMod {+ id: id.into(),+ content,+ }+ };+ let mut mods = vec![+ make(+ "good",+ vec![+ item("good:tool", Some("good:wrench")),+ item("good:wrench", None),+ ],+ ),+ make("bad", vec![item("bad:tool", Some("bad:wrench"))]),+ make(+ "vanilla",+ vec![item("vanilla:soup", Some("minecraft:bowl"))],+ ),+ ];+ let dropped = drop_dangling_remainders(&mut mods);+ assert_eq!(dropped.len(), 1, "{dropped:?}");+ assert!(dropped[0].contains("bad"), "{dropped:?}");+ let left: Vec<&str> = mods.iter().map(|m| m.id.as_str()).collect();+ assert_eq!(left, ["good", "vanilla"]);+}