[PR #7430] [MERGED] cargo horizon-mod new --template native: a trait mod to start from #7597

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

📋 Pull Request Information

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

Base: main ← Head: v2/ses_01M6BECNQ499TYMMBQBDF00VJ5-native-template


📝 Commits (3)

  • a848ae0 cargo horizon-mod new: a native trait mod template
  • 010db43 Merge remote-tracking branch 'upstream/main' into native-template
  • 0e6e918 Merge remote-tracking branch 'upstream/main' into native-template

📊 Changes

8 files changed (+182 additions, -8 deletions)

View changed files

📝 Cargo.lock (+1 -0)
📝 crates/cargo-horizon-mod/Cargo.toml (+3 -0)
📝 crates/cargo-horizon-mod/src/main.rs (+133 -7)
➕ crates/cargo-horizon-mod/template/native/api.toml (+9 -0)
➕ crates/cargo-horizon-mod/template/native/horizon-mixin.toml (+9 -0)
➕ crates/cargo-horizon-mod/template/native/lib.rs (+18 -0)
📝 docs/mods.md (+4 -1)
📝 docs/native-mods.md (+5 -0)

📄 Description

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

cargo horizon-mod new --template native: a trait mod to start from. This is #6452's "native template in cargo-horizon-mod" item.

Before, new made content mods only and refused any other --template ("code mods are native"). Starting a native mod meant copying a bundle by hand from docs/native-mods.md.

cargo horizon-mod new hello-mod --template native --horizon <40-hex Horizon commit>

This writes the folder below. It follows docs/api/mod-files.md: these files are what a bundle may carry under mixins/<id>/ of an .hnmod.

hello-mod/
  horizon-mixin.toml   [mod] id/version, [compatibility] horizon_revision, [api] path = "api"
  api/Cargo.toml       package mod-hello_mod, horizon-client at that commit
  api/src/lib.rs       pub fn hooks() -> Box<dyn Hooks>, implementing player_logged_in
  .gitignore
  • The one hook is player_logged_in (NeoForge's PlayerLoggedInEvent). It tells the joining player hello_mod says hello, <name>! through Host::tell. It is chosen because it shows on a server-thread world and on a dedicated server with nothing to set up.
  • --horizon pins the commit in horizon_revision and in the crate's horizon-client git dependency. A value that isn't 40 lowercase hex digits is refused, with the same check the registry uses (index::native::revision). Without --horizon, the pin is left as a commented line, and the folder builds on the instance's own Horizon.
  • horizon-native.json isn't written. The launcher writes it when it packs the folder, filling in the horizon-mixins commit it builds with. The template can't know that commit.
  • The folder builds as it is: horizon-launcher native-build hello-mod --instance <name> --trust-native-code. The tool prints that line after new.
  • docs/mods.md and docs/native-mods.md ("Trait mods") name the new template.

Tests

  • New test, the_native_template_packs_into_an_hnmod_the_registry_accepts:
    • writes the template with a pin;
    • checks that every file passes index::native::allowed;
    • packs the files the way the launcher packs a mod folder (horizon-native.json plus mixins/<id>/…);
    • runs cargo horizon-mod check (the registry's checks) on the .hnmod;
    • checks that a pin that isn't a commit is refused, and that no pin leaves horizon_revision out.
  • The content template's test is unchanged.
  • Cargo.lock gains one line: zip as a dev-dependency of cargo-horizon-mod, at the version horizon-mods already uses.

Tested in game

new hello-mod --template native --horizon 0992fe856f50cb24a1fa5091e62b277d7e807555 ran at 010db43f76. The head only merges main 0de9fbac4 on top of that. The generated folder, unedited, was built through the launcher with native-build --trust-native-code.

  • Server thread: the joining player's chat shows hello_mod says hello, Player05552!.

    The greeting in chat on joining a server-thread world

  • Dedicated server: the same unedited bundle was exported through the launcher as a standalone server (--server-output, then --dedicated). A client joined as Proof, and its chat showed hello_mod says hello, Proof!. This PR changes only the cargo-horizon-mod tool and its docs, not game or server code. The run checks that the template's output works on a server too.

The recommended end-to-end route for native mods is horizon-machine-sample. It wasn't used: the point of this check was to build the template's own output unedited.

pr_ready

Run at head 0e6e918a.

pr_ready (tools/pr_ready.py --quick --base 0de9fbac4 on f2196cc12001, against 0de9fbac4 at 0de9fbac4, 31 min 30 s)

Check Result
Scope ✅ 8 files, +182 −8
Cargo.lock ✅ changes with a Cargo.toml
Public tree ✅
Python tests ✅ 612 passed (33 s)
rustfmt ✅ (7 s)
clippy ✅ (15 s)
tests: workspace ❌ 5086 passed, 6 failed (18 min 57 s)
doc tests ✅ 0 passed (1 min 42 s)
content root tests ✅ 24 passed (4 min 33 s)
mod API up to date ➖ native hooks untouched
tokens.css up to date ➖ theme untouched
launcher rustfmt ✅ (1 s)
launcher clippy ✅ (1 min 55 s)
launcher tests ✅ 445 passed (3 min 27 s)
Parity ➖ 382 affected, to run in CI (--quick): active_effect_tick, active_effects, ambient_sound, anchor, anvil_turtle_egg, armor_stand_frost, armor_stand_turtle_egg, arrow, arrow_wind_charge, attribute_health, attribute_map_queries, attribute and 370 more
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

The 6 failures are horizon-world's piston tests (level::tests::pistons_push_and_sticky_pistons_pull and five more). They fail the same way on main 0de9fbac4 and 0cf1b3d20 on the same machine, with extended reading "", and this PR touches no horizon-world code. They run here only because the Cargo.lock line widens the tests to the whole workspace. This PR's own test (cargo test -p cargo-horizon-mod) passes.

🤖 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/7430 **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-native-template` --- ### 📝 Commits (3) - [`a848ae0`](https://github.com/horizon-rust/horizon/commit/a848ae0be2c6e4b9dd95b2f2781d0650c284c3fa) cargo horizon-mod new: a native trait mod template - [`010db43`](https://github.com/horizon-rust/horizon/commit/010db43f7669de48753d265ab7ade6024dd73383) Merge remote-tracking branch 'upstream/main' into native-template - [`0e6e918`](https://github.com/horizon-rust/horizon/commit/0e6e918a75480db35eaa41cafe60d4b5e665f9f3) Merge remote-tracking branch 'upstream/main' into native-template ### 📊 Changes **8 files changed** (+182 additions, -8 deletions) <details> <summary>View changed files</summary> 📝 `Cargo.lock` (+1 -0) 📝 `crates/cargo-horizon-mod/Cargo.toml` (+3 -0) 📝 `crates/cargo-horizon-mod/src/main.rs` (+133 -7) ➕ `crates/cargo-horizon-mod/template/native/api.toml` (+9 -0) ➕ `crates/cargo-horizon-mod/template/native/horizon-mixin.toml` (+9 -0) ➕ `crates/cargo-horizon-mod/template/native/lib.rs` (+18 -0) 📝 `docs/mods.md` (+4 -1) 📝 `docs/native-mods.md` (+5 -0) </details> ### 📄 Description > 🤖 Opened by Aria's agent swarm, Dyna, not by Aria. **`cargo horizon-mod new --template native`: a trait mod to start from.** This is #6452's "native template in cargo-horizon-mod" item. Before, `new` made content mods only and refused any other `--template` ("code mods are native"). Starting a native mod meant copying a bundle by hand from `docs/native-mods.md`. ```sh cargo horizon-mod new hello-mod --template native --horizon <40-hex Horizon commit> ``` This writes the folder below. It follows [`docs/api/mod-files.md`](docs/api/mod-files.md): these files are what a bundle may carry under `mixins/<id>/` of an `.hnmod`. ``` hello-mod/ horizon-mixin.toml [mod] id/version, [compatibility] horizon_revision, [api] path = "api" api/Cargo.toml package mod-hello_mod, horizon-client at that commit api/src/lib.rs pub fn hooks() -> Box<dyn Hooks>, implementing player_logged_in .gitignore ``` - **The one hook** is `player_logged_in` (NeoForge's `PlayerLoggedInEvent`). It tells the joining player `hello_mod says hello, <name>!` through `Host::tell`. It is chosen because it shows on a server-thread world and on a dedicated server with nothing to set up. - **`--horizon`** pins the commit in `horizon_revision` and in the crate's `horizon-client` git dependency. A value that isn't 40 lowercase hex digits is refused, with the same check the registry uses (`index::native::revision`). Without `--horizon`, the pin is left as a commented line, and the folder builds on the instance's own Horizon. - **`horizon-native.json` isn't written.** The launcher writes it when it packs the folder, filling in the horizon-mixins commit it builds with. The template can't know that commit. - The folder builds as it is: `horizon-launcher native-build hello-mod --instance <name> --trust-native-code`. The tool prints that line after `new`. - `docs/mods.md` and `docs/native-mods.md` ("Trait mods") name the new template. ## Tests - **New test, `the_native_template_packs_into_an_hnmod_the_registry_accepts`:** - writes the template with a pin; - checks that every file passes `index::native::allowed`; - packs the files the way the launcher packs a mod folder (`horizon-native.json` plus `mixins/<id>/…`); - runs `cargo horizon-mod check` (the registry's checks) on the `.hnmod`; - checks that a pin that isn't a commit is refused, and that no pin leaves `horizon_revision` out. - The content template's test is unchanged. - `Cargo.lock` gains one line: `zip` as a dev-dependency of `cargo-horizon-mod`, at the version `horizon-mods` already uses. ## Tested in game `new hello-mod --template native --horizon 0992fe856f50cb24a1fa5091e62b277d7e807555` ran at 010db43f76. The head only merges main 0de9fbac4 on top of that. The generated folder, unedited, was built through the launcher with `native-build --trust-native-code`. - **Server thread:** the joining player's chat shows `hello_mod says hello, Player05552!`. ![The greeting in chat on joining a server-thread world](https://raw.githubusercontent.com/arismoko/horizon/2db2f6588bbc61a0bcffa2cddfecbb4e7b695f4e/native-template-greeting.png) - **Dedicated server:** the same unedited bundle was exported through the launcher as a standalone server (`--server-output`, then `--dedicated`). A client joined as `Proof`, and its chat showed `hello_mod says hello, Proof!`. This PR changes only the `cargo-horizon-mod` tool and its docs, not game or server code. The run checks that the template's output works on a server too. The recommended end-to-end route for native mods is [horizon-machine-sample](https://github.com/arismoko/horizon-machine-sample). It wasn't used: the point of this check was to build the template's own output unedited. ## pr_ready Run at head 0e6e918a. **pr_ready** (`tools/pr_ready.py --quick --base 0de9fbac4` on f2196cc12001, against 0de9fbac4 at 0de9fbac4, 31 min 30 s) | Check | Result | | --- | --- | | Scope | ✅ 8 files, +182 −8 | | Cargo.lock | ✅ changes with a Cargo.toml | | Public tree | ✅ | | Python tests | ✅ 612 passed (33 s) | | rustfmt | ✅ (7 s) | | clippy | ✅ (15 s) | | tests: workspace | ❌ 5086 passed, 6 failed (18 min 57 s) | | doc tests | ✅ 0 passed (1 min 42 s) | | content root tests | ✅ 24 passed (4 min 33 s) | | mod API up to date | ➖ native hooks untouched | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ✅ (1 s) | | launcher clippy | ✅ (1 min 55 s) | | launcher tests | ✅ 445 passed (3 min 27 s) | | Parity | ➖ 382 affected, to run in CI (--quick): active_effect_tick, active_effects, ambient_sound, anchor, anvil_turtle_egg, armor_stand_frost, armor_stand_turtle_egg, arrow, arrow_wind_charge, attribute_health, attribute_map_queries, attribute and 370 more | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | The 6 failures are horizon-world's piston tests (`level::tests::pistons_push_and_sticky_pistons_pull` and five more). They fail the same way on main 0de9fbac4 and 0cf1b3d20 on the same machine, with `extended` reading `""`, and this PR touches no horizon-world code. They run here only because the `Cargo.lock` line widens the tests to the whole workspace. This PR's own test (`cargo test -p cargo-horizon-mod`) passes. 🤖 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 07:20:33 +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#7597
No description provided.