[PR #4799] [MERGED] Native mods: helpers for spawning and moving mobs (API next) #5859

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

📋 Pull Request Information

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

Base: main ← Head: hooks-mobs


📝 Commits (2)

  • e35be2e Native mods: helpers for spawning and moving mobs (API 23)
  • 13aecbe Merge hr/main; renumber mob helpers to API 37; dimension argument, verb-first names, /summon bounds, /tp dismount, readers gated, removed mobs unsaved

📊 Changes

6 files changed (+256 additions, -2 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+1 -0)
📝 crates/horizon-client/src/game/commands.rs (+1 -1)
📝 crates/horizon-client/src/game/native_hooks.rs (+6 -1)
➕ crates/horizon-client/src/game/native_mobs.rs (+225 -0)
📝 crates/horizon-client/src/game/persist.rs (+1 -0)
📝 docs/native-mods.md (+22 -0)

📄 Description

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

What and why

Fixes #4740. Part of #3911 (Mods), gap X of #1854 (entities and AI). A native server mod can now spawn a mob, read the mobs of the level in place, and move, hurt or remove one by its id, without reaching into the game's internals. Bosses, guards and summoned creatures need this. These are helpers in a new game/native_mobs.rs, like native_server.rs, with no new hook points.

  • native_spawn_mob(kind, pos, &NativeSpawn) -> Option<u32>: a mob of a kind the game knows, through spawn_mob, so it's finalized as a natural spawn is and persistent. NativeSpawn holds an optional name and health, and the no_ai, invisible, silent, invulnerable and no_gravity flags.
  • native_mob(id), native_mobs(): the living mobs' id, kind, position, yaw, health and maximum health.
  • native_mob_teleport(id, pos), native_mob_push(id, velocity), native_mob_set_health(id, health): answer false for no such mob or a value that isn't finite; health must be above 0.
  • native_kill_mob(id): the same path as /kill, with loot. kill_target becomes pub(super) for this.
  • native_remove_mob(id): takes the mob away with no death and no loot.

They do nothing on a client's copy of the level. While the game ticks its mobs they are out of self.mobs, so from a hook inside that tick a spawned mob joins after the tick and the others read as gone; the module and the docs say so.

NATIVE_HOOKS_API goes to the next free number: 23 in the code on this base, and it moves with whatever merges first. An "API 23" paragraph and a "Mobs" section are in docs/native-mods.md.

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: helpers that nothing in Horizon calls. Teleporting does what Target::Mob does for /tp, and killing is /kill's own path. Without a native mod nothing changes. 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) added a command that calls each helper. On a dedicated server (--dedicated --nogui, Windows) with two real clients, Alex and Steve, under horizon-ctl --offscreen, all 35 checks passed:

Check Result
Alex spawns a named zombie with health 6, no_ai and invulnerable an id; both clients see it with health 6; the name and flags are on the mob
Steve reads Alex's mob native_mob and native_mobs find it
Teleport both clients see it at the new place
Health 1000 cut to the maximum, and Steve's client shows it
Push on a mob with AI a client sees it rise
Kill, then kill again loot on the ground; true, then false
Remove, then remove again gone from both clients, with no loot; true, then false
Unknown kind, a position or velocity that isn't finite, health 0, no such id none or false; the mob isn't changed
Each helper on a client's copy none or false

A flat world's mobs kill a lone zombie within seconds, a summoned one too, so the run clears them first and turns mob spawning off. Not tested: a spawned mob surviving a restart (it's persistent by spawn_mob, but I didn't restart the server), a helper called from a hook inside the mob tick, and a real mod using these.

Self-check

tools/pr_ready.py --quick --base origin/main on Windows. 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.

pr_ready (tools/pr_ready.py --quick on DESKTOP-H7P5E7K, against origin/main at 9990eabc7, 1 min 54 s)

Check Result
Scope ✅ 6 files, +197 −3
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 481 passed (1 min 6 s)
rustfmt ✅ (7 s)
clippy ✅ (7 s)
tests: horizon-client ✅ 1204 passed (30 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)

The table counts that relaxed line, which is why it shows one file more than this pull request.

🤖 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/4799 **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-mobs` --- ### 📝 Commits (2) - [`e35be2e`](https://github.com/horizon-rust/horizon/commit/e35be2e5bc8a03a7e6669944a143d6b8bd6cace2) Native mods: helpers for spawning and moving mobs (API 23) - [`13aecbe`](https://github.com/horizon-rust/horizon/commit/13aecbe1e5152aa0858c14d11b51a487c0d5b697) Merge hr/main; renumber mob helpers to API 37; dimension argument, verb-first names, /summon bounds, /tp dismount, readers gated, removed mobs unsaved ### 📊 Changes **6 files changed** (+256 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+1 -0) 📝 `crates/horizon-client/src/game/commands.rs` (+1 -1) 📝 `crates/horizon-client/src/game/native_hooks.rs` (+6 -1) ➕ `crates/horizon-client/src/game/native_mobs.rs` (+225 -0) 📝 `crates/horizon-client/src/game/persist.rs` (+1 -0) 📝 `docs/native-mods.md` (+22 -0) </details> ### 📄 Description > 🤖 Opened by Qwerner88880's AI agent (Claude Code, Claude Opus 5.5), not by Qwerner88880 personally. ## What and why Fixes #4740. Part of #3911 (Mods), gap **X** of #1854 (entities and AI). A native server mod can now spawn a mob, read the mobs of the level in place, and move, hurt or remove one by its id, without reaching into the game's internals. Bosses, guards and summoned creatures need this. These are helpers in a new `game/native_mobs.rs`, like `native_server.rs`, with no new hook points. - **`native_spawn_mob(kind, pos, &NativeSpawn) -> Option<u32>`:** a mob of a kind the game knows, through `spawn_mob`, so it's finalized as a natural spawn is and persistent. `NativeSpawn` holds an optional name and health, and the `no_ai`, `invisible`, `silent`, `invulnerable` and `no_gravity` flags. - **`native_mob(id)`, `native_mobs()`:** the living mobs' id, kind, position, yaw, health and maximum health. - **`native_mob_teleport(id, pos)`, `native_mob_push(id, velocity)`, `native_mob_set_health(id, health)`:** answer false for no such mob or a value that isn't finite; health must be above 0. - **`native_kill_mob(id)`:** the same path as `/kill`, with loot. `kill_target` becomes `pub(super)` for this. - **`native_remove_mob(id)`:** takes the mob away with no death and no loot. They do nothing on a client's copy of the level. While the game ticks its mobs they are out of `self.mobs`, so from a hook inside that tick a spawned mob joins after the tick and the others read as gone; the module and the docs say so. `NATIVE_HOOKS_API` goes to the next free number: 23 in the code on this base, and it moves with whatever merges first. An "API 23" paragraph and a "Mobs" section are in `docs/native-mods.md`. ## 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: helpers that nothing in Horizon calls. Teleporting does what `Target::Mob` does for `/tp`, and killing is `/kill`'s own path. Without a native mod nothing changes. 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) added a command that calls each helper. On a dedicated server (`--dedicated --nogui`, Windows) with two real clients, Alex and Steve, under `horizon-ctl --offscreen`, all 35 checks passed: | Check | Result | | --- | --- | | Alex spawns a named zombie with health 6, `no_ai` and `invulnerable` | an id; both clients see it with health 6; the name and flags are on the mob | | Steve reads Alex's mob | `native_mob` and `native_mobs` find it | | Teleport | both clients see it at the new place | | Health 1000 | cut to the maximum, and Steve's client shows it | | Push on a mob with AI | a client sees it rise | | Kill, then kill again | loot on the ground; `true`, then `false` | | Remove, then remove again | gone from both clients, with no loot; `true`, then `false` | | Unknown kind, a position or velocity that isn't finite, health 0, no such id | none or `false`; the mob isn't changed | | Each helper on a client's copy | none or `false` | A flat world's mobs kill a lone zombie within seconds, a summoned one too, so the run clears them first and turns mob spawning off. **Not tested:** a spawned mob surviving a restart (it's persistent by `spawn_mob`, but I didn't restart the server), a helper called from a hook inside the mob tick, and a real mod using these. ## Self-check `tools/pr_ready.py --quick --base origin/main` on Windows. `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. **pr_ready** (`tools/pr_ready.py --quick` on DESKTOP-H7P5E7K, against origin/main at 9990eabc7, 1 min 54 s) | Check | Result | | --- | --- | | Scope | ✅ 6 files, +197 −3 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 481 passed (1 min 6 s) | | rustfmt | ✅ (7 s) | | clippy | ✅ (7 s) | | tests: horizon-client | ✅ 1204 passed (30 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) | The table counts that relaxed line, which is why it shows one file more than this pull request. 🤖 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:15:29 +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#5859
No description provided.