[PR #4656] [MERGED] Native mods: a hook point for left-clicking a block (API 21) #5759

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

📋 Pull Request Information

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

Base: main ← Head: native-left-click-block-hook


📝 Commits (2)

  • 0c9b29d Native mods: a hook point for left-clicking a block (API 21)
  • fcaaed0 Merge hr/main; renumber left-click-block hook to API 30, narrow the cancel contract

📊 Changes

4 files changed (+43 additions, -1 deletions)

View changed files

📝 crates/horizon-client/src/game/lan_actions.rs (+12 -0)
📝 crates/horizon-client/src/game/native_hooks.rs (+20 -1)
📝 docs/native-mods.md (+6 -0)
📝 native-hooks.json (+5 -0)

📄 Description

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

Stacked on #4648 (API 20): review only the last commit (0c9b29d20, +41 −1).

What and why

Fixes #4654. Part of #3911 (Mods), gap B of #1854, left_click_block in the priority list of #4402: a native mod can now react when a player starts digging a block, which blocks that react to a punch, tools with a left-click action and protected areas need. native_destroy_block (API 14) sees a break only at its end; this one stops the dig before it starts, so a protected block shows no crack and plays no note. Named to pair with #4610's native_right_click_block.

  • native_left_click_block(&mut self, pos: [i32; 3], face: [i32; 3], state: BlockStateId, canceled: &mut bool): the block, the face hit ([0, 1, 0] is the top), and canceled. A mod that sets it ignores the click: the block isn't attacked (Block.attack, so a note block stays silent), dug or broken in creative.
  • Called in lan_actions.rs on a START_DESTROY_BLOCK, where ServerPlayerGameMode.handleBlockBreakAction takes a dig's start, after its reach, spawn protection and world border checks. Every player goes through it on the server (the single player server thread, LAN guests, dedicated servers), so it is authoritative; the helpers (native_player...) read the acting player. The ack already sent puts a canceled block back on the client, as spawn protection does, and with no dig recorded the STOP_DESTROY_BLOCK that follows breaks nothing.
  • Not canceled, the dig goes on exactly as before: nothing changes without a native mod.
  • NATIVE_HOOKS_API 20 → 21, its native-hooks.json entry (left_click_block, version 1), and an "API 21" paragraph in docs/native-mods.md. The number follows #4648 and moves with it.

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 (a hook point; it does nothing in Horizon). It sits in ServerPlayerGameMode.handleBlockBreakAction's START_DESTROY_BLOCK, once mayInteract and the reach check passed, before the creative destroyAndAck and before BlockState.attack. Without a native mod digging is unchanged; CI's parity job picks the harnesses that cover lan_actions.rs.

Tested in the game

A throwaway local change (not in this pull request) logged the hook and canceled when an environment variable was set. Fresh worlds on the server thread, through horizon-ctl (--offscreen): a dirt block next to the player (/setblock), then break it, holding the attack button up to 3 s:

Run Mode Hook called Block after
no cancel survival once, minecraft:dirt, face [0, 1, 0] air, 1 dirt dropped
no cancel creative once air
cancel survival once dirt
cancel creative once dirt

Self-check

On this commit: cargo fmt --check ✅, cargo clippy -p horizon-client --bin horizon-client ✅ (no warnings), native_hooks::tests ✅ 6 passed (the catalog test checks the new entry). tools/pr_ready.py was not run.

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/4656 **Author:** [@ludovicthenot](https://github.com/ludovicthenot) **Created:** 10/30/2026 **Status:** ✅ Merged **Merged:** 10/31/2026 **Merged by:** [@levzzz5154](https://github.com/levzzz5154) **Base:** `main` ← **Head:** `native-left-click-block-hook` --- ### 📝 Commits (2) - [`0c9b29d`](https://github.com/horizon-rust/horizon/commit/0c9b29d20a06248fde3e1cb10e5a9bed8a6b3d9d) Native mods: a hook point for left-clicking a block (API 21) - [`fcaaed0`](https://github.com/horizon-rust/horizon/commit/fcaaed088b81f3878d674815dcd759058fa90e7a) Merge hr/main; renumber left-click-block hook to API 30, narrow the cancel contract ### 📊 Changes **4 files changed** (+43 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game/lan_actions.rs` (+12 -0) 📝 `crates/horizon-client/src/game/native_hooks.rs` (+20 -1) 📝 `docs/native-mods.md` (+6 -0) 📝 `native-hooks.json` (+5 -0) </details> ### 📄 Description > 🤖 Opened by ludovicthenot's AI agent (Claude Code, Claude Opus 5.5), not by ludovicthenot personally. **Stacked on #4648 (API 20): review only the last commit** (`0c9b29d20`, +41 −1). ## What and why Fixes #4654. Part of #3911 (Mods), gap **B** of #1854, `left_click_block` in the priority list of #4402: a native mod can now react when a player starts digging a block, which blocks that react to a punch, tools with a left-click action and protected areas need. `native_destroy_block` (API 14) sees a break only at its end; this one stops the dig before it starts, so a protected block shows no crack and plays no note. Named to pair with #4610's `native_right_click_block`. - **`native_left_click_block(&mut self, pos: [i32; 3], face: [i32; 3], state: BlockStateId, canceled: &mut bool)`**: the block, the face hit (`[0, 1, 0]` is the top), and `canceled`. A mod that sets it ignores the click: the block isn't attacked (`Block.attack`, so a note block stays silent), dug or broken in creative. - Called in `lan_actions.rs` on a `START_DESTROY_BLOCK`, where `ServerPlayerGameMode.handleBlockBreakAction` takes a dig's start, after its reach, spawn protection and world border checks. Every player goes through it on the server (the single player server thread, LAN guests, dedicated servers), so it is authoritative; the helpers (`native_player`...) read the acting player. The ack already sent puts a canceled block back on the client, as spawn protection does, and with no dig recorded the `STOP_DESTROY_BLOCK` that follows breaks nothing. - Not canceled, the dig goes on exactly as before: nothing changes without a native mod. - `NATIVE_HOOKS_API` 20 → 21, its `native-hooks.json` entry (`left_click_block`, version 1), and an "API 21" paragraph in `docs/native-mods.md`. The number follows #4648 and moves with it. ## 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 (a hook point; it does nothing in Horizon). It sits in `ServerPlayerGameMode.handleBlockBreakAction`'s `START_DESTROY_BLOCK`, once `mayInteract` and the reach check passed, before the creative `destroyAndAck` and before `BlockState.attack`. Without a native mod digging is unchanged; CI's parity job picks the harnesses that cover `lan_actions.rs`. ## Tested in the game A throwaway local change (not in this pull request) logged the hook and canceled when an environment variable was set. Fresh worlds on the server thread, through `horizon-ctl` (`--offscreen`): a dirt block next to the player (`/setblock`), then `break` it, holding the attack button up to 3 s: | Run | Mode | Hook called | Block after | | --- | --- | --- | --- | | no cancel | survival | once, `minecraft:dirt`, face `[0, 1, 0]` | air, 1 dirt dropped | | no cancel | creative | once | air | | cancel | survival | once | dirt | | cancel | creative | once | dirt | ## Self-check On this commit: `cargo fmt --check` ✅, `cargo clippy -p horizon-client --bin horizon-client` ✅ (no warnings), `native_hooks::tests` ✅ 6 passed (the catalog test checks the new entry). `tools/pr_ready.py` was not run. 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:47 +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#5759
No description provided.