[PR #6972] [MERGED] Native mods: RETURN, MODIFY_ARG and MODIFY_EXPRESSION_VALUE trait injections #7244

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

📋 Pull Request Information

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

Base: main ← Head: v2/ses_01M6DMWRZSPA9JSD7HP0ZN2DNJ-1d979769f9dd


📝 Commits (4)

  • 5780b6c Let trait_method injections return a changed value
  • 760dbcc Test value-changing trait injections
  • d0c6715 Document value-changing trait injections
  • 805ce26 Merge main into #6972

📊 Changes

2 files changed (+210 additions, -56 deletions)

View changed files

📝 docs/native-mods.md (+31 -5)
📝 launcher/src/native_mods/inject.rs (+179 -51)

📄 Description

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

What it does

A trait mod's own injection (trait_method) could be HEAD only, to listen or cancel. It can now also be RETURN, MODIFY_ARG or MODIFY_EXPRESSION_VALUE, so a mod's typed [api] crate can change a returned value, a call argument or an expression's value where no catalog hook covers it. Until now, that logic had to stay in a plain mixin helper outside the typed crate, because a helper compiled into horizon-client sees trait mods only as dyn Hooks.

The binding whose value is $value becomes a plain field of the generated event (InjectExamplePointsEvent { points }). The trait method changes it in place, and the generated helper returns it. As with HEAD injections, only the declaring mod's Hooks object is called, other &mut scalar bindings are written back, and the value passes through unchanged before the mods are installed. Selectors, require, ordinal and argument are horizon-mixins' own fields, so horizon-mixins still checks the site, the value's type and the chain order (priority, mod id, injection id). The launcher now rejects a value kind with no $value binding, cancellable on a non-HEAD kind, and any other kind.

Only the launcher's trait-injection generator (launcher/src/native_mods/inject.rs) and the trait-mod section of docs/native-mods.md change. The game, xtask and horizon-mixins are unchanged. The generator reuses the existing event and lifetime rules, owner lookup, helper staging and stage. A Contract enum (listen, cancel, value) replaces the cancellable flag.

[[injection]]
id = "double"
target = "horizon_client::game::commands::Game<'_>::change_experience"
kind = "MODIFY_ARG"
selector = "self.give_points"
require = 1
ordinal = 0
argument = 0
trait_method = "double"
bindings = [{ name = "points", ty = "i32", value = "$value" }]
fn inject_example_double(&self, event: &mut InjectExampleDoubleEvent) {
    event.points *= 2;
}

Mixin counterpart

There is no NeoForge event for this: it is the Mixin side of the API.

  • RETURN: @Inject at @At("RETURN") with CallbackInfoReturnable#setReturnValue. MixinExtras' chaining @ModifyReturnValue is closer, since it receives the returned value and returns the adjusted one.
  • MODIFY_ARG: Mixin's @ModifyArg.
  • MODIFY_EXPRESSION_VALUE: MixinExtras' @ModifyExpressionValue.

References: injection points, MixinExtras. Cancellable value kinds are left out; horizon-mixins allows cancellation only on HEAD and the interior call/assign hooks.

Part of #6452 ("Value-changing trait injections").

Tests

  • value_injection_returns_what_the_owner_changed compiles and runs the generated RETURN helper and event. Before install the value is unchanged; after install the owner's change is returned, a scalar binding is written back, and the non-owner is never called.
  • trait_injection_kinds_are_checked covers the rejected kinds and fields.
  • The existing HEAD listen and cancel test is unchanged.

Tested in game

At this head (d0c6715e0b), the launcher's native-build built a throwaway trait mod with three injections on the /experience command's change_experience, and the game ran it on the server thread (integrated world, creative):

Kind What the mod does Result
MODIFY_ARG doubles the points given ✅ /xp add @s 2 points → /xp query shows 4 points (VALUE_PROBE double in=2 out=4)
MODIFY_EXPRESSION_VALUE adds 10 to the new level ✅ from 0, /xp add @s 1 levels → 11 levels (VALUE_PROBE bonus in=1 out=11)
RETURN refuses the 13-level add ✅ /xp add @s 13 levels gave vanilla's "Cannot set experience points above the maximum…" failure instead of success (VALUE_PROBE refuse in=true out=false)

The same build ran as a dedicated server (--dedicated --nogui) with a client joined, with the same three results.

Regression: https://github.com/arismoko/horizon-machine-sample (the recommended end-to-end route, used here), rebuilt by the same launcher at this head, still turned 4 cobblestone into 4 stone on the server thread and on the dedicated server. (The sample itself needed own_background: false added for #6641, which is unrelated to this PR.)

pr_ready

pr_ready (tools/pr_ready.py --quick --base cabe8b5de7d0b45541c923c4a6b3c5cb3e3686c7 at d0c6715e0b, 1 min 43 s)

Check Result
Scope ✅ 2 files, +210 −56
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ❌ 610 run, FAILED (failures=1, skipped=1) (40 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 ✅ (1 s)
launcher clippy ✅ (19 s)
launcher tests ✅ 445 passed (43 s)
Parity ➖ 377 affected, to run in CI (--quick)
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

The one Python failure is test_world_input_capture.test_native_split_mouse_turns_only_its_owner. It fails the same way at the base, cabe8b5de, without this change, and this PR touches no Python or game code.

🤖 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/6972 **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_01M6DMWRZSPA9JSD7HP0ZN2DNJ-1d979769f9dd` --- ### 📝 Commits (4) - [`5780b6c`](https://github.com/horizon-rust/horizon/commit/5780b6c9407c5e15b0351c2d2a0c624088c57617) Let trait_method injections return a changed value - [`760dbcc`](https://github.com/horizon-rust/horizon/commit/760dbcc535160689b2074f5e4b183c45252533a2) Test value-changing trait injections - [`d0c6715`](https://github.com/horizon-rust/horizon/commit/d0c6715e0bb342285fe9a78afd03251952aa539e) Document value-changing trait injections - [`805ce26`](https://github.com/horizon-rust/horizon/commit/805ce265cd353554049a758b0e82b1abf28ba786) Merge main into #6972 ### 📊 Changes **2 files changed** (+210 additions, -56 deletions) <details> <summary>View changed files</summary> 📝 `docs/native-mods.md` (+31 -5) 📝 `launcher/src/native_mods/inject.rs` (+179 -51) </details> ### 📄 Description > 🤖 Opened by Aria's agent swarm, Dyna, not by Aria. ## What it does A trait mod's own injection (`trait_method`) could be HEAD only, to listen or cancel. It can now also be `RETURN`, `MODIFY_ARG` or `MODIFY_EXPRESSION_VALUE`, so a mod's typed `[api]` crate can change a returned value, a call argument or an expression's value where no catalog hook covers it. Until now, that logic had to stay in a plain mixin helper outside the typed crate, because a helper compiled into `horizon-client` sees trait mods only as `dyn Hooks`. The binding whose value is `$value` becomes a plain field of the generated event (`InjectExamplePointsEvent { points }`). The trait method changes it in place, and the generated helper returns it. As with HEAD injections, only the declaring mod's `Hooks` object is called, other `&mut` scalar bindings are written back, and the value passes through unchanged before the mods are installed. Selectors, `require`, `ordinal` and `argument` are horizon-mixins' own fields, so horizon-mixins still checks the site, the value's type and the chain order (priority, mod id, injection id). The launcher now rejects a value kind with no `$value` binding, `cancellable` on a non-HEAD kind, and any other kind. Only the launcher's trait-injection generator (`launcher/src/native_mods/inject.rs`) and the trait-mod section of `docs/native-mods.md` change. The game, xtask and horizon-mixins are unchanged. The generator reuses the existing event and lifetime rules, owner lookup, helper staging and `stage`. A `Contract` enum (listen, cancel, value) replaces the `cancellable` flag. ```toml [[injection]] id = "double" target = "horizon_client::game::commands::Game<'_>::change_experience" kind = "MODIFY_ARG" selector = "self.give_points" require = 1 ordinal = 0 argument = 0 trait_method = "double" bindings = [{ name = "points", ty = "i32", value = "$value" }] ``` ```rust fn inject_example_double(&self, event: &mut InjectExampleDoubleEvent) { event.points *= 2; } ``` ## Mixin counterpart There is no NeoForge event for this: it is the Mixin side of the API. - `RETURN`: `@Inject` at `@At("RETURN")` with `CallbackInfoReturnable#setReturnValue`. MixinExtras' chaining `@ModifyReturnValue` is closer, since it receives the returned value and returns the adjusted one. - `MODIFY_ARG`: Mixin's `@ModifyArg`. - `MODIFY_EXPRESSION_VALUE`: MixinExtras' `@ModifyExpressionValue`. References: [injection points](https://github.com/SpongePowered/Mixin/wiki/Injection-Point-Reference), [MixinExtras](https://github.com/LlamaLad7/MixinExtras/wiki). Cancellable value kinds are left out; horizon-mixins allows cancellation only on HEAD and the interior call/assign hooks. Part of #6452 ("Value-changing trait injections"). ## Tests - `value_injection_returns_what_the_owner_changed` compiles and runs the generated RETURN helper and event. Before install the value is unchanged; after install the owner's change is returned, a scalar binding is written back, and the non-owner is never called. - `trait_injection_kinds_are_checked` covers the rejected kinds and fields. - The existing HEAD listen and cancel test is unchanged. ## Tested in game At this head (d0c6715e0b), the launcher's `native-build` built a throwaway trait mod with three injections on the `/experience` command's `change_experience`, and the game ran it on the server thread (integrated world, creative): | Kind | What the mod does | Result | | --- | --- | --- | | `MODIFY_ARG` | doubles the points given | ✅ `/xp add @s 2 points` → `/xp query` shows 4 points (`VALUE_PROBE double in=2 out=4`) | | `MODIFY_EXPRESSION_VALUE` | adds 10 to the new level | ✅ from 0, `/xp add @s 1 levels` → 11 levels (`VALUE_PROBE bonus in=1 out=11`) | | `RETURN` | refuses the 13-level add | ✅ `/xp add @s 13 levels` gave vanilla's "Cannot set experience points above the maximum…" failure instead of success (`VALUE_PROBE refuse in=true out=false`) | The same build ran as a dedicated server (`--dedicated --nogui`) with a client joined, with the same three results. Regression: https://github.com/arismoko/horizon-machine-sample (the recommended end-to-end route, used here), rebuilt by the same launcher at this head, still turned 4 cobblestone into 4 stone on the server thread and on the dedicated server. (The sample itself needed `own_background: false` added for #6641, which is unrelated to this PR.) ## pr_ready **pr_ready** (`tools/pr_ready.py --quick --base cabe8b5de7d0b45541c923c4a6b3c5cb3e3686c7` at d0c6715e0b, 1 min 43 s) | Check | Result | | --- | --- | | Scope | ✅ 2 files, +210 −56 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ❌ 610 run, FAILED (failures=1, skipped=1) (40 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 | ✅ (1 s) | | launcher clippy | ✅ (19 s) | | launcher tests | ✅ 445 passed (43 s) | | Parity | ➖ 377 affected, to run in CI (--quick) | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | The one Python failure is `test_world_input_capture.test_native_split_mouse_turns_only_its_owner`. It fails the same way at the base, cabe8b5de, without this change, and this PR touches no Python or game code. 🤖 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:36:18 +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#7244
No description provided.