[PR #4669] [MERGED] Native mods: mod messages and event hook points (API next) #5769

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

📋 Pull Request Information

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

Base: main ← Head: hooks-clean


📝 Commits (5)

  • 25950c6 Native mods: mod messages and event hook points (API 21)
  • 6830f20 Merge main; mod messages and event hooks are API 22
  • 4b8f735 Say which mobs native_mob_spawned reports as not natural
  • fe4b750 Merge main; mod messages and event hooks are API 23
  • 97b2e10 Merge hr/main; renumber mod messages and event hooks to API 40; not-joined error first, send allowance per server tick, sweep and spear kills

📊 Changes

24 files changed (+545 additions, -3 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+14 -0)
📝 crates/horizon-client/src/game/chat.rs (+2 -0)
📝 crates/horizon-client/src/game/commands/data.rs (+4 -1)
📝 crates/horizon-client/src/game/creatures.rs (+3 -0)
📝 crates/horizon-client/src/game/dispenser.rs (+1 -0)
📝 crates/horizon-client/src/game/golems.rs (+1 -0)
📝 crates/horizon-client/src/game/lan.rs (+9 -0)
📝 crates/horizon-client/src/game/lan_actions.rs (+8 -0)
📝 crates/horizon-client/src/game/mace.rs (+4 -0)
📝 crates/horizon-client/src/game/native_hooks.rs (+98 -1)
➕ crates/horizon-client/src/game/native_net.rs (+164 -0)
📝 crates/horizon-client/src/game/natural_spawning.rs (+1 -0)
📝 crates/horizon-client/src/game/raids.rs (+1 -0)
📝 crates/horizon-client/src/game/remote.rs (+14 -1)
📝 crates/horizon-client/src/game/sculk.rs (+1 -0)
📝 crates/horizon-client/src/game/spawner.rs (+1 -0)
📝 crates/horizon-client/src/game/spear.rs (+3 -0)
📝 crates/horizon-client/src/game/villagers.rs (+1 -0)
📝 crates/horizon-client/src/lan/conn.rs (+8 -0)
📝 crates/horizon-client/src/net.rs (+4 -0)

...and 4 more files

📄 Description

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

What and why

Fixes #4668. Part of #3911 (Mods). This replaces the closed #4538: after levzzz5154 asked for hooks only, it keeps the hook points and leaves out the runtime, the SDK and the examples.

A native mod's server half and client half can now exchange data, and a server mod can hear player deaths, new mobs, kills, drops and pickups.

Mod messages (game/native_net.rs, horizon-protocol/src/mod_net.rs):

  • native_net_send_to_player(player, channel, data) and native_net_send_to_server(channel, data) send, on one horizon:mod_net custom payload. native_net_from_client(player, channel, data) and native_net_from_server(channel, data) hear.
  • The channel is mod_id:name; minecraft and horizon are refused. Data is at most 30 000 bytes, and 32 messages a tick go each way per player.
  • A server announces the channel during configuration, as it does for quiet commands. Only clients with the Horizon brand are sent messages. Sending to the server is an error until the player has joined, because a play packet sent during configuration is lost.
  • The hub is out of the game while a guest's packet or turn runs, so both directions queue: a player's message reaches the hook once the hub is back, and a message to a player leaves at the tick's end, from any server hook.

Events (all server-side, a player named by UUID):

Hook Where it fires Answer
native_player_died(player, cause) where ServerPlayer.die starts, whether death messages are shown or not none
native_mob_spawned(dimension, kind, pos, natural) a new mob joined. natural is true for the world's own spawning; false for a breed, raid, spawner, conversion or /summon. Not for a mob loaded with its chunk, leaving a hive or changing level none
native_mob_killed(player, entity, kind) a player's melee blow killed a mob; other deaths aren't told yet none
native_item_dropped(player, item, count) Player.drop none
native_item_picked_up(player, item, count, canceled) ItemEntity.playerTouch canceled leaves the stack on the ground; it isn't offered again for 10 ticks

NATIVE_HOOKS_API goes to the next free number: 23 in the code on this base. The title says "API next", as #4402 proposes, because the number moves with whatever merges first. The native-hooks.json entries and docs/native-mods.md are included.

Left out on purpose: right-clicking an entity (#4648 does it better), damage (reservedbytes, on #4402), particles and block breaking (already merged), and sounds (#4574). Helpers that need stored state (mobs a mod owns, displays, redstone output, fluids) aren't here: they need separate pull requests.

Size: about 510 lines of code by pr_ready, slightly over the limit, including the protocol file's tests. The messages and the events could ship as two pull requests if that's easier to review.

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 do nothing in Horizon. They sit at ServerPlayer.die, Player.attack, Player.drop and ItemEntity.playerTouch, and where mobs are added to the level. Without a native mod, the only changes are one more custom payload announced to Horizon clients and the same gameplay. CI's parity job picks the harnesses for these files; I didn't run parity here (no vanilla data on this machine).

Tested in the game

A throwaway horizon-mixins bundle (not in this pull request) hooked all seven and logged each call, applied with horizon-mixins apply and built with --profile fast. Worlds on the single player server thread, driven through horizon-ctl, on Windows with an RTX 5070:

Check Result
Client sends hookproof:ping once joined, server answers from the hook net_from_client got ping, net_from_server got pong
World spawning, then /summon with and without data natural=true, then natural=false for both
/summon with a passenger one natural=false event for each mob, no duplicates
A natural jockey (seen in the log) the first mob natural=true, its mount natural=false
Melee kill of a pig mob_killed once, with its id and kind
Throw stone, walk onto it item_dropped, item_picked_up, stone back in the inventory
Throw dirt with the hook canceling item_dropped, then canceled=true every 10 ticks; dirt stays on the ground
/kill with show_death_messages on, then off player_died both times, cause=death.attack.genericKill

No errors in the log. On a dedicated server with two real clients: --dedicated --nogui and two Horizon clients (Alex, Steve) under horizon-ctl --offscreen, over TCP on localhost, on Windows, with a throwaway bundle hooking all of this. It ran on a local merge of #4669, #4677 and #4725 with main, not on this branch alone; all 56 checks passed.

Check Result
Each client sends a message the server hears each with the right UUID, and each client gets only its own answer
A bad channel, horizon:mod_net, 30 001 bytes refused
40 sends in one tick at most 32 accepted; the server hears them and drops none it accepted
A message to a player who left accepted, with no trouble; the other player keeps getting theirs, and the one who left gets them again after rejoining
Console /summon, also with a passenger one natural=false event a mob
Each player kills a mob by melee mob_killed names that player's UUID only
Alex throws stone, Steve takes it item_dropped names Alex, item_picked_up names Steve, and each client's count is right
A canceled pickup offered about every 10 ticks; the stack stays on the ground
/kill each player, with death messages on, then off player_died once, naming only that player

Not tested: a vanilla client beside a Horizon one, a client refused for sending before it joined (on a dedicated server the first tick comes after joining, and that message arrives), and a real mod using these hooks.

Self-check

tools/pr_ready.py --quick --base origin/main on Windows, on this branch.

horizon-client doesn't currently build on Windows on main, because #4732 added unsafe to save.rs under #![forbid(unsafe_code)], so I ran this and the game with that one line relaxed locally. It isn't in this pull request, and the table counts it.

pr_ready (tools/pr_ready.py --quick on DESKTOP-H7P5E7K, against origin/main at 672b204c0, 3 min 46 s)

Check Result
Scope ⚠️ 23 files, +530 −4; 514 lines of code: over 500, split it if it can ship in parts
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 481 passed (1 min 25 s)
rustfmt ✅ (8 s)
clippy ✅ (37 s)
tests: horizon-client, horizon-protocol ✅ 1349 passed (1 min 29 s)
doc tests ✅ 0 passed (1 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 ➖ not run (--quick): CI's parity job picks the affected harnesses
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

🤖 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/4669 **Author:** [@Qwerner88880](https://github.com/Qwerner88880) **Created:** 10/30/2026 **Status:** ✅ Merged **Merged:** 10/31/2026 **Merged by:** [@levzzz5154](https://github.com/levzzz5154) **Base:** `main` ← **Head:** `hooks-clean` --- ### 📝 Commits (5) - [`25950c6`](https://github.com/horizon-rust/horizon/commit/25950c64ad7ad20264c553707023c6e7b4dd8576) Native mods: mod messages and event hook points (API 21) - [`6830f20`](https://github.com/horizon-rust/horizon/commit/6830f201d5544596f2421564c7fdf2de5db8fb29) Merge main; mod messages and event hooks are API 22 - [`4b8f735`](https://github.com/horizon-rust/horizon/commit/4b8f735c7b55c226a2378faf34832b0703add266) Say which mobs native_mob_spawned reports as not natural - [`fe4b750`](https://github.com/horizon-rust/horizon/commit/fe4b7508274c4b3020b2049aec72760122ce7da4) Merge main; mod messages and event hooks are API 23 - [`97b2e10`](https://github.com/horizon-rust/horizon/commit/97b2e10df57f5d9e75dbe710c7a8ba62cccb8155) Merge hr/main; renumber mod messages and event hooks to API 40; not-joined error first, send allowance per server tick, sweep and spear kills ### 📊 Changes **24 files changed** (+545 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+14 -0) 📝 `crates/horizon-client/src/game/chat.rs` (+2 -0) 📝 `crates/horizon-client/src/game/commands/data.rs` (+4 -1) 📝 `crates/horizon-client/src/game/creatures.rs` (+3 -0) 📝 `crates/horizon-client/src/game/dispenser.rs` (+1 -0) 📝 `crates/horizon-client/src/game/golems.rs` (+1 -0) 📝 `crates/horizon-client/src/game/lan.rs` (+9 -0) 📝 `crates/horizon-client/src/game/lan_actions.rs` (+8 -0) 📝 `crates/horizon-client/src/game/mace.rs` (+4 -0) 📝 `crates/horizon-client/src/game/native_hooks.rs` (+98 -1) ➕ `crates/horizon-client/src/game/native_net.rs` (+164 -0) 📝 `crates/horizon-client/src/game/natural_spawning.rs` (+1 -0) 📝 `crates/horizon-client/src/game/raids.rs` (+1 -0) 📝 `crates/horizon-client/src/game/remote.rs` (+14 -1) 📝 `crates/horizon-client/src/game/sculk.rs` (+1 -0) 📝 `crates/horizon-client/src/game/spawner.rs` (+1 -0) 📝 `crates/horizon-client/src/game/spear.rs` (+3 -0) 📝 `crates/horizon-client/src/game/villagers.rs` (+1 -0) 📝 `crates/horizon-client/src/lan/conn.rs` (+8 -0) 📝 `crates/horizon-client/src/net.rs` (+4 -0) _...and 4 more files_ </details> ### 📄 Description > 🤖 Opened by Qwerner88880's AI agent (Claude Code, Claude Opus 5.5), not by Qwerner88880 personally. ## What and why Fixes #4668. Part of #3911 (Mods). This replaces the closed #4538: after levzzz5154 asked for hooks only, it keeps the hook points and leaves out the runtime, the SDK and the examples. A native mod's server half and client half can now exchange data, and a server mod can hear player deaths, new mobs, kills, drops and pickups. **Mod messages** (`game/native_net.rs`, `horizon-protocol/src/mod_net.rs`): - `native_net_send_to_player(player, channel, data)` and `native_net_send_to_server(channel, data)` send, on one `horizon:mod_net` custom payload. `native_net_from_client(player, channel, data)` and `native_net_from_server(channel, data)` hear. - The channel is `mod_id:name`; `minecraft` and `horizon` are refused. Data is at most 30 000 bytes, and 32 messages a tick go each way per player. - A server announces the channel during configuration, as it does for quiet commands. Only clients with the Horizon brand are sent messages. Sending to the server is an error until the player has joined, because a play packet sent during configuration is lost. - The hub is out of the game while a guest's packet or turn runs, so both directions queue: a player's message reaches the hook once the hub is back, and a message to a player leaves at the tick's end, from any server hook. **Events** (all server-side, a player named by UUID): | Hook | Where it fires | Answer | |---|---|---| | `native_player_died(player, cause)` | where `ServerPlayer.die` starts, whether death messages are shown or not | none | | `native_mob_spawned(dimension, kind, pos, natural)` | a new mob joined. `natural` is true for the world's own spawning; false for a breed, raid, spawner, conversion or `/summon`. Not for a mob loaded with its chunk, leaving a hive or changing level | none | | `native_mob_killed(player, entity, kind)` | a player's melee blow killed a mob; other deaths aren't told yet | none | | `native_item_dropped(player, item, count)` | `Player.drop` | none | | `native_item_picked_up(player, item, count, canceled)` | `ItemEntity.playerTouch` | `canceled` leaves the stack on the ground; it isn't offered again for 10 ticks | `NATIVE_HOOKS_API` goes to the next free number: 23 in the code on this base. The title says "API next", as #4402 proposes, because the number moves with whatever merges first. The `native-hooks.json` entries and `docs/native-mods.md` are included. **Left out on purpose:** right-clicking an entity (#4648 does it better), damage (reservedbytes, on #4402), particles and block breaking (already merged), and sounds (#4574). Helpers that need stored state (mobs a mod owns, displays, redstone output, fluids) aren't here: they need separate pull requests. **Size:** about 510 lines of code by `pr_ready`, slightly over the limit, including the protocol file's tests. The messages and the events could ship as two pull requests if that's easier to review. ## 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 do nothing in Horizon. They sit at `ServerPlayer.die`, `Player.attack`, `Player.drop` and `ItemEntity.playerTouch`, and where mobs are added to the level. Without a native mod, the only changes are one more custom payload announced to Horizon clients and the same gameplay. CI's parity job picks the harnesses for these files; I didn't run parity here (no vanilla data on this machine). ## Tested in the game A throwaway horizon-mixins bundle (not in this pull request) hooked all seven and logged each call, applied with `horizon-mixins apply` and built with `--profile fast`. Worlds on the single player server thread, driven through `horizon-ctl`, on Windows with an RTX 5070: | Check | Result | | --- | --- | | Client sends `hookproof:ping` once joined, server answers from the hook | `net_from_client` got `ping`, `net_from_server` got `pong` | | World spawning, then `/summon` with and without data | `natural=true`, then `natural=false` for both | | `/summon` with a passenger | one `natural=false` event for each mob, no duplicates | | A natural jockey (seen in the log) | the first mob `natural=true`, its mount `natural=false` | | Melee kill of a pig | `mob_killed` once, with its id and kind | | Throw stone, walk onto it | `item_dropped`, `item_picked_up`, stone back in the inventory | | Throw dirt with the hook canceling | `item_dropped`, then `canceled=true` every 10 ticks; dirt stays on the ground | | `/kill` with `show_death_messages` on, then off | `player_died` both times, `cause=death.attack.genericKill` | No errors in the log. **On a dedicated server with two real clients:** `--dedicated --nogui` and two Horizon clients (Alex, Steve) under `horizon-ctl --offscreen`, over TCP on localhost, on Windows, with a throwaway bundle hooking all of this. It ran on a local merge of #4669, #4677 and #4725 with main, not on this branch alone; all 56 checks passed. | Check | Result | | --- | --- | | Each client sends a message | the server hears each with the right UUID, and each client gets only its own answer | | A bad channel, `horizon:mod_net`, 30 001 bytes | refused | | 40 sends in one tick | at most 32 accepted; the server hears them and drops none it accepted | | A message to a player who left | accepted, with no trouble; the other player keeps getting theirs, and the one who left gets them again after rejoining | | Console `/summon`, also with a passenger | one `natural=false` event a mob | | Each player kills a mob by melee | `mob_killed` names that player's UUID only | | Alex throws stone, Steve takes it | `item_dropped` names Alex, `item_picked_up` names Steve, and each client's count is right | | A canceled pickup | offered about every 10 ticks; the stack stays on the ground | | `/kill` each player, with death messages on, then off | `player_died` once, naming only that player | **Not tested:** a vanilla client beside a Horizon one, a client refused for sending before it joined (on a dedicated server the first tick comes after joining, and that message arrives), and a real mod using these hooks. ## Self-check `tools/pr_ready.py --quick --base origin/main` on Windows, on this branch. `horizon-client` doesn't currently build on Windows on main, because #4732 added `unsafe` to `save.rs` under `#![forbid(unsafe_code)]`, so I ran this and the game with that one line relaxed locally. It isn't in this pull request, and the table counts it. **pr_ready** (`tools/pr_ready.py --quick` on DESKTOP-H7P5E7K, against origin/main at 672b204c0, 3 min 46 s) | Check | Result | | --- | --- | | Scope | ⚠️ 23 files, +530 −4; 514 lines of code: over 500, split it if it can ship in parts | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 481 passed (1 min 25 s) | | rustfmt | ✅ (8 s) | | clippy | ✅ (37 s) | | tests: horizon-client, horizon-protocol | ✅ 1349 passed (1 min 29 s) | | doc tests | ✅ 0 passed (1 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 | ➖ not run (--quick): CI's parity job picks the affected harnesses | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | 🤖 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:52 +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#5769
No description provided.