[PR #6910] [MERGED] Native hooks: AnvilCraftEvent.Pre and Post (native_anvil_craft_pre, native_anvil_craft_post) #7185

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/6910
Author: @arismoko
Created: 11/2/2026
Status: ✅ Merged
Merged: 11/2/2026
Merged by: @ludovic111

Base: main ← Head: v2/ses_01M6DKF0Z8BE7TF075HX2BZ8T2-b83f524e8607


📝 Commits (10+)

  • 1dcaf71 Add AnvilCraftEvent.Pre and Post hooks
  • 56725bd Keep the anvil take in the predicted click and skip createResult after a cancelled Pre
  • 7c2cc94 Make the anvil craft hooks server-side and keep the station early return
  • a615551 Leave the deprecated in-frame menu path out of the anvil craft hooks
  • a7372a5 Regenerate the mod API
  • 99520e0 Stub AnvilCraft in the mod API generator's test
  • 050529f Merge remote-tracking branch 'hr/main' into fix6910
  • 5b2b7ac Refuse a cancelled AnvilCraftEvent.Pre take; hook the anvil take only with mods
  • 501b015 Merge main into #6910
  • 72ce1a6 Anvil craft fragments: their own marker names

📊 Changes

9 files changed (+320 additions, -13 deletions)

View changed files

📝 crates/horizon-client/src/game/lan_crafting.rs (+7 -1)
📝 crates/horizon-client/src/game/lan_stations.rs (+54 -11)
📝 crates/horizon-client/src/game/native_hooks.rs (+21 -0)
📝 crates/horizon-client/src/menu.rs (+129 -1)
📝 crates/horizon-client/src/mod_api/generated.rs (+72 -0)
📝 docs/native-mods.md (+2 -0)
➕ tools/native-hook-fragments/native_anvil_craft_post.json (+15 -0)
➕ tools/native-hook-fragments/native_anvil_craft_pre.json (+17 -0)
📝 xtask/src/mod_api.rs (+3 -0)

📄 Description

🤖 Opened by Aria's agent swarm, Dyna, not by Aria.

Adds the native hooks for NeoForge's AnvilCraftEvent.Pre (cancel) and AnvilCraftEvent.Post (listen), fired where vanilla runs AnvilMenu.onTake.

  • native_anvil_craft_pre(player, name, pos, craft, cancel) fires when a player takes an anvil's result, before the levels are charged, the inputs used up and the anvil worn. craft (a new AnvilCraft struct) holds the left and right inputs and the result as they were before. A cancel skips all of that and Post, and the result is still taken: NeoForge's javadoc says cancelling prevents "any post-processing that occurs when the output item is picked up", so the mod does the rest itself.
  • native_anvil_craft_post(player, name, pos, craft) fires after the levels, inputs and anvil wear are done, so a broken anvil is already air. It does not fire when Pre cancelled.

Both fire on the server only, from lan_station_op and lan_station_combined, which serve every player on the server thread, LAN and a dedicated server. lan_open_station sets Menu::anvil_hook, and Menu::anvil_take becomes pub so the station runs it after Pre. The window's predicted take does not call the hooks. The deprecated in-frame menu_session path is left unchanged.

NeoForge's javadoc says both events fire on both sides. Horizon runs the take on the server, so the side is server, as docs/native-mods.md says.

Tested in game

Built through the launcher (native-build, dev profile) with a throwaway trait mod on a throwaway branch of https://github.com/arismoko/horizon-machine-sample (the recommended end-to-end route, used here). The build was one test merge of this PR with the batch's other hooks PRs (#6911, #6912) on main db813a1c3. Each hook logged a WAVE_PROOF line. The commit after that test only adds a type stub to the mod API generator's own test.

Hook Server thread (integrated) Dedicated server
anvil_craft_pre ✅ repairing a damaged diamond pickaxe with a diamond: with Pre cancelling, the result still went to the cursor, but both inputs stayed (pickaxe damage 3, 2 diamonds), the levels stayed at 5 and the anvil was unchanged, and Post didn't fire. With Pre allowed, the same take cost a level (5 to 4) and used one diamond ✅ cancelled take: both inputs stayed, no Post line; allowed take: Pre then Post
anvil_craft_post ✅ fired after the allowed take, once the level and the diamond were spent; not on the cancelled take ✅ fired after the allowed take

pr_ready

pr_ready (tools/pr_ready.py --quick --base db813a1c3879cd7334b6d6e11b9ef2eeb175a49f at 99520e08f, against db813a1c38 at db813a1c3, 14 min 24 s)

Check Result
Scope ✅ 8 files, +198 −12
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 610 passed (40 s)
rustfmt ✅ (11 s)
clippy ✅ (2 min 14 s)
tests: horizon-client, horizon-client-lib, xtask ✅ 2020 passed (9 min 9 s)
doc tests ✅ 0 passed (1 min 36 s)
content root tests ➖ content root untouched
mod API up to date ✅ (24 s)
tokens.css up to date ✅ (1 s)
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ➖ 377 affected, to run in CI (--quick): active_effect_tick, active_effects, ambient_sound, anchor, armor_stand_frost, arrow, arrow_wind_charge, attribute_health, attribute_map_queries, attribute, attribute_updates, audio_attributes and 365 more
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

CI's verify fails on two sign content tests in mod_content_tests.rs. They come from main, where verify is broken the same way, and #6957 fixes them. This PR doesn't touch them.

Part of #4953.

🤖 Generated with Dyna.


🔄 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/6910 **Author:** [@arismoko](https://github.com/arismoko) **Created:** 11/2/2026 **Status:** ✅ Merged **Merged:** 11/2/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `v2/ses_01M6DKF0Z8BE7TF075HX2BZ8T2-b83f524e8607` --- ### 📝 Commits (10+) - [`1dcaf71`](https://github.com/horizon-rust/horizon/commit/1dcaf7115446ccea5ca9b43500126bad1beb5dff) Add AnvilCraftEvent.Pre and Post hooks - [`56725bd`](https://github.com/horizon-rust/horizon/commit/56725bdfdd14ae353516640a1558896388a3f821) Keep the anvil take in the predicted click and skip createResult after a cancelled Pre - [`7c2cc94`](https://github.com/horizon-rust/horizon/commit/7c2cc943aeed537808879caa8b3039bdf4c4961e) Make the anvil craft hooks server-side and keep the station early return - [`a615551`](https://github.com/horizon-rust/horizon/commit/a6155517010d8850fc443e0021988574f1d09098) Leave the deprecated in-frame menu path out of the anvil craft hooks - [`a7372a5`](https://github.com/horizon-rust/horizon/commit/a7372a5028f28c0cf620332ad7d52e15e0f5713f) Regenerate the mod API - [`99520e0`](https://github.com/horizon-rust/horizon/commit/99520e08ff87f304b9c321512b34e925313e764e) Stub AnvilCraft in the mod API generator's test - [`050529f`](https://github.com/horizon-rust/horizon/commit/050529f5c5be3a9b847996e8e172c738b56e85cf) Merge remote-tracking branch 'hr/main' into fix6910 - [`5b2b7ac`](https://github.com/horizon-rust/horizon/commit/5b2b7ac2c5814a349e50a98f66fd9bfcbcb39c65) Refuse a cancelled AnvilCraftEvent.Pre take; hook the anvil take only with mods - [`501b015`](https://github.com/horizon-rust/horizon/commit/501b015ec32976f2edba7ebb37ba67166512cc63) Merge main into #6910 - [`72ce1a6`](https://github.com/horizon-rust/horizon/commit/72ce1a61861e26c427f24905c739d12084b4605e) Anvil craft fragments: their own marker names ### 📊 Changes **9 files changed** (+320 additions, -13 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game/lan_crafting.rs` (+7 -1) 📝 `crates/horizon-client/src/game/lan_stations.rs` (+54 -11) 📝 `crates/horizon-client/src/game/native_hooks.rs` (+21 -0) 📝 `crates/horizon-client/src/menu.rs` (+129 -1) 📝 `crates/horizon-client/src/mod_api/generated.rs` (+72 -0) 📝 `docs/native-mods.md` (+2 -0) ➕ `tools/native-hook-fragments/native_anvil_craft_post.json` (+15 -0) ➕ `tools/native-hook-fragments/native_anvil_craft_pre.json` (+17 -0) 📝 `xtask/src/mod_api.rs` (+3 -0) </details> ### 📄 Description > 🤖 Opened by Aria's agent swarm, Dyna, not by Aria. Adds the native hooks for NeoForge's `AnvilCraftEvent.Pre` (cancel) and `AnvilCraftEvent.Post` (listen), fired where vanilla runs `AnvilMenu.onTake`. - `native_anvil_craft_pre(player, name, pos, craft, cancel)` fires when a player takes an anvil's result, before the levels are charged, the inputs used up and the anvil worn. `craft` (a new `AnvilCraft` struct) holds the left and right inputs and the result as they were before. A cancel skips all of that and Post, and the result is still taken: NeoForge's javadoc says cancelling prevents "any post-processing that occurs when the output item is picked up", so the mod does the rest itself. - `native_anvil_craft_post(player, name, pos, craft)` fires after the levels, inputs and anvil wear are done, so a broken anvil is already air. It does not fire when Pre cancelled. Both fire on the server only, from `lan_station_op` and `lan_station_combined`, which serve every player on the server thread, LAN and a dedicated server. `lan_open_station` sets `Menu::anvil_hook`, and `Menu::anvil_take` becomes `pub` so the station runs it after Pre. The window's predicted take does not call the hooks. The deprecated in-frame `menu_session` path is left unchanged. NeoForge's javadoc says both events fire on both sides. Horizon runs the take on the server, so the side is `server`, as `docs/native-mods.md` says. ## Tested in game Built through the launcher (native-build, dev profile) with a throwaway trait mod on a throwaway branch of https://github.com/arismoko/horizon-machine-sample (the recommended end-to-end route, used here). The build was one test merge of this PR with the batch's other hooks PRs (#6911, #6912) on main db813a1c3. Each hook logged a `WAVE_PROOF` line. The commit after that test only adds a type stub to the mod API generator's own test. | Hook | Server thread (integrated) | Dedicated server | | --- | --- | --- | | `anvil_craft_pre` | ✅ repairing a damaged diamond pickaxe with a diamond: with Pre cancelling, the result still went to the cursor, but both inputs stayed (pickaxe damage 3, 2 diamonds), the levels stayed at 5 and the anvil was unchanged, and Post didn't fire. With Pre allowed, the same take cost a level (5 to 4) and used one diamond | ✅ cancelled take: both inputs stayed, no Post line; allowed take: Pre then Post | | `anvil_craft_post` | ✅ fired after the allowed take, once the level and the diamond were spent; not on the cancelled take | ✅ fired after the allowed take | ## pr_ready **pr_ready** (`tools/pr_ready.py --quick --base db813a1c3879cd7334b6d6e11b9ef2eeb175a49f` at 99520e08f, against db813a1c3879cd7334b6d6e11b9ef2eeb175a49f at db813a1c3, 14 min 24 s) | Check | Result | | --- | --- | | Scope | ✅ 8 files, +198 −12 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 610 passed (40 s) | | rustfmt | ✅ (11 s) | | clippy | ✅ (2 min 14 s) | | tests: horizon-client, horizon-client-lib, xtask | ✅ 2020 passed (9 min 9 s) | | doc tests | ✅ 0 passed (1 min 36 s) | | content root tests | ➖ content root untouched | | mod API up to date | ✅ (24 s) | | tokens.css up to date | ✅ (1 s) | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ 377 affected, to run in CI (--quick): active_effect_tick, active_effects, ambient_sound, anchor, armor_stand_frost, arrow, arrow_wind_charge, attribute_health, attribute_map_queries, attribute, attribute_updates, audio_attributes and 365 more | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | CI's `verify` fails on two sign content tests in `mod_content_tests.rs`. They come from main, where verify is broken the same way, and #6957 fixes them. This PR doesn't touch them. Part of #4953. 🤖 Generated with Dyna. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 06:35:23 +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#7185
No description provided.