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.

Recipe book sync sends empty ingredients for NeoForge's object shapes

hui4f48e48a43b4
diff --git a/crates/horizon-client/src/lan/advancements.rs b/crates/horizon-client/src/lan/advancements.rs
index d0622fbfa..a29f8e55e 100644
--- a/crates/horizon-client/src/lan/advancements.rs
+++ b/crates/horizon-client/src/lan/advancements.rs
@@ -19,10 +19,12 @@ pub struct ServerAdvancements {
tree: std::sync::Arc<Tree>,
kids: Vec<Vec<usize>>,
layout: Vec<Option<(i32, f32)>>,
- /// Recipe files by id, as compact JSON text: a book entry parses its
- /// recipe when a player gets it (a few µs), and the ~1,400 parsed files
- /// would keep about 5 MB alive for the server's whole run.
- recipes: BTreeMap<String, Box<str>>,
+ /// Recipe files by id, as compact JSON text with their ingredient
+ /// objects already resolved to flat item lists (`network_recipes`): a
+ /// book entry parses its recipe when a player gets it (a few µs), and
+ /// the ~1,400 parsed files would keep about 5 MB alive for the server's
+ /// whole run.
+ pub(super) recipes: BTreeMap<String, Box<str>>,
displays: RecipeIndex,
/// RecipeManager.unpackRecipeInfo's group numbers.
groups: HashMap<String, i32>,
@@ -36,24 +38,15 @@ pub struct FirstTick {
}
impl ServerAdvancements {
- pub fn load(resources: &Path, overlay: &horizon_world::loot::PackOverlay) -> Self {
+ pub fn load(
+ resources: &Path,
+ overlay: &horizon_world::loot::PackOverlay,
+ recipes: BTreeMap<String, Box<str>>,
+ groups: HashMap<String, i32>,
+ ) -> Self {
let tree = Tree::shared(&resources.join("data"), overlay);
let kids = tree.children();
let layout = tree.layout();
- let mut recipes = BTreeMap::new();
- super::recipes::recipes(&resources.join("data/minecraft/recipe"), "", &mut recipes);
- super::recipes::overlay_recipes(overlay, &mut recipes);
- let mut groups = HashMap::new();
- for r in recipes.values() {
- if let Some(g) = r["group"].as_str().filter(|g| !g.is_empty()) {
- let next = groups.len() as i32;
- groups.entry(g.to_owned()).or_insert(next);
- }
- }
- let recipes = recipes
- .into_iter()
- .map(|(id, r)| (id, r.to_string().into_boxed_str()))
- .collect();
Self {
tree,
kids,
@@ -371,7 +364,7 @@ impl ServerAdvancements {
};
let r = &r;
let kind = r["type"].as_str().unwrap_or("");
- let item = |n: &str| sync.id("minecraft:item", n).unwrap_or(0);
+ let item = |n: &str| sync.id("minecraft:item", n);
let slot = |n: &str| sync.id("minecraft:slot_display", n).unwrap_or(0);
let mut w = Writer::new();
w.varint(ids.start);
@@ -391,16 +384,19 @@ impl ServerAdvancements {
// The result as its ItemStackSlotDisplay, the station as its item.
let result = |w: &mut Writer| {
w.varint(slot("minecraft:item_stack"));
- w.varint(item(
- horizon_world::loot::recipe_result_id(&r["result"]).unwrap_or("minecraft:air"),
- ));
+ w.varint(
+ item(
+ horizon_world::loot::recipe_result_id(&r["result"]).unwrap_or("minecraft:air"),
+ )
+ .unwrap_or(0),
+ );
w.varint(r["result"]["count"].as_i64().unwrap_or(1) as i32);
w.varint(0);
w.varint(0);
};
let station = |w: &mut Writer, name: &str| {
w.varint(slot("minecraft:item"));
- w.varint(item(name));
+ w.varint(item(name).unwrap_or(0));
};
// The display, then the ingredients the craftable filter checks and
// the category of the tab that lists it.
@@ -551,20 +547,25 @@ fn shrink(rows: &[Value]) -> Vec<Vec<char>> {
}
/// ByteBufCodecs.holderSet for an ingredient: a tag by name, or the items.
-fn holder_set(w: &mut Writer, v: &Value, item: &dyn Fn(&str) -> i32) {
+/// An item the registries do not know is left out, not sent as id 0.
+fn holder_set(w: &mut Writer, v: &Value, item: &dyn Fn(&str) -> Option<i32>) {
match v {
Value::String(s) if s.starts_with('#') => {
w.varint(0);
w.string(&s[1..]);
}
- Value::String(s) => {
- w.varint(2);
- w.varint(item(s));
- }
+ Value::String(s) => match item(s) {
+ Some(id) => {
+ w.varint(2);
+ w.varint(id);
+ }
+ None => w.varint(1),
+ },
Value::Array(a) => {
- w.varint(a.len() as i32 + 1);
- for s in a {
- w.varint(item(s.as_str().unwrap_or("")));
+ let ids: Vec<i32> = a.iter().filter_map(|s| item(s.as_str()?)).collect();
+ w.varint(ids.len() as i32 + 1);
+ for id in ids {
+ w.varint(id);
}
}
_ => w.varint(1),
@@ -637,6 +638,7 @@ mod tests {
let dir = root.join("data/minecraft/recipe");
std::fs::create_dir_all(&dir).unwrap();
std::fs::write(root.join("registries.json"), REGISTRIES).unwrap();
+ std::fs::write(root.join("items.json"), "{}").unwrap();
for (id, json) in recipes {
std::fs::write(dir.join(format!("{id}.json")), json).unwrap();
}
@@ -657,6 +659,121 @@ mod tests {
(sync, entry)
}
+ /// A shaped recipe whose key uses one of NeoForge's ingredient shapes
+ /// reaches the client with the shape's items, not an empty list.
+ #[test]
+ fn a_neoforge_ingredient_in_the_key_reaches_the_client_with_items() {
+ let root = resources(
+ "compound_key",
+ &[(
+ "compound_key",
+ r#"{"type":"minecraft:crafting_shaped",
+ "pattern":["X"],
+ "key":{"X":{"type":"neoforge:compound","children":["minecraft:raw_copper","minecraft:redstone"]}},
+ "result":{"id":"minecraft:copper_ingot"}}"#,
+ )],
+ );
+ let (sync, e) = entry(&root, "minecraft:compound_key");
+ let item = |n: &str| sync.id("minecraft:item", n).unwrap();
+ let raw = item("minecraft:raw_copper");
+ let redstone = item("minecraft:redstone");
+ let req = e.requirements.as_ref().unwrap();
+ assert_eq!(req.len(), 1, "one cell: {req:?}");
+ match &req[0] {
+ HolderSet::Items(items) => {
+ assert!(
+ items.contains(&raw) && items.contains(&redstone),
+ "the compound's items: {items:?}"
+ );
+ }
+ other => panic!("not an item list: {other:?}"),
+ }
+ let _ = std::fs::remove_dir_all(&root);
+ }
+
+ /// A recipe whose ingredient kind no loader knows stays out of the book:
+ /// the server does not load it, and an empty ingredient slot in its
+ /// place would mislead the client.
+ #[test]
+ fn a_recipe_with_an_unknown_ingredient_kind_stays_out_of_the_book() {
+ let root = resources(
+ "mymod_kind",
+ &[(
+ "mymod_kind",
+ r#"{"type":"minecraft:crafting_shaped",
+ "pattern":["X"],
+ "key":{"X":{"type":"mymod:x"}},
+ "result":{"id":"minecraft:copper_ingot"}}"#,
+ )],
+ );
+ let sync = SyncData::load(&root, &horizon_world::loot::PackOverlay::NONE).unwrap();
+ assert!(
+ !sync
+ .advancements
+ .recipes
+ .contains_key("minecraft:mymod_kind"),
+ "the network copy drops the recipe"
+ );
+ assert!(
+ sync.advancements
+ .book_entries("minecraft:mymod_kind", &sync, NOTIFY_AND_HIGHLIGHT)
+ .is_empty()
+ );
+ let _ = std::fs::remove_dir_all(&root);
+ }
+
+ /// The property sets and the stonecutter read a NeoForge shape's items
+ /// too, not an empty slot: UpdateRecipes carries them.
+ #[test]
+ fn update_recipes_sends_a_neoforge_shapes_items() {
+ let root = resources(
+ "compound_sets",
+ &[
+ (
+ "compound_smelting",
+ r#"{"type":"minecraft:smelting",
+ "ingredient":{"type":"neoforge:compound","children":["minecraft:raw_copper","minecraft:redstone"]},
+ "result":{"id":"minecraft:copper_ingot"}}"#,
+ ),
+ (
+ "compound_stonecutting",
+ r#"{"type":"minecraft:stonecutting",
+ "ingredient":{"type":"neoforge:compound","children":["minecraft:raw_copper"]},
+ "result":{"id":"minecraft:copper_ingot"}}"#,
+ ),
+ ],
+ );
+ let sync = SyncData::load(&root, &horizon_world::loot::PackOverlay::NONE).unwrap();
+ let item = |n: &str| sync.id("minecraft:item", n).unwrap();
+ let raw = item("minecraft:raw_copper");
+ let redstone = item("minecraft:redstone");
+ let mut r = Reader::new(&sync.recipes);
+ // The property sets, then the stonecutter's recipes.
+ let mut furnace_input = None;
+ for _ in 0..r.varint().unwrap() {
+ let key = r.string(64).unwrap();
+ let ids: Vec<i32> = (0..r.varint().unwrap())
+ .filter_map(|_| r.varint().ok())
+ .collect();
+ if key == "minecraft:furnace_input" {
+ furnace_input = Some(ids);
+ }
+ }
+ let ids = furnace_input.expect("furnace_input set present");
+ assert!(
+ ids.contains(&raw) && ids.contains(&redstone),
+ "the compound's items in furnace_input: {ids:?}"
+ );
+ // The stonecutter's entry: the compound's items, then the result.
+ let stone = r.varint().unwrap();
+ assert_eq!(stone, 1, "one stonecutting recipe");
+ let len = r.varint().unwrap();
+ assert!(len >= 2, "an item list, not empty ({len}) nor a tag");
+ assert_eq!(len - 1, 1, "the compound's one item");
+ assert_eq!(r.varint().unwrap(), raw);
+ let _ = std::fs::remove_dir_all(&root);
+ }
+
#[test]
fn smelting_reaches_the_furnace_book() {
let root = resources(
diff --git a/crates/horizon-client/src/lan/data.rs b/crates/horizon-client/src/lan/data.rs
index fe14bee0a..5a9c7095d 100644
--- a/crates/horizon-client/src/lan/data.rs
+++ b/crates/horizon-client/src/lan/data.rs
@@ -198,6 +198,8 @@ impl SyncData {
advancements: super::advancements::ServerAdvancements::load(
Path::new(""),
&horizon_world::loot::PackOverlay::NONE,
+ BTreeMap::new(),
+ HashMap::new(),
),
content_identity: None,
}
@@ -264,9 +266,13 @@ impl SyncData {
features: vec!["minecraft:vanilla".to_owned()],
commands: super::commands::CommandTree::load(resources),
recipes: Vec::new(),
- advancements: super::advancements::ServerAdvancements::load(resources, overlay),
+ advancements: {
+ let (recipes, groups) = super::recipes::network_recipes(resources, overlay);
+ super::advancements::ServerAdvancements::load(resources, overlay, recipes, groups)
+ },
};
- sync.recipes = super::recipes::update_recipes(resources, &sync, overlay);
+ sync.recipes =
+ super::recipes::update_recipes(&sync.advancements.recipes, resources, &sync, overlay);
Ok(sync)
}
diff --git a/crates/horizon-client/src/lan/recipes.rs b/crates/horizon-client/src/lan/recipes.rs
index 134d71e7f..721c504e0 100644
--- a/crates/horizon-client/src/lan/recipes.rs
+++ b/crates/horizon-client/src/lan/recipes.rs
@@ -6,7 +6,7 @@ use super::data::SyncData;
use horizon_protocol::buf::Writer;
use serde_json::Value;
use std::{
- collections::{BTreeMap, BTreeSet},
+ collections::{BTreeMap, BTreeSet, HashMap},
path::Path,
sync::{Arc, Mutex},
};
@@ -81,18 +81,135 @@ pub(super) fn overlay_recipes(
}
}
-/// The packet's payload for the vanilla data pack in `resources`.
-pub fn update_recipes(
+/// The network copy's recipes: every recipe file and overlay recipe, each
+/// ingredient object — NeoForge's shapes, a brewing slot's item predicate —
+/// replaced by the flat item list the crafting copy resolves it to. The
+/// crafting copy resolves these shapes where it loads them; this copy reads
+/// the files again, and `holder_set` writes any object it meets as an empty
+/// list. A recipe that keeps an object the loader cannot parse (a mod's own
+/// ingredient kind) is left out: the server does not load it, and an empty
+/// ingredient in its place misleads the client.
+pub(super) fn network_recipes(
resources: &Path,
- sync: &SyncData,
overlay: &horizon_world::loot::PackOverlay,
-) -> Vec<u8> {
+) -> (BTreeMap<String, Box<str>>, HashMap<String, i32>) {
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.
+ 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}"),
+ }
+ // RecipeManager.unpackRecipeInfo's group numbers, while the files are
+ // still parsed.
+ let mut groups = HashMap::new();
+ for r in all.values() {
+ if let Some(g) = r["group"].as_str().filter(|g| !g.is_empty()) {
+ let next = groups.len() as i32;
+ groups.entry(g.to_owned()).or_insert(next);
+ }
+ }
+ // Each file as its compact JSON text: a book entry parses the one it
+ // needs, and the parsed files would keep about 5 MB alive for the
+ // server's whole run.
+ let all = all
+ .into_iter()
+ .map(|(id, r)| (id, r.to_string().into_boxed_str()))
+ .collect();
+ (all, groups)
+}
+
+/// An ingredient object's flat item list: the shape NeoForge's standard
+/// kinds resolve to, or a brewing predicate's `item`. `None`: the object is
+/// a kind the loader does not know, a mod's own.
+fn flat(ing: &Value, items: &horizon_client::items::Items) -> Option<Value> {
+ if !ing.is_object() {
+ return None;
+ }
+ let parsed = horizon_client::crafting::Ingredient::parse(ing, items).or_else(|| {
+ // A brewing slot's item predicate: its `ingredient`, as the
+ // property sets have always read it.
+ ing.get("item")
+ .and_then(|v| horizon_client::crafting::Ingredient::parse(v, items))
+ })?;
+ Some(Value::Array(
+ parsed.1.iter().map(|i| Value::String(i.clone())).collect(),
+ ))
+}
+
+/// Replace each of a recipe's ingredient objects with its flat item list,
+/// so `holder_set` writes the items instead of an empty list. `false`: the
+/// recipe keeps an object the loader cannot parse.
+fn normalize_ingredients(r: &mut Value, items: &horizon_client::items::Items) -> bool {
+ let known = r["type"]
+ .as_str()
+ .is_some_and(|t| t.starts_with("minecraft:"));
+ if !known {
+ return true;
+ }
+ let mut parsed = true;
+ // The shaped recipe's key: a map of symbols to ingredients.
+ if let Some(map) = r.get_mut("key").and_then(|k| k.as_object_mut()) {
+ for ing in map.values_mut() {
+ if let Some(replacement) = flat(ing, items) {
+ *ing = replacement;
+ } else if ing.is_object() {
+ parsed = false;
+ }
+ }
+ }
+ // The list and single-ingredient keys, the smithing trio, the brewing
+ // pair.
+ for key in [
+ "ingredients",
+ "ingredient",
+ "base",
+ "addition",
+ "template",
+ "input",
+ "reagent",
+ ] {
+ let Some(ing) = r.get_mut(key) else { continue };
+ if let Some(replacement) = flat(ing, items) {
+ *ing = replacement;
+ continue;
+ }
+ if let Value::Array(a) = ing {
+ for entry in a.iter_mut() {
+ if let Some(replacement) = flat(entry, items) {
+ *entry = replacement;
+ } else if entry.is_object() {
+ parsed = false;
+ }
+ }
+ } else if ing.is_object() {
+ parsed = false;
+ }
+ }
+ parsed
+}
+
+/// 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);
- all.retain(|id, v| filters.apply(id, v));
+ 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);
+ }
+ }
let tags: BTreeMap<&str, &[i32]> = sync
.tags
.registries
@@ -101,21 +218,22 @@ pub fn update_recipes(
.flat_map(|r| r.tags.iter())
.map(|t| (t.name.trim_start_matches("minecraft:"), t.ids.as_slice()))
.collect();
- let item = |name: &str| sync.id("minecraft:item", name).unwrap_or(0);
+ // An item the registries do not know is left out, not sent as id 0.
+ let item = |name: &str| sync.id("minecraft:item", name);
let items = |i: &Ingredient| -> Vec<i32> {
match i {
Ingredient::Tag(t) => tags
.get(t.trim_start_matches("minecraft:"))
.map(|ids| ids.to_vec())
.unwrap_or_default(),
- Ingredient::Items(list) => list.iter().map(|n| item(n)).collect(),
+ Ingredient::Items(list) => list.iter().filter_map(|n| item(n)).collect(),
}
};
let mut w = Writer::new();
w.varint(PROPERTY_SETS.len() as i32);
for (key, kind, fields) in PROPERTY_SETS {
let mut set = BTreeSet::new();
- for recipe in all.values() {
+ for recipe in &chosen {
let t = recipe["type"].as_str().unwrap_or("");
let matches = if *kind == "smithing" {
t.starts_with("minecraft:smithing_")
@@ -138,8 +256,8 @@ pub fn update_recipes(
}
// SelectableRecipe.SingleInputSet: each stonecutting recipe's input and
// its result as an ItemStackSlotDisplay.
- let stonecutting: Vec<&Value> = all
- .values()
+ let stonecutting: Vec<&Value> = chosen
+ .iter()
.filter(|r| r["type"] == "minecraft:stonecutting")
.collect();
let item_stack = sync
@@ -162,9 +280,10 @@ pub fn update_recipes(
None => w.varint(1),
}
w.varint(item_stack);
- w.varint(item(
- horizon_world::loot::recipe_result_id(&r["result"]).unwrap_or("minecraft:air"),
- ));
+ w.varint(
+ item(horizon_world::loot::recipe_result_id(&r["result"]).unwrap_or("minecraft:air"))
+ .unwrap_or(0),
+ );
w.varint(r["result"]["count"].as_i64().unwrap_or(1) as i32);
w.varint(0); // no components added
w.varint(0); // nor removed
diff --git a/crates/horizon-client/tests/lan_bot.rs b/crates/horizon-client/tests/lan_bot.rs
index 8750ecb64..deee8e09b 100644
--- a/crates/horizon-client/tests/lan_bot.rs
+++ b/crates/horizon-client/tests/lan_bot.rs
@@ -234,9 +234,16 @@ fn server(resources: &Path) -> Server {
}
fn server_with(resources: &Path, net: NetConfig) -> Server {
- let sync = Arc::new(
- SyncData::load(resources, &horizon_world::loot::PackOverlay::NONE).expect("sync data"),
- );
+ server_sync(
+ Arc::new(
+ SyncData::load(resources, &horizon_world::loot::PackOverlay::NONE).expect("sync data"),
+ ),
+ net,
+ )
+}
+
+/// A server over already-built sync data (a test's packs layered in).
+fn server_sync(sync: Arc<SyncData>, net: NetConfig) -> Server {
let lan = Lan::start_with(sync.clone(), net).unwrap();
let biomes: Vec<String> = sync
.dynamic
@@ -436,6 +443,174 @@ fn recipe_settings_packets_update_only_the_players_book_and_survive_save() {
}
}
+/// A server whose pack carries recipes with NeoForge's ingredient shapes:
+/// every guest that joins gets the shapes' items, not empty slots — the
+/// book lists the shaped recipe's compound, the furnace's and the
+/// stonecutter's input sets carry it — and no guest is disconnected over
+/// them (#6368).
+#[test]
+fn neoforge_shapes_items_reach_two_guests() {
+ let Some(resources) = resources() else {
+ return;
+ };
+ let compound = r#"{"type":"neoforge:compound",
+ "children":["minecraft:raw_copper","minecraft:redstone"]}"#;
+ let packs = vec![
+ (
+ "advancement/minecraft:recipes/compound_book".to_owned(),
+ vec![
+ br#"{"criteria":{"tick":{"trigger":"minecraft:tick"}},
+ "rewards":{"recipes":["minecraft:compound_book"]}}"#
+ .to_vec(),
+ ],
+ ),
+ (
+ "recipe/minecraft:compound_book".to_owned(),
+ vec![
+ format!(
+ r#"{{"type":"minecraft:crafting_shaped","pattern":["X"],
+ "key":{{"X":{compound}}},
+ "result":{{"id":"minecraft:copper_ingot"}}}}"#
+ )
+ .into_bytes(),
+ ],
+ ),
+ (
+ "recipe/minecraft:compound_smelting".to_owned(),
+ vec![
+ format!(
+ r#"{{"type":"minecraft:smelting","ingredient":{compound},
+ "result":{{"id":"minecraft:copper_ingot"}}}}"#
+ )
+ .into_bytes(),
+ ],
+ ),
+ (
+ "recipe/minecraft:compound_stonecutting".to_owned(),
+ vec![
+ format!(
+ r#"{{"type":"minecraft:stonecutting","ingredient":{compound},
+ "result":{{"id":"minecraft:copper_ingot"}}}}"#
+ )
+ .into_bytes(),
+ ],
+ ),
+ ];
+ let sync = Arc::new(
+ SyncData::load(
+ &resources,
+ &horizon_world::loot::PackOverlay { files: &packs },
+ )
+ .expect("sync data"),
+ );
+ let (raw_copper, redstone) = (
+ sync.id("minecraft:item", "minecraft:raw_copper").unwrap(),
+ sync.id("minecraft:item", "minecraft:redstone").unwrap(),
+ );
+ let mut s = server_sync(sync, NetConfig::lan(0, "Test - World".into(), 8));
+ let port = s.hub.lan.port;
+ // Guest one joins first and stays while guest two joins and reads its
+ // own join packets, then guest one reads its own.
+ let mut one = run(&mut s, move || connect(port, "CompoundOne", true));
+ let expected = (raw_copper, redstone);
+ let _two_stays = run(&mut s, move || {
+ let mut two = connect(port, "CompoundTwo", true)?;
+ read_join_recipes(&mut two, expected, "guest two")?;
+ Ok(two)
+ });
+ assert_eq!(s.hub.guests.len(), 2, "both guests stay connected");
+ run(&mut s, move || {
+ read_join_recipes(&mut one, expected, "guest one")
+ });
+}
+
+/// Reads a fresh guest's packets until the recipe update and the book add
+/// arrived, checking the compound's items in each: the furnace's input
+/// set, a stonecutting entry's input, and the book entry's requirements.
+fn read_join_recipes(bot: &mut Bot, expected: (i32, i32), who: &str) -> Result<(), String> {
+ let (raw_copper, redstone) = expected;
+ let mut sets_ok = false;
+ let mut book_ok = false;
+ for _ in 0..400 {
+ let packet = bot.recv_play().map_err(|e| format!("{who}: {e}"))?;
+ match packet {
+ C::Unknown(id, payload)
+ if id == horizon_protocol::ids::play::clientbound::UPDATE_RECIPES =>
+ {
+ let mut r = horizon_protocol::buf::Reader::new(&payload);
+ let mut furnace_input = None;
+ let mut stonecutting = Vec::new();
+ for _ in 0..r.varint().map_err(|e| e.to_string())? {
+ let key = r.string(64).map_err(|e| e.to_string())?;
+ let ids: Vec<i32> = (0..r.varint().map_err(|e| e.to_string())?)
+ .map(|_| r.varint().unwrap_or(-1))
+ .collect();
+ if key == "minecraft:furnace_input" {
+ furnace_input = Some(ids);
+ }
+ }
+ let furnace_input = furnace_input.expect("furnace_input set");
+ assert!(
+ furnace_input.contains(&raw_copper) && furnace_input.contains(&redstone),
+ "{who}: furnace_input holds the compound: first ids {:?}",
+ &furnace_input[..furnace_input.len().min(8)]
+ );
+ for _ in 0..r.varint().map_err(|e| e.to_string())? {
+ if let horizon_protocol::packets::recipes::HolderSet::Items(ids) =
+ horizon_protocol::packets::recipes::HolderSet::read(&mut r)
+ .map_err(|e| e.to_string())?
+ {
+ stonecutting.push(ids);
+ }
+ // The result's ItemStackSlotDisplay: its type, the item,
+ // the count and the two empty component lists.
+ for _ in 0..5 {
+ r.varint().map_err(|e| e.to_string())?;
+ }
+ }
+ assert!(
+ stonecutting
+ .iter()
+ .any(|ids| ids.contains(&raw_copper) && ids.contains(&redstone)),
+ "{who}: a stonecutting input holds the compound"
+ );
+ sets_ok = true;
+ }
+ C::RecipeBookAdd(add) => {
+ // sendInitialRecipeBook's own add arrives first, empty
+ // until the first tick rewards its recipes.
+ if add.entries.is_empty() {
+ continue;
+ }
+ let compound = add.entries.iter().any(|e| {
+ e.requirements.as_deref().unwrap_or(&[]).iter().any(|set| {
+ matches!(set,
+ horizon_protocol::packets::recipes::HolderSet::Items(ids)
+ if ids.contains(&raw_copper) && ids.contains(&redstone))
+ })
+ });
+ assert!(
+ compound,
+ "{who}: the book lists the compound recipe ({} entries: {:?})",
+ add.entries.len(),
+ add.entries
+ .iter()
+ .map(|e| e.requirements.clone())
+ .collect::<Vec<_>>()
+ );
+ book_ok = true;
+ }
+ _ => {}
+ }
+ if sets_ok && book_ok {
+ return Ok(());
+ }
+ }
+ Err(format!(
+ "{who}: recipes {sets_ok} book {book_ok} never both arrived"
+ ))
+}
+
#[test]
fn sprint_commands_survive_keyboard_input_changes() {
let Some(resources) = resources() else {