[PR #7454] [MERGED] Native mods: entity and level handles (EntityRef, LevelRef) and an entity's position, type, UUID and level #7611

Closed
opened 2026-11-03 07:20:41 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

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

Base: main ← Head: modapi/entity-handles


📝 Commits (3)

  • b21901f Native mods: entity and level handles, and an entity's position, type, UUID and level (#7387)
  • 7b77a5e Merge main into modapi/entity-handles
  • 4caae28 Merge remote-tracking branch 'hr/main' into modapi/entity-handles

📊 Changes

10 files changed (+488 additions, -7 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+1 -0)
📝 crates/horizon-client/src/game/mod_api_host_generated.rs (+24 -0)
📝 crates/horizon-client/src/game/native_entities.rs (+5 -5)
➕ crates/horizon-client/src/game/native_entity_refs.rs (+114 -0)
📝 crates/horizon-client/src/game/native_lifecycle.rs (+6 -0)
📝 crates/horizon-client/src/mod_api.rs (+53 -1)
📝 crates/horizon-client/src/mod_api/generated_host.rs (+83 -0)
📝 docs/native-mods.md (+17 -0)
➕ tools/native-hook-fragments/entity_handles.json (+48 -0)
📝 xtask/src/mod_api.rs (+137 -1)

📄 Description

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

Part of #7387: the first slice, following the issue's proposal (typed handles whose methods take the host).

What it adds

  • EntityRef (the world's open epoch plus the entity id) and LevelRef (the epoch plus a dimension), small Copy values in mod_api.
  • Bridges host.entity(id) and host.level(dimension): the only id-taking entry points. They return None on a client, with no world open, or for no such entity or level.
  • The generator's receiver key. A helper whose catalog entry says "receiver": "entity" (or "level") is still a plain Host method (host.entity_position(entity)). It also becomes a one-line method of the handle, generated beside Host in generated_host.rs: entity.position(host). The host is borrowed as the helper borrows Game (&dyn Host or &mut dyn Host). The name must start with the receiver, and the first argument must be the handle. The xtask checks both and has a test for each error.
  • First EntityRef reads (top-30 rows 5, 7, 17, 20, 26): position, block_position, rotation, kind (type is a keyword), uuid and level.
    • They read the level in place (the one a hook runs in) and the server's players, whatever their level.
    • uuid takes &mut: an entity with no UUID yet gets the one it will be saved with, as a new vanilla entity has one.
  • Docs: docs/native-mods.md, "Entity and level handles".
  • Rename: the private native_entity_level(dimension) -> bool in native_entities.rs is now native_simulates_level, so the name is free for EntityRef::level.

A stale handle (an earlier open), a gone entity or a handle used on a client reads as None and never panics. Epochs come from the existing NativeLifecycle (process-wide, never reused), now readable with NativeLifecycle::epoch().

Proof

A mixin bundle injected at Game::tick_mobs HEAD calls host.entity(id) for ids 0..3000 every 100 server ticks, then each handle method. Run on this branch's fast build, server thread, offscreen, scratch homes:

ENTPROBE tick=50 level=minecraft:overworld epoch=1 nether=None bogus=None
ENTPROBE id=1 kind=Some("minecraft:player") pos=Some([-24.5, 69.0, 2.5]) block=Some([-25, 69, 2]) rot=Some([0.0, 0.0]) uuid=Some(d1fad0ff286c349da0b42abab8432fbe) uuid_again=Some(d1fad0ff286c349da0b42abab8432fbe) level=Some("minecraft:overworld") stale_pos=None
ENTPROBE id=2 kind=Some("minecraft:chicken") pos=Some([-58.87, 64.0, 22.83]) block=Some([-59, 64, 22]) rot=Some([227.93959, 0.0]) uuid=Some(fd2f8571caed4b0888fea455e977ec28) uuid_again=Some(fd2f8571caed4b0888fea455e977ec28) level=Some("minecraft:overworld") stale_pos=None
ENTPROBE id=5 kind=Some("minecraft:bat") pos=Some([-59.73, -45.31, -15.46]) block=Some([-60, -46, -16]) ...
ENTPROBE found=347
...
ENTPROBE tick=150 ... id=2 kind=Some("minecraft:chicken") pos=Some([-58.51, 64.0, 19.85]) ... uuid=Some(fd2f8571caed4b0888fea455e977ec28)
  • The player (a server-thread guest) resolves, with its own UUID.
  • Mobs move between samples and keep their UUID.
  • A handle with the next epoch reads None.
  • The Nether isn't loaded, so its level handle is None, and so is an unknown dimension.

Tests: cargo +stable test -p xtask (20, including the new handle_methods_call_the_host_and_borrow_it_as_the_helper_borrows_game), cargo +stable test -p horizon-client --lib (the mod_api and native_hooks tests, plus the new uuid_words_are_most_significant_first), cargo +stable clippy -p horizon-client -p xtask --lib --bins --tests -D warnings, and cargo run -p xtask -- mod-api --check.

pr_ready (tools/pr_ready.py --quick --base hr/main on cachyos-x8664, against hr/main at 0cf1b3d20, 4 min 58 s)

Check Result
Scope ✅ 10 files, +488 −7
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 613 passed (34 s)
rustfmt ✅ (6 s)
clippy ✅ (1 min 30 s)
tests: horizon-client, horizon-client-lib, xtask ✅ 2175 passed (1 min 42 s)
doc tests ✅ 0 passed (52 s)
content root tests ➖ content root untouched
mod API up to date ✅ (14 s)
tokens.css up to date ✅
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)

Next

#7387's next slices build on this: LevelRef block and time reads, EntityRef motion, and EntityRef data and tags. They are ready and stacked on this branch, and open once this one is reviewed.

🤖 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/7454 **Author:** [@levzzz5154](https://github.com/levzzz5154) **Created:** 11/2/2026 **Status:** ✅ Merged **Merged:** 11/2/2026 **Merged by:** [@levzzz5154](https://github.com/levzzz5154) **Base:** `main` ← **Head:** `modapi/entity-handles` --- ### 📝 Commits (3) - [`b21901f`](https://github.com/horizon-rust/horizon/commit/b21901f67698b54bb46148a0409769ce9e24c8d5) Native mods: entity and level handles, and an entity's position, type, UUID and level (#7387) - [`7b77a5e`](https://github.com/horizon-rust/horizon/commit/7b77a5ec989f448298572d44dee9ab84fe38cb50) Merge main into modapi/entity-handles - [`4caae28`](https://github.com/horizon-rust/horizon/commit/4caae28435cb9eafea26a4532268ee52df008773) Merge remote-tracking branch 'hr/main' into modapi/entity-handles ### 📊 Changes **10 files changed** (+488 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+1 -0) 📝 `crates/horizon-client/src/game/mod_api_host_generated.rs` (+24 -0) 📝 `crates/horizon-client/src/game/native_entities.rs` (+5 -5) ➕ `crates/horizon-client/src/game/native_entity_refs.rs` (+114 -0) 📝 `crates/horizon-client/src/game/native_lifecycle.rs` (+6 -0) 📝 `crates/horizon-client/src/mod_api.rs` (+53 -1) 📝 `crates/horizon-client/src/mod_api/generated_host.rs` (+83 -0) 📝 `docs/native-mods.md` (+17 -0) ➕ `tools/native-hook-fragments/entity_handles.json` (+48 -0) 📝 `xtask/src/mod_api.rs` (+137 -1) </details> ### 📄 Description > 🤖 Opened by levzzz5154's AI agent (Claude Code, Claude Opus 5.5), not by levzzz5154 personally. Part of #7387: the first slice, following the issue's proposal (typed handles whose methods take the host). ## What it adds - **`EntityRef`** (the world's open epoch plus the entity id) and **`LevelRef`** (the epoch plus a dimension), small `Copy` values in `mod_api`. - **Bridges** `host.entity(id)` and `host.level(dimension)`: the only id-taking entry points. They return `None` on a client, with no world open, or for no such entity or level. - **The generator's `receiver` key.** A helper whose catalog entry says `"receiver": "entity"` (or `"level"`) is still a plain `Host` method (`host.entity_position(entity)`). It also becomes a one-line method of the handle, generated beside `Host` in `generated_host.rs`: `entity.position(host)`. The host is borrowed as the helper borrows `Game` (`&dyn Host` or `&mut dyn Host`). The name must start with the receiver, and the first argument must be the handle. The xtask checks both and has a test for each error. - **First `EntityRef` reads** (top-30 rows 5, 7, 17, 20, 26): `position`, `block_position`, `rotation`, `kind` (`type` is a keyword), `uuid` and `level`. - They read the level in place (the one a hook runs in) and the server's players, whatever their level. - `uuid` takes `&mut`: an entity with no UUID yet gets the one it will be saved with, as a new vanilla entity has one. - **Docs:** `docs/native-mods.md`, "Entity and level handles". - **Rename:** the private `native_entity_level(dimension) -> bool` in `native_entities.rs` is now `native_simulates_level`, so the name is free for `EntityRef::level`. A stale handle (an earlier open), a gone entity or a handle used on a client reads as `None` and never panics. Epochs come from the existing `NativeLifecycle` (process-wide, never reused), now readable with `NativeLifecycle::epoch()`. ## Proof A mixin bundle injected at `Game::tick_mobs` HEAD calls `host.entity(id)` for ids 0..3000 every 100 server ticks, then each handle method. Run on this branch's fast build, server thread, offscreen, scratch homes: ``` ENTPROBE tick=50 level=minecraft:overworld epoch=1 nether=None bogus=None ENTPROBE id=1 kind=Some("minecraft:player") pos=Some([-24.5, 69.0, 2.5]) block=Some([-25, 69, 2]) rot=Some([0.0, 0.0]) uuid=Some(d1fad0ff286c349da0b42abab8432fbe) uuid_again=Some(d1fad0ff286c349da0b42abab8432fbe) level=Some("minecraft:overworld") stale_pos=None ENTPROBE id=2 kind=Some("minecraft:chicken") pos=Some([-58.87, 64.0, 22.83]) block=Some([-59, 64, 22]) rot=Some([227.93959, 0.0]) uuid=Some(fd2f8571caed4b0888fea455e977ec28) uuid_again=Some(fd2f8571caed4b0888fea455e977ec28) level=Some("minecraft:overworld") stale_pos=None ENTPROBE id=5 kind=Some("minecraft:bat") pos=Some([-59.73, -45.31, -15.46]) block=Some([-60, -46, -16]) ... ENTPROBE found=347 ... ENTPROBE tick=150 ... id=2 kind=Some("minecraft:chicken") pos=Some([-58.51, 64.0, 19.85]) ... uuid=Some(fd2f8571caed4b0888fea455e977ec28) ``` - The player (a server-thread guest) resolves, with its own UUID. - Mobs move between samples and keep their UUID. - A handle with the next epoch reads `None`. - The Nether isn't loaded, so its level handle is `None`, and so is an unknown dimension. Tests: `cargo +stable test -p xtask` (20, including the new `handle_methods_call_the_host_and_borrow_it_as_the_helper_borrows_game`), `cargo +stable test -p horizon-client --lib` (the mod_api and native_hooks tests, plus the new `uuid_words_are_most_significant_first`), `cargo +stable clippy -p horizon-client -p xtask --lib --bins --tests -D warnings`, and `cargo run -p xtask -- mod-api --check`. **pr_ready** (`tools/pr_ready.py --quick --base hr/main` on cachyos-x8664, against hr/main at 0cf1b3d20, 4 min 58 s) | Check | Result | | --- | --- | | Scope | ✅ 10 files, +488 −7 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 613 passed (34 s) | | rustfmt | ✅ (6 s) | | clippy | ✅ (1 min 30 s) | | tests: horizon-client, horizon-client-lib, xtask | ✅ 2175 passed (1 min 42 s) | | doc tests | ✅ 0 passed (52 s) | | content root tests | ➖ content root untouched | | mod API up to date | ✅ (14 s) | | tokens.css up to date | ✅ | | 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) | ## Next #7387's next slices build on this: LevelRef block and time reads, EntityRef motion, and EntityRef data and tags. They are ready and stacked on this branch, and open once this one is reviewed. 🤖 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 07:20:41 +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#7611
No description provided.