[PR #4961] [MERGED] Make a knowledge book teach its recipes #5976

Closed
opened 2026-11-03 05:16:21 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/4961
Author: @MSedgeMC
Created: 10/31/2026
Status: ✅ Merged
Merged: 10/31/2026
Merged by: @rdbtCVS

Base: main ← Head: fix/knowledge-book-unlock


📝 Commits (1)

  • f8b5fed Make a knowledge book teach its recipes

📊 Changes

3 files changed (+152 additions, -0 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+2 -0)
📝 crates/horizon-client/src/game/advancements.rs (+33 -0)
📝 crates/horizon-client/src/recipe_book.rs (+117 -0)

📄 Description

Fixes the KnowledgeBookItem.use row in the port ledger. (No issue.)

KnowledgeBookItem.use reads the recipe ids in the book's minecraft:recipes component, calls awardRecipes on them, and returns SUCCESS; an empty list is FAIL, and an id the server has no recipe for logs Invalid recipe: {} and fails without learning the valid ids beside it. The book is consumed before either check (ItemStack.consume), so an invalid book is used up too, and only a player with infinite materials keeps it. There is no sound.

Horizon had no handler: a knowledge book in hand matched no branch of the item chain and fell through to "not a block, nothing happens", so the item was inert.

The implementation reuses the award path /recipe give and crafting already go through — Settings::add_recipes (the ServerRecipeBook.addRecipes port) and Game::recipe_unlocked (toast, the recipe-book packet for a network player, and the recipe_unlocked advancement) — with the component parsed as vanilla's codec does, the namespace defaulting to minecraft. A book that names an unknown recipe returns FAIL, which leaves the off hand its turn, as vanilla's startUseItem does.

What is proven: cargo test -p horizon-client --lib knowledge_book → 1 passed on a build box, covering the four cases: two recipes unlocked with the stack going 2 → 1; a creative player keeping the book; an unknown id failing without learning the valid id beside it and with the book consumed; and a bare book (the /give default) failing, consumed.

What is not proven: the game half — that clicking the book reaches the handler, swings the arm, shows the toast, sends the recipe-book packet and counts the used statistic. The test cannot reach it: it is a method on the bin-only Game, and the crate has no Game fixture. Nor is there a parity harness; CONTRIBUTING asks for one on gameplay changes, and adding VanillaKnowledgeBookOracle plus a probe is the right follow-up rather than something I can verify here.

One deliberate deviation from local convention, in vanilla's favour: most helpers in that chain return true on FAIL ("ends here"), while this one returns false so the other hand gets its turn, matching Minecraft.startUseItem.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon/pull/4961 **Author:** [@MSedgeMC](https://github.com/MSedgeMC) **Created:** 10/31/2026 **Status:** ✅ Merged **Merged:** 10/31/2026 **Merged by:** [@rdbtCVS](https://github.com/rdbtCVS) **Base:** `main` ← **Head:** `fix/knowledge-book-unlock` --- ### 📝 Commits (1) - [`f8b5fed`](https://github.com/horizon-rust/horizon/commit/f8b5fed2f018be6999e8fdedd40e2b69a9317557) Make a knowledge book teach its recipes ### 📊 Changes **3 files changed** (+152 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+2 -0) 📝 `crates/horizon-client/src/game/advancements.rs` (+33 -0) 📝 `crates/horizon-client/src/recipe_book.rs` (+117 -0) </details> ### 📄 Description Fixes the `KnowledgeBookItem.use` row in the port ledger. (No issue.) `KnowledgeBookItem.use` reads the recipe ids in the book's `minecraft:recipes` component, calls `awardRecipes` on them, and returns `SUCCESS`; an empty list is `FAIL`, and an id the server has no recipe for logs `Invalid recipe: {}` and fails **without learning the valid ids beside it**. The book is consumed *before* either check (`ItemStack.consume`), so an invalid book is used up too, and only a player with infinite materials keeps it. There is no sound. Horizon had no handler: a knowledge book in hand matched no branch of the item chain and fell through to "not a block, nothing happens", so the item was inert. The implementation reuses the award path `/recipe give` and crafting already go through — `Settings::add_recipes` (the `ServerRecipeBook.addRecipes` port) and `Game::recipe_unlocked` (toast, the recipe-book packet for a network player, and the `recipe_unlocked` advancement) — with the component parsed as vanilla's codec does, the namespace defaulting to `minecraft`. A book that names an unknown recipe returns `FAIL`, which leaves the off hand its turn, as vanilla's `startUseItem` does. **What is proven:** `cargo test -p horizon-client --lib knowledge_book` → 1 passed on a build box, covering the four cases: two recipes unlocked with the stack going 2 → 1; a creative player keeping the book; an unknown id failing without learning the valid id beside it and with the book consumed; and a bare book (the `/give` default) failing, consumed. **What is not proven:** the game half — that clicking the book reaches the handler, swings the arm, shows the toast, sends the recipe-book packet and counts the `used` statistic. The test cannot reach it: it is a method on the bin-only `Game`, and the crate has no `Game` fixture. Nor is there a parity harness; `CONTRIBUTING` asks for one on gameplay changes, and adding `VanillaKnowledgeBookOracle` plus a probe is the right follow-up rather than something I can verify here. One deliberate deviation from local convention, in vanilla's favour: most helpers in that chain return `true` on `FAIL` ("ends here"), while this one returns `false` so the other hand gets its turn, matching `Minecraft.startUseItem`. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 05:16:21 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#5976
No description provided.