[PR #4610] [MERGED] Native mods: right click on a block, the acting player, server commands (API 21) #5725

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

📋 Pull Request Information

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

Base: main ← Head: feat/smp-claim-hooks


📝 Commits (5)

  • 1de9f9f Native mods: right click on a block, the acting player, server commands (API 15)
  • e021395 Native mods: native_action_bar, which reaches the acting player in their hook
  • bf29bd9 Merge main: block entities took API 15, these hooks are API 16
  • cf6e5c2 Merge main: mod inventories and menus took API 16 and 17, these hooks are API 18
  • c0f09fe Merge main: mod screens took API 18 to 20, these hooks are API 21

📊 Changes

6 files changed (+117 additions, -3 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+9 -0)
📝 crates/horizon-client/src/game/native_hooks.rs (+21 -1)
📝 crates/horizon-client/src/game/native_server.rs (+62 -1)
📝 docs/native-mods.md (+19 -0)
📝 docs/smp.md (+1 -1)
📝 native-hooks.json (+5 -0)

📄 Description

🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself.

What and why

Phase 4 of the SMP (docs/smp.md): land claims and teleports for the official server's native mod, built on #4302 (item use, API 13) and #4483 (block breaking, API 14), named as #4402 proposes. A stock client is all players need. Five additions, API 20 → 21 (contributors' mod block entities, inventories, menus and screens took 15 to 20 while this was open):

  • native_right_click_block(pos, face, canceled): a player's right click on a block, where ServerPlayerGameMode.useItemOn starts. It runs before the block's own use (a chest, a door, a lever) and before native_use_item_on, once per hand. A mod that sets canceled stops both, with no swing. A guest gets the block (and the one beside the clicked face) sent back, through the corrections UseItemOn already sends. #4302's native_use_item_on runs only once the block let the click through, so a chest still opens; this one is what a claim needs.
  • native_acting_player(): who acts inside a player's hook (UUID, name, level, position, dimension, game mode, health), built from the swap (lan_acting_*). The block hooks had no way to tell a claim's owner from anyone else.
  • native_run_command(line): a command run as the server's console (level 4, silent source at the overworld's spawn), refused inside a player's swap. execute in minecraft:the_nether run tp Alex 0 70 0 moves a player across levels through the existing level_teleports, so no new teleport code is needed.
  • native_action_bar(uuid, text): a line over a player's hotbar. It also reaches the acting player inside their own hook, where native_tell reaches nobody because the host is out of self.lan during the swap. A claim says why a click was refused this way.
  • health on NativeServerPlayer: a teleport's warmup is called off when it drops. No damage hook is needed for that.

Without a native mod nothing changes: the hook is an empty function and the helpers are unused (#[allow(dead_code)], as the others are).

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. native_right_click_block sits at the top of use_hand's block section, where ServerPlayerGameMode.useItemOn starts. native_run_command is DedicatedServer.handleConsoleInputs' path (as_console → run_command) with a silent source.

Tested in the game

The SMP mod's places (horizon-rust/horizon-mods, feat/smp-places) were built on this commit with native.py proof smp: a real dedicated server and two horizon-ctl clients, on fresh mktemp data.

  • /home from the Nether's roof landed Steve back in the overworld at his home (execute in … run tp).
  • Walking during the warmup called it off ("you moved"), and so did /damage Steve 2 ("you were hurt", read from health).
  • /tpa + /tpaccept put Alex on Steve.
  • An operator-only /setwarp was refused to a level 0 player.

The rest of the SMP proof (economy, trades, coinflip, lottery) passed in the same run. The claims, which use native_right_click_block and native_acting_player, come next in the mod with their own proof.

Self-check

On the first merge with main (bf29bd9; later merges of main, conflicts only in the API lines), tools/pr_ready.py --quick:

Check Result
Scope ✅ 6 files, +117 −3
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 481 passed (1 min 39 s)
rustfmt ✅ (4 s)
clippy ✅ (1 min 39 s)
tests: horizon-client ✅ 1087 passed (4 min 47 s)
doc tests ✅ 0 passed (2 s)
content root tests ➖ content root untouched
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ➖ 30 affected, to run in CI (--quick): block_removal, command_exec, composter, crafter, cursor_death, dedicated_server, dispenser, forced_end, friends_integration, hardcore_respawn, lan_integration, locator_bar and 18 more
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

CI skips PR parity when no harness changes. So the affected harnesses ran locally on cf6e5c2 with tools/parity.py --changed origin/main: 31 passed, 1 failed in 48.7 min.

  • They include use_item_on, block_removal, command_exec, dedicated_server, online_mode, forced_end, dispenser, crafter, mace and sculk.
  • friends_integration failed once with reused oracle results, then passed on its retry.
  • lunge_motion fails on main's own code too (c822f6e, with this branch's changes taken out), and its diff moves between runs (vanilla 0.0831 vs Horizon 0.1648; a falling line that differs in one run and not the next). It is not this change, which only calls an empty hook before a block is used.

Label: feature.

🤖 Generated with Claude Code


