[PR #4483] [MERGED] Native mods: hook points for breaking and placing a block (API 6) #5648

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/4483
Author: @ludovicthenot
Created: 10/30/2026
Status: ✅ Merged
Merged: 10/30/2026
Merged by: @levzzz5154

Base: main ← Head: native-block-hooks


📝 Commits (2)

  • fbac0ae Native mods: hook points for breaking and placing a block (API 6)
  • f969e62 Merge main: block hooks are API 14

📊 Changes

4 files changed (+54 additions, -2 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+9 -1)
📝 crates/horizon-client/src/game/native_hooks.rs (+30 -1)
📝 docs/native-mods.md (+5 -0)
📝 native-hooks.json (+10 -0)

📄 Description

🤖 Opened by ludovicthenot's AI agent (Claude Code, Claude Opus 5.5), not by ludovicthenot personally.

Stacked on #4302 (API 5), itself on #4284 (API 4): review only the last commit (fbac0ae2d, +55 −2).

What and why

Fixes #4474. Part of #3911 (Mods), gap B of #1854 (block behaviour hooks), first in the priority list of #4402: a native mod can now react when a player breaks or places a block, which protected blocks, tools that break more than one block, extra drops and blocks that do something when placed need. Named after the vanilla calls they sit in, as agreed on #4402 until CONTRIBUTING changes.

  • native_destroy_block(&mut self, pos: [i32; 3], state: BlockStateId, canceled: &mut bool): a player breaks the block state at pos, once the game allowed it (the held item can break blocks, the debug stick didn't take the click). A mod that sets canceled keeps the block: nothing is destroyed or dropped, and no rumble. In break_block_as_player (game.rs), where ServerPlayerGameMode.destroyBlock starts, before Block.playerWillDestroy.
  • native_place_block(&mut self, stack: &ItemStack, pos: [i32; 3], state: BlockStateId): a player placed stack as the block state at pos. In use_hand, where BlockItem.place set it, after the placed_block trigger and before the stack shrinks. It only hears: a mod stops a placement by claiming native_use_item_on (#4302), which runs before it, so there is one way to cancel, not two.
  • Every player goes through both on the server (the single player server thread, LAN guests through guest_destroy and their UseItemOn, dedicated servers), so they are authoritative; the helpers (native_player...) read the acting player. A guest whose break is canceled gets the block back through the usual acknowledgement, as when its item can't break the block.
  • Not canceled, everything goes on exactly as before: nothing changes without a native mod.
  • NATIVE_HOOKS_API 5 → 6, its native-hooks.json entries (destroy_block and place_block, version 1), and an "API 6" paragraph in docs/native-mods.md. The number follows #4302 and moves with it, or becomes whatever is free at merge if #4402 settles that.

Kind

  • parity: Horizon now does what vanilla 26.3 does
  • bug: a crash or a breakage
  • perf: faster, or less memory
  • feature: something new for players (listed under New in the release notes)
  • extra: Horizon-only, off by default
  • tooling: tools, CI, tests, harnesses
  • docs

Vanilla reference

Horizon-only (hook points; they do nothing in Horizon). native_destroy_block sits where ServerPlayerGameMode.destroyBlock has passed its checks and is about to call Block.playerWillDestroy; native_place_block where BlockItem.place has set the block and fired CriteriaTriggers.PLACED_BLOCK. Without a native mod breaking and placing are unchanged; CI's parity job picks the harnesses that cover game.rs.

Tested in the game

A throwaway local change (not in this pull request) logged both hooks and made native_destroy_block cancel when an environment variable was set. Fresh survival worlds on the server thread, through horizon-ctl (--offscreen): a dirt floor next to the player (/fill), /give @s minecraft:dirt 4, then place a dirt block and break it by hand:

Run Hooks called Place Break
no cancel place_block minecraft:dirt, then destroy_block minecraft:dirt, same position placed, 1 dirt used air, 1 dirt dropped
cancel the same placed, 1 dirt used still dirt, nothing dropped

A LAN guest's canceled break was not tested with a second client.

Self-check

On this commit: cargo fmt --check ✅, cargo clippy -p horizon-client --bin horizon-client ✅ (no warnings), native_hooks::tests ✅ 4 passed (the catalog test checks the two new entries). tools/pr_ready.py was not run on this one; the change has the same shape as #4302 (one call per hook in game.rs, empty hook points, catalog, docs).

Label: feature (players get something new).


🔄 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/4483 **Author:** [@ludovicthenot](https://github.com/ludovicthenot) **Created:** 10/30/2026 **Status:** ✅ Merged **Merged:** 10/30/2026 **Merged by:** [@levzzz5154](https://github.com/levzzz5154) **Base:** `main` ← **Head:** `native-block-hooks` --- ### 📝 Commits (2) - [`fbac0ae`](https://github.com/horizon-rust/horizon/commit/fbac0ae2d9221efd5c4b9ba455d72be5323260ad) Native mods: hook points for breaking and placing a block (API 6) - [`f969e62`](https://github.com/horizon-rust/horizon/commit/f969e62a566ab6b4e0987c7cc21c915b5b8ae6b9) Merge main: block hooks are API 14 ### 📊 Changes **4 files changed** (+54 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+9 -1) 📝 `crates/horizon-client/src/game/native_hooks.rs` (+30 -1) 📝 `docs/native-mods.md` (+5 -0) 📝 `native-hooks.json` (+10 -0) </details> ### 📄 Description > 🤖 Opened by ludovicthenot's AI agent (Claude Code, Claude Opus 5.5), not by ludovicthenot personally. **Stacked on #4302 (API 5), itself on #4284 (API 4): review only the last commit** (`fbac0ae2d`, +55 −2). ## What and why Fixes #4474. Part of #3911 (Mods), gap **B** of #1854 (block behaviour hooks), first in the priority list of #4402: a native mod can now react when a player breaks or places a block, which protected blocks, tools that break more than one block, extra drops and blocks that do something when placed need. Named after the vanilla calls they sit in, as agreed on #4402 until CONTRIBUTING changes. - **`native_destroy_block(&mut self, pos: [i32; 3], state: BlockStateId, canceled: &mut bool)`**: a player breaks the block `state` at `pos`, once the game allowed it (the held item can break blocks, the debug stick didn't take the click). A mod that sets `canceled` keeps the block: nothing is destroyed or dropped, and no rumble. In `break_block_as_player` (game.rs), where `ServerPlayerGameMode.destroyBlock` starts, before `Block.playerWillDestroy`. - **`native_place_block(&mut self, stack: &ItemStack, pos: [i32; 3], state: BlockStateId)`**: a player placed `stack` as the block `state` at `pos`. In `use_hand`, where `BlockItem.place` set it, after the `placed_block` trigger and before the stack shrinks. It only hears: a mod stops a placement by claiming `native_use_item_on` (#4302), which runs before it, so there is one way to cancel, not two. - Every player goes through both on the server (the single player server thread, LAN guests through `guest_destroy` and their `UseItemOn`, dedicated servers), so they are authoritative; the helpers (`native_player`...) read the acting player. A guest whose break is canceled gets the block back through the usual acknowledgement, as when its item can't break the block. - Not canceled, everything goes on exactly as before: nothing changes without a native mod. - `NATIVE_HOOKS_API` 5 → 6, its `native-hooks.json` entries (`destroy_block` and `place_block`, version 1), and an "API 6" paragraph in `docs/native-mods.md`. The number follows #4302 and moves with it, or becomes whatever is free at merge if #4402 settles that. ## Kind - [ ] parity: Horizon now does what vanilla 26.3 does - [ ] bug: a crash or a breakage - [ ] perf: faster, or less memory - [x] feature: something new for players (listed under New in the release notes) - [ ] extra: Horizon-only, off by default - [ ] tooling: tools, CI, tests, harnesses - [ ] docs ## Vanilla reference Horizon-only (hook points; they do nothing in Horizon). `native_destroy_block` sits where `ServerPlayerGameMode.destroyBlock` has passed its checks and is about to call `Block.playerWillDestroy`; `native_place_block` where `BlockItem.place` has set the block and fired `CriteriaTriggers.PLACED_BLOCK`. Without a native mod breaking and placing are unchanged; CI's parity job picks the harnesses that cover `game.rs`. ## Tested in the game A throwaway local change (not in this pull request) logged both hooks and made `native_destroy_block` cancel when an environment variable was set. Fresh survival worlds on the server thread, through `horizon-ctl` (`--offscreen`): a dirt floor next to the player (`/fill`), `/give @s minecraft:dirt 4`, then `place` a dirt block and `break` it by hand: | Run | Hooks called | Place | Break | | --- | --- | --- | --- | | no cancel | `place_block minecraft:dirt`, then `destroy_block minecraft:dirt`, same position | placed, 1 dirt used | air, 1 dirt dropped | | cancel | the same | placed, 1 dirt used | still dirt, nothing dropped | A LAN guest's canceled break was not tested with a second client. ## Self-check On this commit: `cargo fmt --check` ✅, `cargo clippy -p horizon-client --bin horizon-client` ✅ (no warnings), `native_hooks::tests` ✅ 4 passed (the catalog test checks the two new entries). `tools/pr_ready.py` was not run on this one; the change has the same shape as #4302 (one call per hook in `game.rs`, empty hook points, catalog, docs). Label: `feature` (players get something new). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 05:14:03 +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#5648
No description provided.