[PR #7214] [MERGED] docs: the typed mod API from mixin code #7416

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

📋 Pull Request Information

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

Base: main ← Head: v2/ses_01M6BECNQ499TYMMBQBDF00VJ5-mixin-docs


📝 Commits (5)

  • 41074f0 docs: the typed API from mixin code
  • 28cb0a5 docs: fix the typed API from mixin code examples
  • 364297a Merge remote-tracking branch 'upstream/main' into mixin-docs
  • 32b4236 docs: where a mixin module lives, and why the [api] crate keeps its own attachment
  • c1649ac Merge remote-tracking branch 'upstream/main' into mixin-docs

📊 Changes

1 file changed (+70 additions, -1 deletions)

View changed files

📝 docs/native-mods.md (+70 -1)

📄 Description

🤖 Opened by Aria's agent swarm, Dyna, not by Aria.

This PR documents how mixin code uses the typed mod API. It is #6452's "Document the typed API from mixin code" item, and it changes docs only: a new section, "The typed API from mixin code", in docs/native-mods.md.

What it documents

  • A helper on a Game method.
    • Bind &mut crate::game::Game<'_> and coerce it to &mut dyn Host. Game isn't an AttachmentHost itself, so this coercion is the step that matters.
    • Then use attachments and any Host helper.
    • The attachment static lives in a [[module]] of the bundle. The doc shows how a module's file and name give its path (crate::game::example).
  • A helper on a GameLevel method (native_random_tick, native_tick_block, native_perform_bonemeal, native_is_bonemeal_success).
    • Bind &mut dyn crate::mod_api::LevelRandomHost, for attachments and random().
    • The doc says which level host the hook points pass for scheduling and block writes.
  • A trait injection.
    • Bind host: &mut dyn crate::mod_api::Host, so the [api] crate reads event.host.
    • The [api] crate depends on horizon-client's library, not on the game executable that helpers and modules are compiled into. So it declares its own AttachmentType with the same namespace and name. The pair is the key, so both statics read one value.
  • Versioning.
    • A catalog hook's trait method, event and return are part of its hook_version contract. Later Horizons only add #[non_exhaustive] event fields, defaulted trait methods and Host methods.
    • So a mod that uses only catalog hooks and Host can set "hooks" in its .hnmod.
    • A mod that injects into a raw target pins horizon_revision instead.
  • A link from "Server attachments" to the new section.

It follows Sponge Mixin's model, which the section names: a handler merged into its target class.

Tested in game

Both examples were built from the doc's code as written, adding only a log line each. They were built through the launcher (horizon-launcher native-build <bundle> --instance horizon --trust-native-code), so horizon-mixins applied the injections. The bundle:

  • the count helper injected at the HEAD of Game::tick_mobs, with COUNTER in a [[module]] at crates/horizon-client/src/game.rs, named example;
  • a trait_method = "count" injection at the same target, with the host binding, whose [api] crate keeps its own COUNTER with the same namespace and name.

On the single-player server thread, both logged the same level counter, read through the two statics:

MIXIN_DOCS helper count=100   MIXIN_DOCS trait count=100
MIXIN_DOCS helper count=200   MIXIN_DOCS trait count=200
… 300, 400, 500, 600, 700, the same on both

This ran at 32b4236c75. The head adds only a merge of main, which brings main's new "Testing a trait mod" section beside this one, and changes none of this section's text.

The recommended end-to-end route for native mods is horizon-machine-sample. It wasn't used here: this section's examples are their own bundle, so a throwaway bundle built from the doc was the closer test.

pr_ready

pr_ready (tools/pr_ready.py --quick --base 8ee7236892, against 8ee7236892, 32 s)

Check Result
Scope ✅ 1 files, +70 −1
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 612 passed (32 s)
rustfmt ➖ no Rust change
clippy ➖ no Rust change
tests ➖ no crate touched
doc tests ➖ no crate touched
content root tests ➖ content root untouched
mod API up to date ➖ native hooks 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 skip-release

Label: skip-release.

🤖 Generated with Dyna.


🔄 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/7214 **Author:** [@arismoko](https://github.com/arismoko) **Created:** 11/2/2026 **Status:** ✅ Merged **Merged:** 11/2/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `v2/ses_01M6BECNQ499TYMMBQBDF00VJ5-mixin-docs` --- ### 📝 Commits (5) - [`41074f0`](https://github.com/horizon-rust/horizon/commit/41074f04df34de26ad1ac18c9b7a0fc714b60c1b) docs: the typed API from mixin code - [`28cb0a5`](https://github.com/horizon-rust/horizon/commit/28cb0a51463e1b2f725e4660461dbeaac83562ca) docs: fix the typed API from mixin code examples - [`364297a`](https://github.com/horizon-rust/horizon/commit/364297a363c426780be6480ccec34b8559f1b834) Merge remote-tracking branch 'upstream/main' into mixin-docs - [`32b4236`](https://github.com/horizon-rust/horizon/commit/32b4236c758509ff4f2230af33631e38440a965a) docs: where a mixin module lives, and why the [api] crate keeps its own attachment - [`c1649ac`](https://github.com/horizon-rust/horizon/commit/c1649ac88e3e42f2ef9ecb347eebd4c65944f0ce) Merge remote-tracking branch 'upstream/main' into mixin-docs ### 📊 Changes **1 file changed** (+70 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `docs/native-mods.md` (+70 -1) </details> ### 📄 Description > 🤖 Opened by Aria's agent swarm, Dyna, not by Aria. This PR documents how mixin code uses the typed mod API. It is #6452's "Document the typed API from mixin code" item, and it changes docs only: a new section, "The typed API from mixin code", in `docs/native-mods.md`. ## What it documents - **A helper on a `Game` method.** - Bind `&mut crate::game::Game<'_>` and coerce it to `&mut dyn Host`. `Game` isn't an `AttachmentHost` itself, so this coercion is the step that matters. - Then use attachments and any `Host` helper. - The attachment static lives in a `[[module]]` of the bundle. The doc shows how a module's `file` and `name` give its path (`crate::game::example`). - **A helper on a `GameLevel` method** (`native_random_tick`, `native_tick_block`, `native_perform_bonemeal`, `native_is_bonemeal_success`). - Bind `&mut dyn crate::mod_api::LevelRandomHost`, for attachments and `random()`. - The doc says which level host the hook points pass for scheduling and block writes. - **A trait injection.** - Bind `host: &mut dyn crate::mod_api::Host`, so the `[api]` crate reads `event.host`. - The `[api]` crate depends on horizon-client's library, not on the game executable that helpers and modules are compiled into. So it declares its own `AttachmentType` with the same namespace and name. The pair is the key, so both statics read one value. - **Versioning.** - A catalog hook's trait method, event and return are part of its `hook_version` contract. Later Horizons only add `#[non_exhaustive]` event fields, defaulted trait methods and `Host` methods. - So a mod that uses only catalog hooks and `Host` can set `"hooks"` in its `.hnmod`. - A mod that injects into a raw `target` pins `horizon_revision` instead. - **A link** from "Server attachments" to the new section. It follows Sponge Mixin's model, which the section names: a handler merged into its target class. ## Tested in game Both examples were built from the doc's code as written, adding only a log line each. They were built through the launcher (`horizon-launcher native-build <bundle> --instance horizon --trust-native-code`), so horizon-mixins applied the injections. The bundle: - the `count` helper injected at the HEAD of `Game::tick_mobs`, with `COUNTER` in a `[[module]]` at `crates/horizon-client/src/game.rs`, named `example`; - a `trait_method = "count"` injection at the same target, with the `host` binding, whose `[api]` crate keeps its own `COUNTER` with the same namespace and name. On the single-player server thread, both logged the same level counter, read through the two statics: ``` MIXIN_DOCS helper count=100 MIXIN_DOCS trait count=100 MIXIN_DOCS helper count=200 MIXIN_DOCS trait count=200 … 300, 400, 500, 600, 700, the same on both ``` This ran at 32b4236c75. The head adds only a merge of main, which brings main's new "Testing a trait mod" section beside this one, and changes none of this section's text. The recommended end-to-end route for native mods is [horizon-machine-sample](https://github.com/arismoko/horizon-machine-sample). It wasn't used here: this section's examples are their own bundle, so a throwaway bundle built from the doc was the closer test. ## pr_ready **pr_ready** (`tools/pr_ready.py --quick --base 8ee7236892`, against 8ee7236892, 32 s) | Check | Result | | --- | --- | | Scope | ✅ 1 files, +70 −1 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 612 passed (32 s) | | rustfmt | ➖ no Rust change | | clippy | ➖ no Rust change | | tests | ➖ no crate touched | | doc tests | ➖ no crate touched | | content root tests | ➖ content root untouched | | mod API up to date | ➖ native hooks 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 | `skip-release` | Label: `skip-release`. 🤖 Generated with Dyna. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 06:39:13 +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#7416
No description provided.