[PR #6549] [CLOSED] Fire the item crafted hook when a crafting result is taken #6944

Closed
opened 2026-11-03 06:29:58 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/6549
Author: @MSedgeMC
Created: 11/1/2026
Status: ❌ Closed

Base: main ← Head: fix/mm-crafted


📝 Commits (2)

  • 17b95d8 Run a mod's loot function on the items engine's drops
  • b4611e8 Fire the item crafted hook when a crafting result is taken

📊 Changes

7 files changed (+335 additions, -26 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+5 -0)
📝 crates/horizon-client/src/game/lan_crafting.rs (+10 -0)
📝 crates/horizon-client/src/game/native_hooks.rs (+11 -0)
📝 crates/horizon-client/src/menu.rs (+25 -0)
📝 crates/horizon-items/src/items.rs (+262 -21)
📝 docs/native-mods.md (+9 -5)
➕ tools/native-hook-fragments/item_crafted.json (+13 -0)

📄 Description

Implements the tracker's Item crafted line (PlayerEvent.ItemCraftedEvent, #4953), claimed on the tracker at 22:46:59Z.

What was missing

A native mod had no point to hear a craft. Vanilla awards one in ResultSlot.onTake, which is where NeoForge posts PlayerEvent.ItemCraftedEvent; Horizon's crafting-grid take had no hook, and the shared menu recorded only the recipe and ingredients for the recipe book.

What changed

  • native_item_crafted(player, recipe, stack) (server-side, informational): the player's uuid, the recipe the grid matched (minecraft:oak_planks) and the result stack taken, with its components.
  • Host path (game.rs::click_inventory, the result slot): fired once per craft the take makes, so a shift-click that crafts several fires for each, next to the existing crafted statistic.
  • Guest path: Menu::on_take now records the taken result alongside the recipe it already recorded for awardUsedRecipes (item_crafted), and game/lan_crafting.rs fires the hook for a guest's click under that guest, so a dedicated server's players are heard too.
  • API from a fragment, tools/native-hook-fragments/item_crafted.json, with the @API:item_crafted@ markers; no API number or native-hooks.json entry, which the stamp PR does after merge.

Scope limits and a shape choice

  • It fires for a crafting grid's result (the player's 2x2 or a crafting table's 3x3), not for a stonecutter's, a smithing table's or a furnace's result: NeoForge's event is posted from ResultSlot, and those menus have their own slots (a stonecutter or smithing take is already covered by the recipe-crafted path, which the hook does not touch).
  • NeoForge's event exposes the crafting inventory (getInventory()); a native mod has no container handle, so the hook passes the matched recipe id instead. That is the one shape decision here and the maintainers may prefer the result stack alone, or the grid.
  • Informational only: it cannot change the take, as NeoForge's event cannot.

Proven

On the build VM:

python3 ~/pushrun.py ~/horizon-worktrees/mm-loot --name mm-crafted -- 'cargo test -q -p horizon-client-lib --lib taking_a_crafting_result'
running 1 test
test result: ok. 1 passed; 0 failed

cargo test -q -p horizon-client-lib --lib menu::tests
running 19 tests
test result: ok. 19 passed

cargo clippy -q -p horizon-client-lib --lib -- -D warnings      -> exit 0
cargo clippy -q -p horizon-client --bin horizon-client -- -D warnings -> exit 0
cargo check -q -p horizon-client --bin horizon-client           -> exit 0
rustfmt --edition 2024 --check <the four changed files>          -> clean
python3 -m unittest discover -s tests                            -> OK (skipped=1)

The new test is menu::tests::taking_a_crafting_result_records_the_crafted_stack: it puts an oak log in a crafting table's grid, settles the result, takes slot 0, and asserts the menu recorded minecraft:oak_planks with the four-plank stack. It needs the extracted game data like the other menu tests, so CI skips it; it ran on the build VM, which has that data.

Not proven

  • A real bundle in game, and a dedicated server guest's craft end to end. The guest path is the same Menu::on_take the test exercises, and the hook call sits beside the existing guest recipe-crafted call, but neither was watched in a running server.

Vanilla reference

Vanilla 26.3's ResultSlot.onTake (the craft's statistics and awardUsedRecipes), which Horizon's take already mirrors; NeoForge's PlayerEvent.ItemCraftedEvent javadoc for the name and the firing point.

Fixes the tracker's Item crafted line in #4953.


