[PR #6307] [MERGED] Native mods: a player's game mode changing, cancellable (native_player_game_mode_changed, part of #5816) #6782

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

📋 Pull Request Information

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

Base: main ← Head: feat-player-game-mode-hook


📝 Commits (4)

  • 46ba796 Native mods: a server player's game mode about to change, cancellable (native_player_game_mode_changed)
  • 81e64df Merge upstream/main: keep both hooks
  • 2934443 Merge main into #6307
  • 1e1d41e Merge main into #6307

📊 Changes

5 files changed (+64 additions, -2 deletions)

View changed files

📝 crates/horizon-client/src/game/commands.rs (+15 -0)
📝 crates/horizon-client/src/game/lan_actions.rs (+12 -2)
📝 crates/horizon-client/src/game/native_hooks.rs (+21 -0)
📝 docs/native-mods.md (+6 -0)
➕ tools/native-hook-fragments/native_player_game_mode_changed.json (+10 -0)

📄 Description

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

What and why

Part of #5816 (hook points a survival server's native mods need). A mod could not hear or refuse a player's game mode change.

  • New hook point native_player_game_mode_changed(player, name, from, to, cancel) (0 survival, 1 creative, 2 adventure, 3 spectator; fragment native_player_game_mode_changed.json, docs paragraph). Setting cancel keeps the old mode.
  • Called from Game::set_game_mode (commands.rs) when a server guest's mode actually differs: covers /gamemode (console or player; the guest's state is swapped in) and the F3+F4 ChangeGameMode packet; also from the hardcore respawn into spectator in guest_respawn. The hub's own set_game_mode cannot reach Game, so the game-side callers are hooked.
  • Nothing changes when no mod hooks it.

Kind

  • feature (new native hook point)

Vanilla reference

NeoForge's PlayerEvent.PlayerChangeGameModeEvent (cancellable).

Other projects' code

none. (Tested with a throwaway horizon-mixins bundle, not part of this PR.)

Proof on a real dedicated server

The bundle cancels any change to spectator.

console: gamemode creative P             -> hook 0->1, client gets mode 1
console: gamemode spectator P (cancelled)-> hook 1->3, "cancelling", client gets nothing
console: gamemode creative P (same mode) -> no hook line
console: gamemode survival P             -> hook 1->0, client gets mode 0
F3+F4 packet: creative / spectator / adventure -> hooks 0->1, 1->3 (cancelled), 1->2
survival -> spectator (cancelled); data get entity P playerGameType -> 0 (still survival)

Not covered: defaultgamemode / force-gamemode enforcement and the mode a player joins with, the integrated server owner's personal mode, a LAN host's own player, and the hardcore-respawn path (same call pattern, not run live; there the player's state is not swapped in).

Self-check

pr_ready --quick --base upstream/main before merging main: all green (515 Python tests, rustfmt, clippy, horizon-client tests 1668 passed, doc tests); parity not run (--quick). After the merge: cargo test -p horizon-client --bin horizon-client native_hooks::tests passes (20 tests).


🔄 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/6307 **Author:** [@Detimes](https://github.com/Detimes) **Created:** 11/1/2026 **Status:** ✅ Merged **Merged:** 11/1/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `feat-player-game-mode-hook` --- ### 📝 Commits (4) - [`46ba796`](https://github.com/horizon-rust/horizon/commit/46ba79697b37f2b03d4b02888bc82f6ee67c2c28) Native mods: a server player's game mode about to change, cancellable (native_player_game_mode_changed) - [`81e64df`](https://github.com/horizon-rust/horizon/commit/81e64df8b235fd2a1f185280455f48ca5b2ac061) Merge upstream/main: keep both hooks - [`2934443`](https://github.com/horizon-rust/horizon/commit/293444390f6d5f2c08d5275a151db88e36d8866d) Merge main into #6307 - [`1e1d41e`](https://github.com/horizon-rust/horizon/commit/1e1d41e588caaa186003f0006916175de7c7da0a) Merge main into #6307 ### 📊 Changes **5 files changed** (+64 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game/commands.rs` (+15 -0) 📝 `crates/horizon-client/src/game/lan_actions.rs` (+12 -2) 📝 `crates/horizon-client/src/game/native_hooks.rs` (+21 -0) 📝 `docs/native-mods.md` (+6 -0) ➕ `tools/native-hook-fragments/native_player_game_mode_changed.json` (+10 -0) </details> ### 📄 Description > 🤖 Opened by Detimes' AI agent (Claude Code, Claude Sonnet 5.5), not by Detimes personally. ## What and why Part of #5816 (hook points a survival server's native mods need). A mod could not hear or refuse a player's game mode change. - New hook point `native_player_game_mode_changed(player, name, from, to, cancel)` (0 survival, 1 creative, 2 adventure, 3 spectator; fragment `native_player_game_mode_changed.json`, docs paragraph). Setting `cancel` keeps the old mode. - Called from `Game::set_game_mode` (commands.rs) when a server guest's mode actually differs: covers `/gamemode` (console or player; the guest's state is swapped in) and the F3+F4 `ChangeGameMode` packet; also from the hardcore respawn into spectator in `guest_respawn`. The hub's own `set_game_mode` cannot reach `Game`, so the game-side callers are hooked. - Nothing changes when no mod hooks it. ## Kind - [x] feature (new native hook point) ## Vanilla reference NeoForge's `PlayerEvent.PlayerChangeGameModeEvent` (cancellable). ## Other projects' code none. (Tested with a throwaway horizon-mixins bundle, not part of this PR.) ## Proof on a real dedicated server The bundle cancels any change to spectator. ``` console: gamemode creative P -> hook 0->1, client gets mode 1 console: gamemode spectator P (cancelled)-> hook 1->3, "cancelling", client gets nothing console: gamemode creative P (same mode) -> no hook line console: gamemode survival P -> hook 1->0, client gets mode 0 F3+F4 packet: creative / spectator / adventure -> hooks 0->1, 1->3 (cancelled), 1->2 survival -> spectator (cancelled); data get entity P playerGameType -> 0 (still survival) ``` Not covered: `defaultgamemode` / `force-gamemode` enforcement and the mode a player joins with, the integrated server owner's personal mode, a LAN host's own player, and the hardcore-respawn path (same call pattern, not run live; there the player's state is not swapped in). ## Self-check `pr_ready --quick --base upstream/main` before merging main: all green (515 Python tests, rustfmt, clippy, `horizon-client` tests 1668 passed, doc tests); parity not run (`--quick`). After the merge: `cargo test -p horizon-client --bin horizon-client native_hooks::tests` passes (20 tests). --- <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: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#6782
No description provided.