[PR #6281] [MERGED] Native mods: an entity mounting or dismounting, EntityMountEvent #6765

Closed
opened 2026-11-03 06:26:17 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/6281
Author: @levzzz5154
Created: 11/1/2026
Status: ✅ Merged
Merged: 11/1/2026
Merged by: @levzzz5154

Base: main ← Head: mods/entity-mount


📝 Commits (1)

  • 0b4fdee Native mods: an entity mounting or dismounting a vehicle, EntityMountEvent

📊 Changes

13 files changed (+203 additions, -7 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+1 -0)
📝 crates/horizon-client/src/game/boats.rs (+7 -0)
📝 crates/horizon-client/src/game/commands/world_cmds.rs (+21 -4)
📝 crates/horizon-client/src/game/cushions.rs (+6 -0)
📝 crates/horizon-client/src/game/ghasts.rs (+3 -0)
📝 crates/horizon-client/src/game/llamas.rs (+3 -0)
📝 crates/horizon-client/src/game/minecarts.rs (+8 -1)
📝 crates/horizon-client/src/game/mounts.rs (+14 -2)
📝 crates/horizon-client/src/game/native_hooks.rs (+34 -0)
➕ crates/horizon-client/src/game/native_mounts.rs (+82 -0)
📝 crates/horizon-client/src/game/nautili.rs (+3 -0)
📝 crates/horizon-client/src/game/passengers.rs (+8 -0)
➕ tools/native-hook-fragments/entity_mount.json (+13 -0)

📄 Description

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

What and why

Fixes #6273, part of #4953 ("Entity: tick, mount, size, projectile impact"). A native mod that keeps players out of a vehicle (or in it), or reacts to a mob being seated, had no hook: nothing told it an entity was about to get on or off a vehicle and nothing let it say no.

One server hook point, API from a fragment (tools/native-hook-fragments/entity_mount.json):

  • native_entity_mount(dimension, entity, kind, vehicle, vehicle_kind, mounting, canceled) (EntityMountEvent): ids and types of the rider (minecraft:player, minecraft:zombie) and the vehicle (minecraft:oak_boat, minecraft:horse, minecraft:cushion), mounting true to board and false to leave. Set canceled and the rider does not board, or keeps riding; a canceled /ride fails with vanilla's "couldn't start riding".

Where. Horizon has no one startRiding; each vehicle keeps its rider state itself, so the hook is asked at each seat/unseat site, before the state changes (game/native_mounts.rs has the helpers native_may_board, native_may_leave, native_mob_may_ride):

  • Player boarding: boats, minecarts, cushions, saddled pigs and striders (mounts.rs), horses and kin, llamas, nautili, happy ghasts, and /ride ... mount. Player leaving: the dismount input for each, /ride ... dismount, a stab, a buck, a teleport, spectator mode (through dismount_mount, dismount, dismount_cart, get_up_from_cushion).
  • Mobs: mount_mob (now try_mount_mob, which returns whether the mob was seated) for jockeys, raiders on ravagers and /ride; dismount_mob for /ride and a stab.
  • Dismount guards ask only if the rider is still seated (riding == Some(vehicle)), so a rail that already cleared the seat does not report a dismount that did not happen.
  • Not told: a vehicle removed or killed under its rider, and riders loaded with a save. The single player server thread and a dedicated server only; clients and the deprecated in-frame path never fire it.

Kind

  • feature: something new for players (mod authors)

Vanilla reference

Entity.startRiding and Entity.removeVehicle/stopRiding. NeoForge posts EntityMountEvent from both (before canRide, so attempts are seen) and cancelling means no mount or no dismount.

Other projects' code

None. NeoForge's names and contracts only.

Proof in the real game

Engine from this branch with a throwaway eprintln! in the hook body (not in this PR) that cancels mount:<vehicle type> / dismount:<vehicle type> entries of an environment variable.

Server thread, cancelling mount:minecraft:oak_boat, dismount:minecraft:minecart, mount:minecraft:pig; /ride commands run by the host player:

  • ride @s mount <oak boat>: "couldn't start riding Oak Boat"; probe entity=2/minecraft:player vehicle=441/minecraft:oak_boat mounting=true canceled=true.
  • ride @s mount <minecart>: "started riding Minecart" (canceled=false); ride @s dismount: probe mounting=false canceled=true, and the next ride @s mount says "is already riding Minecart", so the player stayed seated (/ride dismount still prints "stopped riding Minecart": vanilla's command reports success after stopRiding() whether or not the rider got off, and I left that as is).
  • ride <zombie> mount <pig>: "Zombie couldn't start riding Pig" (canceled=true); ride <zombie> mount <horse>: started riding, then dismount stopped riding (both canceled=false).

Dedicated server (a client connected, commands from the console): ride <zombie> mount <pig> canceled ("Zombie couldn't start riding Pig", probe canceled=true). /ride run on a connected guest player (ride Alex ...) fails with or without the hook ("couldn't start riding": /ride only supports the host player in Horizon today), so the dedicated run proves the mob path only.

Not run: a player boarding or leaving by right-click and sneak (the /ride command paths only), saddled pig/strider/horse/llama/nautilus/ghast and cushions, stab/buck/teleport/spectator dismounts, a LAN guest or a dedicated-server player acting through as_guest (a driven client's position diverged from the server's in my script and I did not chase it), parity harnesses.

Self-check

pr_ready (tools/pr_ready.py --quick --base hr/main on cachyos-x8664, against hr/main at 455b6916b, 1 min 30 s)

Check Result
Scope ✅ 13 files, +203 −7
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 586 passed (34 s)
rustfmt ✅ (6 s)
clippy ✅ (19 s)
tests: horizon-client ✅ 1805 passed (29 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 ➖ not run (--quick): CI's parity job picks the affected harnesses

🤖 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/6281 **Author:** [@levzzz5154](https://github.com/levzzz5154) **Created:** 11/1/2026 **Status:** ✅ Merged **Merged:** 11/1/2026 **Merged by:** [@levzzz5154](https://github.com/levzzz5154) **Base:** `main` ← **Head:** `mods/entity-mount` --- ### 📝 Commits (1) - [`0b4fdee`](https://github.com/horizon-rust/horizon/commit/0b4fdee2900be9ab9a5b8de7abc54601890cc228) Native mods: an entity mounting or dismounting a vehicle, EntityMountEvent ### 📊 Changes **13 files changed** (+203 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+1 -0) 📝 `crates/horizon-client/src/game/boats.rs` (+7 -0) 📝 `crates/horizon-client/src/game/commands/world_cmds.rs` (+21 -4) 📝 `crates/horizon-client/src/game/cushions.rs` (+6 -0) 📝 `crates/horizon-client/src/game/ghasts.rs` (+3 -0) 📝 `crates/horizon-client/src/game/llamas.rs` (+3 -0) 📝 `crates/horizon-client/src/game/minecarts.rs` (+8 -1) 📝 `crates/horizon-client/src/game/mounts.rs` (+14 -2) 📝 `crates/horizon-client/src/game/native_hooks.rs` (+34 -0) ➕ `crates/horizon-client/src/game/native_mounts.rs` (+82 -0) 📝 `crates/horizon-client/src/game/nautili.rs` (+3 -0) 📝 `crates/horizon-client/src/game/passengers.rs` (+8 -0) ➕ `tools/native-hook-fragments/entity_mount.json` (+13 -0) </details> ### 📄 Description > 🤖 Opened by levzzz5154's AI agent (Claude Code, Claude Sonnet 5.5), not by levzzz5154 personally. ## What and why Fixes #6273, part of #4953 ("Entity: tick, mount, size, projectile impact"). A native mod that keeps players out of a vehicle (or in it), or reacts to a mob being seated, had no hook: nothing told it an entity was about to get on or off a vehicle and nothing let it say no. One server hook point, API from a fragment (`tools/native-hook-fragments/entity_mount.json`): - `native_entity_mount(dimension, entity, kind, vehicle, vehicle_kind, mounting, canceled)` (`EntityMountEvent`): ids and types of the rider (`minecraft:player`, `minecraft:zombie`) and the vehicle (`minecraft:oak_boat`, `minecraft:horse`, `minecraft:cushion`), `mounting` true to board and false to leave. Set `canceled` and the rider does not board, or keeps riding; a canceled `/ride` fails with vanilla's "couldn't start riding". Where. Horizon has no one `startRiding`; each vehicle keeps its rider state itself, so the hook is asked at each seat/unseat site, before the state changes (`game/native_mounts.rs` has the helpers `native_may_board`, `native_may_leave`, `native_mob_may_ride`): - Player boarding: boats, minecarts, cushions, saddled pigs and striders (`mounts.rs`), horses and kin, llamas, nautili, happy ghasts, and `/ride ... mount`. Player leaving: the dismount input for each, `/ride ... dismount`, a stab, a buck, a teleport, spectator mode (through `dismount_mount`, `dismount`, `dismount_cart`, `get_up_from_cushion`). - Mobs: `mount_mob` (now `try_mount_mob`, which returns whether the mob was seated) for jockeys, raiders on ravagers and `/ride`; `dismount_mob` for `/ride` and a stab. - Dismount guards ask only if the rider is still seated (`riding == Some(vehicle)`), so a rail that already cleared the seat does not report a dismount that did not happen. - Not told: a vehicle removed or killed under its rider, and riders loaded with a save. The single player server thread and a dedicated server only; clients and the deprecated in-frame path never fire it. ## Kind - [x] feature: something new for players (mod authors) ## Vanilla reference `Entity.startRiding` and `Entity.removeVehicle`/`stopRiding`. NeoForge posts `EntityMountEvent` from both (before `canRide`, so attempts are seen) and cancelling means no mount or no dismount. ## Other projects' code None. NeoForge's names and contracts only. ## Proof in the real game Engine from this branch with a throwaway `eprintln!` in the hook body (not in this PR) that cancels `mount:<vehicle type>` / `dismount:<vehicle type>` entries of an environment variable. Server thread, cancelling `mount:minecraft:oak_boat`, `dismount:minecraft:minecart`, `mount:minecraft:pig`; `/ride` commands run by the host player: - `ride @s mount <oak boat>`: "couldn't start riding Oak Boat"; probe `entity=2/minecraft:player vehicle=441/minecraft:oak_boat mounting=true canceled=true`. - `ride @s mount <minecart>`: "started riding Minecart" (`canceled=false`); `ride @s dismount`: probe `mounting=false canceled=true`, and the next `ride @s mount` says "is already riding Minecart", so the player stayed seated (`/ride dismount` still prints "stopped riding Minecart": vanilla's command reports success after `stopRiding()` whether or not the rider got off, and I left that as is). - `ride <zombie> mount <pig>`: "Zombie couldn't start riding Pig" (`canceled=true`); `ride <zombie> mount <horse>`: started riding, then `dismount` stopped riding (both `canceled=false`). Dedicated server (a client connected, commands from the console): `ride <zombie> mount <pig>` canceled ("Zombie couldn't start riding Pig", probe `canceled=true`). `/ride` run on a connected guest player (`ride Alex ...`) fails with or without the hook ("couldn't start riding": `/ride` only supports the host player in Horizon today), so the dedicated run proves the mob path only. Not run: a player boarding or leaving by right-click and sneak (the `/ride` command paths only), saddled pig/strider/horse/llama/nautilus/ghast and cushions, stab/buck/teleport/spectator dismounts, a LAN guest or a dedicated-server player acting through `as_guest` (a driven client's position diverged from the server's in my script and I did not chase it), parity harnesses. ## Self-check **pr_ready** (`tools/pr_ready.py --quick --base hr/main` on cachyos-x8664, against hr/main at 455b6916b, 1 min 30 s) | Check | Result | | --- | --- | | Scope | ✅ 13 files, +203 −7 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 586 passed (34 s) | | rustfmt | ✅ (6 s) | | clippy | ✅ (19 s) | | tests: horizon-client | ✅ 1805 passed (29 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 | ➖ not run (--quick): CI's parity job picks the affected harnesses | 🤖 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 06:26:17 +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#6765
No description provided.