🔄 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/6549 **Author:** [@MSedgeMC](https://github.com/MSedgeMC) **Created:** 11/1/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/mm-crafted` --- ### 📝 Commits (2) - [`17b95d8`](https://github.com/horizon-rust/horizon/commit/17b95d8828defcf1195b13de606ff3fb9a614f76) Run a mod's loot function on the items engine's drops - [`b4611e8`](https://github.com/horizon-rust/horizon/commit/b4611e862673cf47a6b3188a2250c66ebd1b4970) Fire the item crafted hook when a crafting result is taken ### 📊 Changes **7 files changed** (+335 additions, -26 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+5 -0) 📝 `crates/horizon-client/src/game/lan_crafting.rs` (+10 -0) 📝 `crates/horizon-client/src/game/native_hooks.rs` (+11 -0) 📝 `crates/horizon-client/src/menu.rs` (+25 -0) 📝 `crates/horizon-items/src/items.rs` (+262 -21) 📝 `docs/native-mods.md` (+9 -5) ➕ `tools/native-hook-fragments/item_crafted.json` (+13 -0) </details> ### 📄 Description Implements the tracker's `Item crafted` line (`PlayerEvent.ItemCraftedEvent`, #4953), claimed on the tracker at 22:46:59Z. ## What was missing A native mod had no point to hear a craft. Vanilla awards one in `ResultSlot.onTake`, which is where NeoForge posts `PlayerEvent.ItemCraftedEvent`; Horizon's crafting-grid take had no hook, and the shared menu recorded only the recipe and ingredients for the recipe book. ## What changed - `native_item_crafted(player, recipe, stack)` (server-side, informational): the player's uuid, the recipe the grid matched (`minecraft:oak_planks`) and the result stack taken, with its components. - **Host path** (`game.rs::click_inventory`, the result slot): fired once per craft the take makes, so a shift-click that crafts several fires for each, next to the existing `crafted` statistic. - **Guest path**: `Menu::on_take` now records the taken result alongside the recipe it already recorded for `awardUsedRecipes` (`item_crafted`), and `game/lan_crafting.rs` fires the hook for a guest's click under that guest, so a dedicated server's players are heard too. - API from a fragment, `tools/native-hook-fragments/item_crafted.json`, with the `@API:item_crafted@` markers; no API number or `native-hooks.json` entry, which the stamp PR does after merge. ## Scope limits and a shape choice - It fires for a crafting grid's result (the player's 2x2 or a crafting table's 3x3), not for a stonecutter's, a smithing table's or a furnace's result: NeoForge's event is posted from `ResultSlot`, and those menus have their own slots (a stonecutter or smithing take is already covered by the recipe-crafted path, which the hook does not touch). - NeoForge's event exposes the crafting inventory (`getInventory()`); a native mod has no container handle, so the hook passes the matched recipe id instead. That is the one shape decision here and the maintainers may prefer the result stack alone, or the grid. - Informational only: it cannot change the take, as NeoForge's event cannot. ## Proven On the build VM: ``` python3 ~/pushrun.py ~/horizon-worktrees/mm-loot --name mm-crafted -- 'cargo test -q -p horizon-client-lib --lib taking_a_crafting_result' running 1 test test result: ok. 1 passed; 0 failed cargo test -q -p horizon-client-lib --lib menu::tests running 19 tests test result: ok. 19 passed cargo clippy -q -p horizon-client-lib --lib -- -D warnings -> exit 0 cargo clippy -q -p horizon-client --bin horizon-client -- -D warnings -> exit 0 cargo check -q -p horizon-client --bin horizon-client -> exit 0 rustfmt --edition 2024 --check <the four changed files> -> clean python3 -m unittest discover -s tests -> OK (skipped=1) ``` The new test is `menu::tests::taking_a_crafting_result_records_the_crafted_stack`: it puts an oak log in a crafting table's grid, settles the result, takes slot 0, and asserts the menu recorded `minecraft:oak_planks` with the four-plank stack. It needs the extracted game data like the other menu tests, so CI skips it; it ran on the build VM, which has that data. ## Not proven - A real bundle in game, and a dedicated server guest's craft end to end. The guest path is the same `Menu::on_take` the test exercises, and the hook call sits beside the existing guest recipe-crafted call, but neither was watched in a running server. ## Vanilla reference Vanilla 26.3's `ResultSlot.onTake` (the craft's statistics and `awardUsedRecipes`), which Horizon's take already mirrors; NeoForge's `PlayerEvent.ItemCraftedEvent` javadoc for the name and the firing point. Fixes the tracker's `Item crafted` line in #4953. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 06:29:58 +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#6944
No description provided.