🔄 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/4610 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/30/2026 **Status:** ✅ Merged **Merged:** 10/30/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `feat/smp-claim-hooks` --- ### 📝 Commits (5) - [`1de9f9f`](https://github.com/horizon-rust/horizon/commit/1de9f9fc690ff074abc1dc3d6d9344f212f84416) Native mods: right click on a block, the acting player, server commands (API 15) - [`e021395`](https://github.com/horizon-rust/horizon/commit/e0213952104aa9145ce86c0a3feb272f5f1807a2) Native mods: native_action_bar, which reaches the acting player in their hook - [`bf29bd9`](https://github.com/horizon-rust/horizon/commit/bf29bd9166a1c627b347ef60f7e9172ba0b152cd) Merge main: block entities took API 15, these hooks are API 16 - [`cf6e5c2`](https://github.com/horizon-rust/horizon/commit/cf6e5c2474206eb697dfc6b2913878b36f7762e0) Merge main: mod inventories and menus took API 16 and 17, these hooks are API 18 - [`c0f09fe`](https://github.com/horizon-rust/horizon/commit/c0f09fed88c21b69865614daf1a1fc582af45646) Merge main: mod screens took API 18 to 20, these hooks are API 21 ### 📊 Changes **6 files changed** (+117 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+9 -0) 📝 `crates/horizon-client/src/game/native_hooks.rs` (+21 -1) 📝 `crates/horizon-client/src/game/native_server.rs` (+62 -1) 📝 `docs/native-mods.md` (+19 -0) 📝 `docs/smp.md` (+1 -1) 📝 `native-hooks.json` (+5 -0) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. ## What and why Phase 4 of the SMP ([docs/smp.md](docs/smp.md)): land claims and teleports for the official server's native mod, built on #4302 (item use, API 13) and #4483 (block breaking, API 14), named as #4402 proposes. A stock client is all players need. Five additions, API 20 → 21 (contributors' mod block entities, inventories, menus and screens took 15 to 20 while this was open): - **`native_right_click_block(pos, face, canceled)`**: a player's right click on a block, where `ServerPlayerGameMode.useItemOn` starts. It runs before the block's own use (a chest, a door, a lever) and before `native_use_item_on`, once per hand. A mod that sets `canceled` stops both, with no swing. A guest gets the block (and the one beside the clicked face) sent back, through the corrections `UseItemOn` already sends. `#4302`'s `native_use_item_on` runs only once the block let the click through, so a chest still opens; this one is what a claim needs. - **`native_acting_player()`**: who acts inside a player's hook (UUID, name, level, position, dimension, game mode, health), built from the swap (`lan_acting_*`). The block hooks had no way to tell a claim's owner from anyone else. - **`native_run_command(line)`**: a command run as the server's console (level 4, silent source at the overworld's spawn), refused inside a player's swap. `execute in minecraft:the_nether run tp Alex 0 70 0` moves a player across levels through the existing `level_teleports`, so no new teleport code is needed. - **`native_action_bar(uuid, text)`**: a line over a player's hotbar. It also reaches the acting player inside their own hook, where `native_tell` reaches nobody because the host is out of `self.lan` during the swap. A claim says why a click was refused this way. - **`health`** on `NativeServerPlayer`: a teleport's warmup is called off when it drops. No damage hook is needed for that. Without a native mod nothing changes: the hook is an empty function and the helpers are unused (`#[allow(dead_code)]`, as the others are). ## 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. `native_right_click_block` sits at the top of `use_hand`'s block section, where `ServerPlayerGameMode.useItemOn` starts. `native_run_command` is `DedicatedServer.handleConsoleInputs`' path (`as_console` → `run_command`) with a silent source. ## Tested in the game The SMP mod's places (horizon-rust/horizon-mods, `feat/smp-places`) were built on this commit with `native.py proof smp`: a real dedicated server and two `horizon-ctl` clients, on fresh `mktemp` data. - `/home` from the Nether's roof landed Steve back in the overworld at his home (`execute in … run tp`). - Walking during the warmup called it off ("you moved"), and so did `/damage Steve 2` ("you were hurt", read from `health`). - `/tpa` + `/tpaccept` put Alex on Steve. - An operator-only `/setwarp` was refused to a level 0 player. The rest of the SMP proof (economy, trades, coinflip, lottery) passed in the same run. The claims, which use `native_right_click_block` and `native_acting_player`, come next in the mod with their own proof. ## Self-check On the first merge with main (`bf29bd9`; later merges of main, conflicts only in the API lines), `tools/pr_ready.py --quick`: | Check | Result | | --- | --- | | Scope | ✅ 6 files, +117 −3 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 481 passed (1 min 39 s) | | rustfmt | ✅ (4 s) | | clippy | ✅ (1 min 39 s) | | tests: horizon-client | ✅ 1087 passed (4 min 47 s) | | doc tests | ✅ 0 passed (2 s) | | content root tests | ➖ content root untouched | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ 30 affected, to run in CI (--quick): block_removal, command_exec, composter, crafter, cursor_death, dedicated_server, dispenser, forced_end, friends_integration, hardcore_respawn, lan_integration, locator_bar and 18 more | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | CI skips PR parity when no harness changes. So the affected harnesses ran locally on `cf6e5c2` with `tools/parity.py --changed origin/main`: **31 passed, 1 failed** in 48.7 min. - They include `use_item_on`, `block_removal`, `command_exec`, `dedicated_server`, `online_mode`, `forced_end`, `dispenser`, `crafter`, `mace` and `sculk`. - `friends_integration` failed once with reused oracle results, then passed on its retry. - `lunge_motion` fails on main's own code too (`c822f6e`, with this branch's changes taken out), and its diff moves between runs (vanilla `0.0831` vs Horizon `0.1648`; a `falling` line that differs in one run and not the next). It is not this change, which only calls an empty hook before a block is used. Label: `feature`. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <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:35 +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#5725
No description provided.