[GH-ISSUE #4474] Native mods: hook points for breaking and placing a block #1344

Closed
opened 2026-11-02 15:46:11 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @ludovicthenot on GitHub (Oct 30, 2026).
Original GitHub issue: https://github.com/horizon-rust/horizon/issues/4474

Originally assigned to: @ludovicthenot on GitHub.

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

Part of #3911 (Mods). Gap B of #1854 (block behaviour hooks, 71 of the 307 code mods ranked there), first in the priority list of #4402: today a native mod can't react when a player breaks or places a block. Protected blocks, tools that break more than one block, extra drops and blocks that do something when placed all need it.

Proposal

Two hook points in crates/horizon-client/src/game/native_hooks.rs, named after the vanilla call they sit in, like #4302:

/// 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).
/// Set `canceled` to keep the block: nothing is destroyed or dropped.
pub(super) fn native_destroy_block(&mut self, pos: [i32; 3], state: BlockStateId, canceled: &mut bool)

/// A player placed `stack` as the block `state` at `pos`. To stop a
/// placement, claim `native_use_item_on`, which runs before it.
pub(super) fn native_place_block(&mut self, stack: &ItemStack, pos: [i32; 3], state: BlockStateId)
  • native_destroy_block: in break_block_as_player (game.rs), where ServerPlayerGameMode.destroyBlock starts, after its checks and before Block.playerWillDestroy. Every player goes through it on the server (the integrated server thread, LAN guests through guest_destroy, dedicated servers), so it is authoritative; the helpers (native_player...) read the acting player.
  • native_place_block: in use_hand, where BlockItem.place has set the block (the point of the placed_block trigger). It only hears: native_use_item_on (#4302) already lets a mod stop the click before anything is placed, so placing needs no second way to cancel.
  • To check while building it: a guest whose break is canceled sees its block again (the server sends the block back, as when the item can't break it).
  • Nothing changes without a native mod: not canceled, the break goes on as now.
  • NATIVE_HOOKS_API + 1, its native-hooks.json entries, docs/native-mods.md.

Stacked on #4302 (API 5), so this is API 6, or whatever number is free at merge if #4402 settles that.

Originally created by @ludovicthenot on GitHub (Oct 30, 2026). Original GitHub issue: https://github.com/horizon-rust/horizon/issues/4474 Originally assigned to: @ludovicthenot on GitHub. > 🤖 Filed by ludovicthenot's AI agent (Claude Code, Claude Opus 5.5), not by ludovicthenot personally. Part of #3911 (Mods). Gap **B** of #1854 (block behaviour hooks, 71 of the 307 code mods ranked there), first in the priority list of #4402: today a native mod can't react when a player breaks or places a block. Protected blocks, tools that break more than one block, extra drops and blocks that do something when placed all need it. ## Proposal Two hook points in `crates/horizon-client/src/game/native_hooks.rs`, named after the vanilla call they sit in, like #4302: ```rust /// 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). /// Set `canceled` to keep the block: nothing is destroyed or dropped. pub(super) fn native_destroy_block(&mut self, pos: [i32; 3], state: BlockStateId, canceled: &mut bool) /// A player placed `stack` as the block `state` at `pos`. To stop a /// placement, claim `native_use_item_on`, which runs before it. pub(super) fn native_place_block(&mut self, stack: &ItemStack, pos: [i32; 3], state: BlockStateId) ``` - `native_destroy_block`: in `break_block_as_player` (game.rs), where `ServerPlayerGameMode.destroyBlock` starts, after its checks and before `Block.playerWillDestroy`. Every player goes through it on the server (the integrated server thread, LAN guests through `guest_destroy`, dedicated servers), so it is authoritative; the helpers (`native_player`...) read the acting player. - `native_place_block`: in `use_hand`, where `BlockItem.place` has set the block (the point of the `placed_block` trigger). It only hears: `native_use_item_on` (#4302) already lets a mod stop the click before anything is placed, so placing needs no second way to cancel. - To check while building it: a guest whose break is canceled sees its block again (the server sends the block back, as when the item can't break it). - Nothing changes without a native mod: not canceled, the break goes on as now. - `NATIVE_HOOKS_API` + 1, its `native-hooks.json` entries, docs/native-mods.md. Stacked on #4302 (API 5), so this is API 6, or whatever number is free at merge if #4402 settles that.
Author
Owner

@ludovicthenot commented on GitHub (Oct 30, 2026):

🤖 Agent: /claim

<!-- gh-comment-id:6526574920 --> @ludovicthenot commented on GitHub (Oct 30, 2026): 🤖 Agent: /claim
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#1344
No description provided.