[PR #2284] [MERGED] mods: capability recipes (API level 5): the game's items and recipes, for recipe viewers #4170

Closed
opened 2026-11-03 04:15:12 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/2284
Author: @ludovic111
Created: 10/26/2026
Status: ✅ Merged
Merged: 10/26/2026
Merged by: @ludovic111

Base: main ← Head: feat/mod-recipes-read


📝 Commits (2)

  • 409a828 mods: capability recipes (API level 4), the game's items and recipes for recipe viewers
  • b360e3c Merge main (#1895: world takes level 4): recipes moves to API level 5

📊 Changes

15 files changed (+632 additions, -15 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+2 -0)
➕ crates/horizon-client/src/game/mod_recipes.rs (+252 -0)
📝 crates/horizon-client/src/game/mods.rs (+11 -0)
📝 crates/horizon-client/src/game/recipe_book.rs (+19 -0)
📝 crates/horizon-client/src/stations.rs (+3 -0)
📝 crates/horizon-mod-sdk/src/lib.rs (+1 -1)
📝 crates/horizon-mod-sdk/wit/horizon.wit (+76 -0)
📝 crates/horizon-mods/src/api_level.rs (+5 -2)
📝 crates/horizon-mods/src/manifest.rs (+9 -2)
📝 crates/horizon-mods/src/runtime.rs (+54 -0)
📝 crates/horizon-mods/tests/sandbox.rs (+88 -6)
📝 crates/horizon-mods/tests/ui_guest/src/lib.rs (+39 -1)
📝 docs/api/mods-reference.md (+71 -1)
📝 docs/api/stability.md (+1 -1)
📝 docs/mods.md (+1 -1)

📄 Description

🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself.

The first step toward a recipe browser that ships as an official mod: mods can read the game's items and recipes, and which recipes the player knows. This adds capability recipes (experimental) at API level 5. It is stacked on #2171 (level 3) and changes no existing function.

The work is clean room. It is built only from vanilla 26.3's recipe book and recipe types, and Horizon's own recipe_book.rs, crafting.rs, stations.rs and brewing.rs.

What

  • WIT interface recipes:
    • items(): every item in registry order, with its name in the player's language and its item tags.
    • all(): every recipe. Each one has its kind (crafting shaped and shapeless, smelting, blasting, smoking, campfire, stonecutting, smithing, brewing), the recipe book's category and group, a shaped grid's size, and each slot's stacks.
      • Stacks point into items() by index, which keeps the tables small. Components beyond the item's own are written in vanilla item syntax (a potion's potion_contents).
      • It also gives the results, the cooking time and experience, and the recipe book's display id.
    • known(): the display ids the player's book holds.
  • Where the data comes from:
    • Crafting and furnace recipes come from the recipe book's own entries: vanilla's RecipeDisplayEntrys, with the same display ids the server sends.
    • Campfire, stonecutting and smithing recipes come from the recipe data. Brewing comes from Horizon's brewing data, for display only.
    • known reads the client book in every mode. In single player it is synced from the world's book; on a server it is the server's packets. So the browser's "known" and the later "fill the grid" step follow the server's book, the same rule vanilla's handlePlaceRecipe applies.
    • On a server that isn't Horizon's, the recipes shown are vanilla 26.3's, because a client is sent no others.
  • Cost: the game builds the tables once, the first time a running mod reads them, and never while no mod imports recipes. Restarting mods rebuilds them, since content mods change the items.
  • Smithing::Transform now keeps its recipe id.

Tests

  • sandbox.rs recipes_reads_the_tables: the test guest reads tables of vanilla's size (1,500 items, 1,600 recipes of nine five-item slots) inside one command's fuel, including components and known ids. With no tables it gets empty lists, not a trap.
  • In game, the test guest's /recipes in all five modes: in-frame, server thread, LAN guest of an in-frame host, LAN guest of a host on its server thread, and a guest of a dedicated server.
    • It reads 1,658 items and 2,016 recipes, 279 of them brewing.
    • minecraft:oak_planks is shapeless, made from oak_log, gives 4, and shows known false, then true after /recipe give.
    • A smithing transform, a stonecutting recipe, blasting (100 ticks) and campfire (600 ticks) each come out as their own kind.

All five modes pass (44 checks; the driver is a scratch script). In LAN and dedicated, the guest changes its own book (/recipe give @s), because Horizon's /recipe on another player changes the runner's book, a separate bug noted below.

pr_ready (tools/pr_ready.py --quick --base feat/mod-run-quiet on ludovics-mac-mini, against feat/mod-run-quiet at fb8643081, 11 min 45 s)

Check Result
Scope ✅ 15 files, +630 −13
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ➖ no Python change
rustfmt ✅ (9 s)
clippy ✅ (1 min 32 s)
tests: horizon-client, horizon-mod-sdk, horizon-mods, horizon-mods-test-ui-guest ✅ 1368 passed (5 min 14 s)
doc tests ✅ 2 passed (1 min 23 s)
tokens.css up to date ➖ theme untouched
launcher rustfmt ✅ (1 s)
launcher clippy ✅ (1 min 33 s)
launcher tests ✅ 132 passed (1 min 51 s)
Parity ➖ 115 affected, to run in CI (--quick): ambient_sound, arrow, audio_attributes, auto_jump, block_entity_anim, block_entity_render, block_entity_tickers, block_particles, block_removal, block_transformer, breaking_model, camera and 103 more

Over the ~500 lines: the WIT and the generated reference are 150 of them, and the sandbox test and the guest's command another 100.

Found on the way (not in this PR): /recipe give|take <another player> changes the book of the player or console running it, not the target's (cmd_recipe uses self.level.recipe_book for every target). The message names the target, but nothing reaches them. Vanilla awards the target's own ServerRecipeBook.

skip-release: players see nothing until a mod uses it.

🤖 Generated with Claude Code


🔄 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/2284 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/26/2026 **Status:** ✅ Merged **Merged:** 10/26/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `feat/mod-recipes-read` --- ### 📝 Commits (2) - [`409a828`](https://github.com/horizon-rust/horizon/commit/409a8281283d7776dbb25e8c2f42863cc083971e) mods: capability recipes (API level 4), the game's items and recipes for recipe viewers - [`b360e3c`](https://github.com/horizon-rust/horizon/commit/b360e3c26cd0cfe958c49367fa63a918411966e7) Merge main (#1895: world takes level 4): recipes moves to API level 5 ### 📊 Changes **15 files changed** (+632 additions, -15 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+2 -0) ➕ `crates/horizon-client/src/game/mod_recipes.rs` (+252 -0) 📝 `crates/horizon-client/src/game/mods.rs` (+11 -0) 📝 `crates/horizon-client/src/game/recipe_book.rs` (+19 -0) 📝 `crates/horizon-client/src/stations.rs` (+3 -0) 📝 `crates/horizon-mod-sdk/src/lib.rs` (+1 -1) 📝 `crates/horizon-mod-sdk/wit/horizon.wit` (+76 -0) 📝 `crates/horizon-mods/src/api_level.rs` (+5 -2) 📝 `crates/horizon-mods/src/manifest.rs` (+9 -2) 📝 `crates/horizon-mods/src/runtime.rs` (+54 -0) 📝 `crates/horizon-mods/tests/sandbox.rs` (+88 -6) 📝 `crates/horizon-mods/tests/ui_guest/src/lib.rs` (+39 -1) 📝 `docs/api/mods-reference.md` (+71 -1) 📝 `docs/api/stability.md` (+1 -1) 📝 `docs/mods.md` (+1 -1) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. The first step toward a recipe browser that ships as an official mod: mods can read the game's **items and recipes**, and which recipes the player knows. This adds capability `recipes` (experimental) at API level 5. It is stacked on #2171 (level 3) and changes no existing function. The work is clean room. It is built only from vanilla 26.3's recipe book and recipe types, and Horizon's own `recipe_book.rs`, `crafting.rs`, `stations.rs` and `brewing.rs`. ## What - **WIT** `interface recipes`: - `items()`: every item in registry order, with its name in the player's language and its item tags. - `all()`: every recipe. Each one has its kind (crafting shaped and shapeless, smelting, blasting, smoking, campfire, stonecutting, smithing, brewing), the recipe book's category and group, a shaped grid's size, and each slot's stacks. - Stacks point into `items()` by index, which keeps the tables small. Components beyond the item's own are written in vanilla item syntax (a potion's `potion_contents`). - It also gives the results, the cooking time and experience, and the recipe book's display id. - `known()`: the display ids the player's book holds. - **Where the data comes from:** - Crafting and furnace recipes come from the recipe book's own entries: vanilla's `RecipeDisplayEntry`s, with the same display ids the server sends. - Campfire, stonecutting and smithing recipes come from the recipe data. Brewing comes from Horizon's brewing data, for display only. - `known` reads the client book in every mode. In single player it is synced from the world's book; on a server it is the server's packets. So the browser's "known" and the later "fill the grid" step follow the server's book, the same rule vanilla's `handlePlaceRecipe` applies. - On a server that isn't Horizon's, the recipes shown are vanilla 26.3's, because a client is sent no others. - **Cost:** the game builds the tables once, the first time a running mod reads them, and never while no mod imports `recipes`. Restarting mods rebuilds them, since content mods change the items. - `Smithing::Transform` now keeps its recipe id. ## Tests - `sandbox.rs` `recipes_reads_the_tables`: the test guest reads tables of vanilla's size (1,500 items, 1,600 recipes of nine five-item slots) inside one command's fuel, including components and known ids. With no tables it gets empty lists, not a trap. - In game, the test guest's `/recipes` in **all five modes**: in-frame, server thread, LAN guest of an in-frame host, LAN guest of a host on its server thread, and a guest of a dedicated server. - It reads 1,658 items and 2,016 recipes, 279 of them brewing. - `minecraft:oak_planks` is shapeless, made from `oak_log`, gives 4, and shows known false, then true after `/recipe give`. - A smithing transform, a stonecutting recipe, blasting (100 ticks) and campfire (600 ticks) each come out as their own kind. All five modes pass (44 checks; the driver is a scratch script). In LAN and dedicated, the guest changes its own book (`/recipe give @s`), because Horizon's `/recipe` on another player changes the runner's book, a separate bug noted below. **pr_ready** (`tools/pr_ready.py --quick --base feat/mod-run-quiet` on ludovics-mac-mini, against feat/mod-run-quiet at fb8643081, 11 min 45 s) | Check | Result | | --- | --- | | Scope | ✅ 15 files, +630 −13 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ➖ no Python change | | rustfmt | ✅ (9 s) | | clippy | ✅ (1 min 32 s) | | tests: horizon-client, horizon-mod-sdk, horizon-mods, horizon-mods-test-ui-guest | ✅ 1368 passed (5 min 14 s) | | doc tests | ✅ 2 passed (1 min 23 s) | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ✅ (1 s) | | launcher clippy | ✅ (1 min 33 s) | | launcher tests | ✅ 132 passed (1 min 51 s) | | Parity | ➖ 115 affected, to run in CI (--quick): ambient_sound, arrow, audio_attributes, auto_jump, block_entity_anim, block_entity_render, block_entity_tickers, block_particles, block_removal, block_transformer, breaking_model, camera and 103 more | Over the ~500 lines: the WIT and the generated reference are 150 of them, and the sandbox test and the guest's command another 100. **Found on the way (not in this PR):** `/recipe give|take <another player>` changes the book of the player or console running it, not the target's (`cmd_recipe` uses `self.level.recipe_book` for every target). The message names the target, but nothing reaches them. Vanilla awards the target's own `ServerRecipeBook`. `skip-release`: players see nothing until a mod uses it. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 04:15:12 +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#4170
No description provided.