Skip to content

Minecraft: Java Edition 26.3 rewritten from scratch in Rust, checked against vanilla with 281 differential harnesses. Get it with the Horizon launcher.

The recipe book shows a filter's swapped recipe unswapped

hui6219424298f5
diff --git a/crates/horizon-client/src/lan/advancements.rs b/crates/horizon-client/src/lan/advancements.rs
index a29f8e55e..952448e81 100644
--- a/crates/horizon-client/src/lan/advancements.rs
+++ b/crates/horizon-client/src/lan/advancements.rs
@@ -826,6 +826,57 @@ mod tests {
let _ = std::fs::remove_dir_all(&root);
}
+ /// A recipe filter's `replace_input` (#5910) reaches the book swapped:
+ /// the book writes from the network copy, so the swap must have run
+ /// there, once, before the ingredient normalization. A world's pack
+ /// carries the filter (the way the game reads them).
+ #[test]
+ fn a_recipe_filters_swapped_input_shows_swapped_in_the_book() {
+ let root = resources(
+ "filter_swap",
+ &[(
+ "copper_ingot_from_smelting_raw_copper",
+ r#"{"type":"minecraft:smelting","cookingtime":200,"experience":0.7,
+ "ingredient":"minecraft:raw_copper",
+ "result":{"id":"minecraft:copper_ingot"}}"#,
+ )],
+ );
+ let packs = vec![(
+ "recipe_filter/minecraft:swap".to_owned(),
+ vec![
+ br#"{"filters":[{"id":"minecraft:copper_ingot_from_smelting_raw_copper",
+ "replace_input":{"from":"minecraft:raw_copper","to":"minecraft:redstone"}}]}"#
+ .to_vec(),
+ ],
+ )];
+ let overlay = horizon_world::loot::PackOverlay { files: &packs };
+ let sync = SyncData::load(&root, &overlay).unwrap();
+ let entries = sync.advancements.book_entries(
+ "minecraft:copper_ingot_from_smelting_raw_copper",
+ &sync,
+ NOTIFY_AND_HIGHLIGHT,
+ );
+ assert_eq!(entries.len(), 1, "the recipe has one display");
+ let mut r = Reader::new(&entries[0]);
+ let e = RecipeBookEntry::read(&mut r).unwrap();
+ assert_eq!(r.remaining(), 0, "the entry ends with its flags");
+ let item = |n: &str| sync.id("minecraft:item", n).unwrap();
+ assert_eq!(
+ e.requirements,
+ Some(vec![HolderSet::Items(vec![item("minecraft:redstone")])]),
+ "the filter's swapped input, not the file's"
+ );
+ let RecipeDisplay::Furnace { ingredient, .. } = e.display else {
+ panic!("a smelting recipe shows a furnace display");
+ };
+ assert_eq!(
+ ingredient,
+ SlotDisplay::Tag(HolderSet::Items(vec![item("minecraft:redstone")])),
+ "the display shows the swapped input too"
+ );
+ let _ = std::fs::remove_dir_all(&root);
+ }
+
#[test]
fn blasting_reaches_the_blast_furnace_book() {
let root = resources(
diff --git a/crates/horizon-client/src/lan/data.rs b/crates/horizon-client/src/lan/data.rs
index 5a9c7095d..4e41acdee 100644
--- a/crates/horizon-client/src/lan/data.rs
+++ b/crates/horizon-client/src/lan/data.rs
@@ -271,8 +271,7 @@ impl SyncData {
super::advancements::ServerAdvancements::load(resources, overlay, recipes, groups)
},
};
- sync.recipes =
- super::recipes::update_recipes(&sync.advancements.recipes, resources, &sync, overlay);
+ sync.recipes = super::recipes::update_recipes(&sync.advancements.recipes, &sync);
Ok(sync)
}
diff --git a/crates/horizon-client/src/lan/recipes.rs b/crates/horizon-client/src/lan/recipes.rs
index 721c504e0..11796517b 100644
--- a/crates/horizon-client/src/lan/recipes.rs
+++ b/crates/horizon-client/src/lan/recipes.rs
@@ -96,6 +96,12 @@ pub(super) fn network_recipes(
let mut all = BTreeMap::new();
recipes(&resources.join("data/minecraft/recipe"), "", &mut all);
overlay_recipes(overlay, &mut all);
+ // The data's recipe filters, as the server's own tables apply them
+ // (#5910), once, before the ingredient normalization, so a swapped
+ // name resolves and every copy — the book's displays, the property
+ // sets — agrees on the swapped recipe.
+ let filters = horizon_items::recipe_filters::RecipeFilters::load(resources, overlay);
+ all.retain(|id, r| filters.apply(id, r));
match horizon_client::items::Items::catalog(resources, overlay) {
Ok(items) => all.retain(|_, r| normalize_ingredients(r, &items)),
Err(e) => log::warn!("recipes: NeoForge's ingredient shapes stay unresolved: {e}"),
@@ -190,26 +196,14 @@ fn normalize_ingredients(r: &mut Value, items: &horizon_client::items::Items) ->
}
/// The packet's payload for the network copy's recipes (`network_recipes`).
-pub fn update_recipes(
- all: &BTreeMap<String, Box<str>>,
- resources: &Path,
- sync: &SyncData,
- overlay: &horizon_world::loot::PackOverlay,
-) -> Vec<u8> {
- // The data's recipe filters, as the server's own tables apply them. A
- // filter can also swap a recipe's inputs and outputs, so it runs on
- // this packet's own parsed values, the book's copy keeping its files
- // as loaded. Parsing every recipe takes about a millisecond.
- let filters = horizon_items::recipe_filters::RecipeFilters::load(resources, overlay);
- let mut chosen: Vec<Value> = Vec::new();
- for (id, text) in all {
- let Ok(mut own) = serde_json::from_str::<Value>(text) else {
- continue;
- };
- if filters.apply(id, &mut own) {
- chosen.push(own);
- }
- }
+pub fn update_recipes(all: &BTreeMap<String, Box<str>>, sync: &SyncData) -> Vec<u8> {
+ // The copy is already filtered and swapped (`network_recipes`); the
+ // filters never run twice, so one swap cannot feed a later one again.
+ // Parsing every recipe takes about a millisecond.
+ let chosen: Vec<Value> = all
+ .values()
+ .filter_map(|text| serde_json::from_str::<Value>(text).ok())
+ .collect();
let tags: BTreeMap<&str, &[i32]> = sync
.tags
.registries