From 859236bd9da591444d9e18b137692993585a18d0 Mon Sep 17 00:00:00 2001 From: rdbtCVS <87152661+rdbtCVS@users.noreply.github.com> Date: Sun, 25 Oct 2026 03:25:56 +0000 Subject: [PATCH 1/2] Fix recipe removal notifications for server players Notify connected players of the display IDs forgotten by /recipe take. Discard queued additions for recipes the player no longer knows. Add LAN regression coverage for both single-player paths. Co-Authored-By: OpenCode agentrouter/gpt-6.1-sol --- .../src/game/commands/world_cmds.rs | 15 +++- crates/horizon-client/src/lan/hub.rs | 4 +- tools/lan_e2e.py | 69 ++++++++++++++++++- 3 files changed, 85 insertions(+), 3 deletions(-) diff --git a/crates/horizon-client/src/game/commands/world_cmds.rs b/crates/horizon-client/src/game/commands/world_cmds.rs index 1f7504d8a..ce8d3dfb1 100644 --- a/crates/horizon-client/src/game/commands/world_cmds.rs +++ b/crates/horizon-client/src/game/commands/world_cmds.rs @@ -59,7 +59,20 @@ impl Game<'_> { self.recipe_unlocked(&unlocked); count as i32 } else { - self.level.recipe_book.remove_recipes(index, &recipes) as i32 + let removed: Vec = recipes + .iter() + .filter(|r| self.level.recipe_book.knows(r)) + .flat_map(|r| index.display_ids(r)) + .collect(); + let count = self.level.recipe_book.remove_recipes(index, &recipes); + // ServerRecipeBook.removeRecipes sends the displays actually + // removed, including every display of a transmutation recipe. + if self.lan_acting.is_some() && !removed.is_empty() { + self.guest_packets.push(C::RecipeBookRemove( + horizon_protocol::packets::recipes::RecipeBookRemove { ids: removed }, + )); + } + count as i32 }; tracker.track(&h, n); } diff --git a/crates/horizon-client/src/lan/hub.rs b/crates/horizon-client/src/lan/hub.rs index 4f93b6ff9..5b6364975 100644 --- a/crates/horizon-client/src/lan/hub.rs +++ b/crates/horizon-client/src/lan/hub.rs @@ -1827,7 +1827,9 @@ impl Hub { fn flush_advancements(&mut self, i: usize, show: bool) { let sync = self.sync.clone(); let g = &mut self.guests[i]; - let unlocked = std::mem::take(&mut g.recipes_unlocked); + let mut unlocked = std::mem::take(&mut g.recipes_unlocked); + // A recipe given and taken before this flush must not reappear. + unlocked.retain(|id| g.recipe_book.knows(id)); if let Some(add) = sync.advancements.recipes_added(&unlocked, &sync) { g.send(&raw(ids::RECIPE_BOOK_ADD, add)); } diff --git a/tools/lan_e2e.py b/tools/lan_e2e.py index 3ece4b448..bbe4e8202 100755 --- a/tools/lan_e2e.py +++ b/tools/lan_e2e.py @@ -87,7 +87,9 @@ address. The script then checks, from both sides, what a guest's game used to ge - commands: the guest's chat completes commands and their arguments over the server's command tree (Tab), and runs what it completed; - recipes: the guest's recipe book lists the planks recipe the logs unlock, and clicking it - places a log in the inventory's crafting grid (the server places it). + places a log in the inventory's crafting grid (the server places it). +- recipe_removal: the host and guest each forget all and individual recipes while the book + is open; it stays empty when reopened, and a later grant appears (#1495). - feedback: the guest's command feedback names the guest and shows the numbers, and the host (an operator) is told of it as `[Guest: ...]`. - clicks: with real mouse presses (not click-slot, which skips the screen's press and drag @@ -5496,5 +5498,70 @@ CHECKS += ['villagers'] CHECK_FNS.update(villagers=check_villagers) +def check_recipe_removal(host, guest, out): + """ServerRecipeBook.removeRecipes sends ClientboundRecipeBookRemovePacket to the player: + the open book updates immediately, reopening keeps it empty, and later grants still arrive.""" + seen = {} + for game in (host, guest): + back_to_game(game) + game('command', command='clear @s') + game('command', command='give @s minecraft:oak_log 4') + game('command', command='recipe give @s minecraft:oak_planks') + game('command', command='recipe give @s minecraft:stick') + game.wait(40) + game.raw('key', 'e', 'tap') + game.wait(5) + try: + book = game('screen').get('recipe_book') + assert book, f'{game.name}: the inventory has no recipe book' + if len(book['targets']) == 1: + game.raw('click-at', *centre(book['targets'][0])) + game.wait(5) + book = game('screen')['recipe_book'] + known = book['known'] + assert known > 1, f'{game.name}: recipes were not granted: {book}' + game.shot(out, 'recipe-removal-before') + + game('command', command='recipe take @s *') + game.wait(20) + empty = game('screen')['recipe_book']['known'] + game.shot(out, 'recipe-removal-empty') + assert empty == 0, f'{game.name}: forgotten recipes remain in the open book: {empty}' + game.raw('key', 'esc', 'tap') + game.wait(5) + game.raw('key', 'e', 'tap') + game.wait(5) + reopened = game('screen')['recipe_book']['known'] + assert reopened == 0, f'{game.name}: reopening restored {reopened} forgotten recipes' + + game('command', command='recipe give @s minecraft:oak_planks') + game('command', command='recipe give @s minecraft:stick') + game.wait(20) + given = game('screen')['recipe_book']['known'] + assert given == 2, f'{game.name}: two later grants did not appear: {given}' + game('command', command='recipe take @s minecraft:oak_planks') + game.wait(20) + one = game('screen')['recipe_book']['known'] + assert one == 1, f'{game.name}: taking one recipe left {one}, expected 1' + game('command', command='recipe take @s minecraft:stick') + game.wait(20) + assert game('screen')['recipe_book']['known'] == 0, f'{game.name}: the last recipe remains' + + game('command', command='recipe give @s minecraft:oak_planks') + game.wait(20) + granted = game('screen')['recipe_book']['known'] + assert granted == 1, f'{game.name}: a later grant did not appear: {granted}' + game.shot(out, 'recipe-removal-granted') + seen[game.name] = {'known': known, 'empty': empty, 'reopened': reopened, + 'given': given, 'one': one, 'granted': granted} + finally: + back_to_game(game) + return seen + + +CHECKS += ['recipe_removal'] +CHECK_FNS.update(recipe_removal=check_recipe_removal) + + if __name__ == '__main__': main() From b165506d6e97caf0a84c9f57f3393a1a96480a57 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sun, 25 Oct 2026 05:49:46 +0100 Subject: [PATCH 2/2] Recipe book: removeRecipes returns the display ids it removed, as vanilla The /recipe take path no longer computes them a second time. Co-Authored-By: Claude Opus 5.5 --- .../examples/probe/recipe_book_fixture.rs | 2 +- .../horizon-client/src/game/commands/world_cmds.rs | 13 ++++--------- crates/horizon-client/src/recipe_book.rs | 10 ++++++---- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/crates/horizon-client/examples/probe/recipe_book_fixture.rs b/crates/horizon-client/examples/probe/recipe_book_fixture.rs index 7117d4bbe..ce2afe624 100644 --- a/crates/horizon-client/examples/probe/recipe_book_fixture.rs +++ b/crates/horizon-client/examples/probe/recipe_book_fixture.rs @@ -83,7 +83,7 @@ pub fn main() -> horizon_client::Result<()> { let mut extra = String::new(); match kind { "give" => count = book.add_recipes(&index, &list()).0, - "take" => count = book.remove_recipes(&index, &list()), + "take" => count = book.remove_recipes(&index, &list()).len(), "seen" => book.remove_highlight(op["id"].as_str().unwrap_or_default()), "set" => { let i = match op["type"].as_str().unwrap_or_default() { diff --git a/crates/horizon-client/src/game/commands/world_cmds.rs b/crates/horizon-client/src/game/commands/world_cmds.rs index ce8d3dfb1..c9e5c8003 100644 --- a/crates/horizon-client/src/game/commands/world_cmds.rs +++ b/crates/horizon-client/src/game/commands/world_cmds.rs @@ -59,20 +59,15 @@ impl Game<'_> { self.recipe_unlocked(&unlocked); count as i32 } else { - let removed: Vec = recipes - .iter() - .filter(|r| self.level.recipe_book.knows(r)) - .flat_map(|r| index.display_ids(r)) - .collect(); - let count = self.level.recipe_book.remove_recipes(index, &recipes); - // ServerRecipeBook.removeRecipes sends the displays actually - // removed, including every display of a transmutation recipe. + let removed = self.level.recipe_book.remove_recipes(index, &recipes); + let count = removed.len() as i32; + // A network player's client drops them from its book. if self.lan_acting.is_some() && !removed.is_empty() { self.guest_packets.push(C::RecipeBookRemove( horizon_protocol::packets::recipes::RecipeBookRemove { ids: removed }, )); } - count as i32 + count }; tracker.track(&h, n); } diff --git a/crates/horizon-client/src/recipe_book.rs b/crates/horizon-client/src/recipe_book.rs index fa247a695..c18fa3e48 100644 --- a/crates/horizon-client/src/recipe_book.rs +++ b/crates/horizon-client/src/recipe_book.rs @@ -787,13 +787,15 @@ impl Settings { } (displays, added) } - /// `ServerRecipeBook.removeRecipes`: the displays removed. - pub fn remove_recipes(&mut self, index: &RecipeIndex, ids: &[String]) -> usize { - let mut displays = 0; + /// `ServerRecipeBook.removeRecipes`: the display ids removed, which its + /// `ClientboundRecipeBookRemovePacket` lists (a transmute recipe has one + /// per material count). + pub fn remove_recipes(&mut self, index: &RecipeIndex, ids: &[String]) -> Vec { + let mut displays = Vec::new(); for id in ids { if self.recipes.remove(id) { self.to_be_displayed.remove(id); - displays += index.displays(id); + displays.extend(index.display_ids(id)); } } displays