[PR #5503] [MERGED] Native mods fire their own advancement criteria triggers #6323

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/5503
Author: @navinor
Created: 10/31/2026
Status: ✅ Merged
Merged: 11/1/2026
Merged by: @ludovic111

Base: main ← Head: feat/mod-advancement-triggers


📝 Commits (4)

  • e103983 Native mods fire their own advancement criteria triggers
  • a484e2b The player predicate sees a burning player on fire
  • 175635b Merge main into #5503 (native_criteria next to main's native_components; both doc sections)
  • 08b3aca rustfmt's module order

📊 Changes

5 files changed (+257 additions, -0 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+1 -0)
📝 crates/horizon-client/src/game/advancements.rs (+2 -0)
➕ crates/horizon-client/src/game/native_criteria.rs (+215 -0)
📝 docs/native-mods.md (+31 -0)
➕ tools/native-hook-fragments/native_criteria.json (+8 -0)

📄 Description

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

What and why

Fixes #5481, the "advancement triggers" item of #4953's "Registration and data" list.

A content mod or a world's data pack can ship an advancement whose criterion names a trigger of the mod's own ("trigger": "mymod:pipe_connected"). Horizon's tree already loads it, since advancements.rs's parse keeps any trigger name. But only the game's own events call Game::trigger, with vanilla's names, so nothing could ever grant it short of /advancement grant. A NeoForge mod registers a CriterionTrigger and calls its SimpleCriterionTrigger.trigger(player, matcher) where its event happens; this PR gives native mods that call.

Game::native_trigger_criterion(uuid, trigger, test) (new file game/native_criteria.rs):

  • fires trigger for the player with that UUID through the existing Game::trigger. Each criterion with that trigger the player hasn't been granted, of an advancement not done yet, goes to the mod's test, then to its player predicate, in vanilla's order and with the player's own context (EntityPredicate.createContext(player, player)). Those that pass are granted, and a completed advancement is awarded like any other: toast, chat line, rewards, saved progress, and the advancement packets for a server's players;
  • gives test a NativeCriterion: the criterion's conditions (Null when absent) and item(key, stack), which tests a stack against the item predicate under key as the game's own triggers read one (items with ids, lists or #tags, count, the potion_contents and damage components, the enchantments and damage predicates), so a mod needn't parse it itself. A missing key passes, as an absent Optional<ItemPredicate> does;
  • reaches the acting player inside their hook, and any player on the server only where no player is swapped in (native_tick, a menu hook), the rule native_run_command follows. That player is reached through for_player, as commands reach other players, so their own level is in place: a location or biome predicate reads where they are, and a reward that doesn't fit drops there. It returns true when the player was reached, whether or not anything was granted, and false otherwise: off an authoritative server, when the player isn't on, and for a minecraft: trigger or a name without a namespace (vanilla's triggers are fired by the game's own events).

It adds an API fragment (tools/native-hook-fragments/native_criteria.json, no new hook point) and an "Advancement triggers" section in docs/native-mods.md with an example advancement file.

Not in this PR: refusing unknown trigger names when advancements load (vanilla's codec drops such a file; Horizon keeps it, before and after), and predicate helpers beyond items (entity, location), which can follow if mods ask.

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

net.minecraft.advancements.triggers.SimpleCriterionTrigger.trigger (the matcher, then SimpleInstance.player() against EntityPredicate.createContext(player, player), then PlayerAdvancements.award). The NeoForge side is the public Registries.TRIGGER_TYPE registration of a CriterionTrigger. No harness: the grant path is the game's existing trigger_criteria.

Other projects' code

none

Self-check

pr_ready (tools/pr_ready.py --quick on Aaron, against origin/main at 97ded1757, 2 min 0 s)

Check Result
Scope ✅ 5 files, +260 −0
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 510 passed (1 min 13 s)
rustfmt ✅ (9 s)
clippy ✅ (8 s)
tests: horizon-client ✅ 1571 passed (25 s)
doc tests ✅ 0 passed (2 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)

Tests:

  • native_criteria::tests::a_mods_criterion_takes_its_own_test_and_the_player_predicate: a criterion reading a #c:ingots/copper item predicate with count min 2 and a player predicate (on fire) passes for a burning player with 2 copper ingots, and fails for a player not on fire, for 1 ingot, and for 2 iron ingots. A criterion without the key, or without any conditions, passes the item test.
  • native_criteria::tests::mods_fire_only_their_own_namespaced_triggers.

In the real game, Windows, with a temporary hook body (not committed) standing in for a mod's injection: native_player_tick fired testmod:holding for the acting player with c.item("item", held), and native_server_tick fired testmod:online for every player from native_server_players(), with a test passing when conditions.mode is "any". A world data pack held these advancements:

  • two_logs (testmod:holding, item #minecraft:logs with count min 2, 7 experience reward);
  • creative_online (testmod:online, mode: any, a player predicate requiring creative);
  • wrong_mode (testmod:online, mode: never);
  • nether_online (testmod:online, mode: any, a player predicate with location.dimension minecraft:the_nether; dedicated server run only).

Starting in survival, on the single player server thread and again on a dedicated server (--dedicated --nogui) with a separate client joining it:

  • one oak log granted nothing; the second gave "Advancement Made! Two Logs" (toast and chat line) and level 1 (7 points);
  • creative_online came only after /gamemode creative ("has reached the goal [Creative Online]"), through the non-acting path;
  • nether_online came only after execute in minecraft:the_nether run tp @s 0 100 0, also through the non-acting path;
  • wrong_mode was never granted, and the saved players/advancements/<uuid>.json held the granted ones, done;
  • minecraft:tick and a UUID nobody has returned false.

🤖 Generated with OpenCode


🔄 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/5503 **Author:** [@navinor](https://github.com/navinor) **Created:** 10/31/2026 **Status:** ✅ Merged **Merged:** 11/1/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `feat/mod-advancement-triggers` --- ### 📝 Commits (4) - [`e103983`](https://github.com/horizon-rust/horizon/commit/e103983b5de604d8304f23a118e72fe913851ff8) Native mods fire their own advancement criteria triggers - [`a484e2b`](https://github.com/horizon-rust/horizon/commit/a484e2b4914f0de107195945ef2e4cb95d52e629) The player predicate sees a burning player on fire - [`175635b`](https://github.com/horizon-rust/horizon/commit/175635b82bb51a432b917ff3d670a18c4b1d2815) Merge main into #5503 (native_criteria next to main's native_components; both doc sections) - [`08b3aca`](https://github.com/horizon-rust/horizon/commit/08b3aca04c06157e8fa8ce14688b2b75bf5c0af9) rustfmt's module order ### 📊 Changes **5 files changed** (+257 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+1 -0) 📝 `crates/horizon-client/src/game/advancements.rs` (+2 -0) ➕ `crates/horizon-client/src/game/native_criteria.rs` (+215 -0) 📝 `docs/native-mods.md` (+31 -0) ➕ `tools/native-hook-fragments/native_criteria.json` (+8 -0) </details> ### 📄 Description > 🤖 Opened by navinor's AI agent (OpenCode, Claude Opus 5.5), not by navinor personally. ## What and why Fixes #5481, the "advancement triggers" item of #4953's "Registration and data" list. A content mod or a world's data pack can ship an advancement whose criterion names a trigger of the mod's own (`"trigger": "mymod:pipe_connected"`). Horizon's tree already loads it, since `advancements.rs`'s `parse` keeps any trigger name. But only the game's own events call `Game::trigger`, with vanilla's names, so nothing could ever grant it short of `/advancement grant`. A NeoForge mod registers a `CriterionTrigger` and calls its `SimpleCriterionTrigger.trigger(player, matcher)` where its event happens; this PR gives native mods that call. `Game::native_trigger_criterion(uuid, trigger, test)` (new file `game/native_criteria.rs`): - fires `trigger` for the player with that UUID through the existing `Game::trigger`. Each criterion with that trigger the player hasn't been granted, of an advancement not done yet, goes to the mod's `test`, then to its `player` predicate, in vanilla's order and with the player's own context (`EntityPredicate.createContext(player, player)`). Those that pass are granted, and a completed advancement is awarded like any other: toast, chat line, rewards, saved progress, and the advancement packets for a server's players; - gives `test` a `NativeCriterion`: the criterion's `conditions` (`Null` when absent) and `item(key, stack)`, which tests a stack against the item predicate under `key` as the game's own triggers read one (`items` with ids, lists or `#tags`, `count`, the `potion_contents` and `damage` components, the `enchantments` and `damage` predicates), so a mod needn't parse it itself. A missing key passes, as an absent `Optional<ItemPredicate>` does; - reaches the acting player inside their hook, and any player on the server only where no player is swapped in (`native_tick`, a menu hook), the rule `native_run_command` follows. That player is reached through `for_player`, as commands reach other players, so their own level is in place: a `location` or biome predicate reads where they are, and a reward that doesn't fit drops there. It returns true when the player was reached, whether or not anything was granted, and false otherwise: off an authoritative server, when the player isn't on, and for a `minecraft:` trigger or a name without a namespace (vanilla's triggers are fired by the game's own events). It adds an API fragment (`tools/native-hook-fragments/native_criteria.json`, no new hook point) and an "Advancement triggers" section in `docs/native-mods.md` with an example advancement file. Not in this PR: refusing unknown trigger names when advancements load (vanilla's codec drops such a file; Horizon keeps it, before and after), and predicate helpers beyond items (entity, location), which can follow if mods ask. ## 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 `net.minecraft.advancements.triggers.SimpleCriterionTrigger.trigger` (the matcher, then `SimpleInstance.player()` against `EntityPredicate.createContext(player, player)`, then `PlayerAdvancements.award`). The NeoForge side is the public `Registries.TRIGGER_TYPE` registration of a `CriterionTrigger`. No harness: the grant path is the game's existing `trigger_criteria`. ## Other projects' code none ## Self-check **pr_ready** (`tools/pr_ready.py --quick` on Aaron, against origin/main at 97ded1757, 2 min 0 s) | Check | Result | | --- | --- | | Scope | ✅ 5 files, +260 −0 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 510 passed (1 min 13 s) | | rustfmt | ✅ (9 s) | | clippy | ✅ (8 s) | | tests: horizon-client | ✅ 1571 passed (25 s) | | doc tests | ✅ 0 passed (2 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) | Tests: - `native_criteria::tests::a_mods_criterion_takes_its_own_test_and_the_player_predicate`: a criterion reading a `#c:ingots/copper` item predicate with `count` min 2 and a `player` predicate (on fire) passes for a burning player with 2 copper ingots, and fails for a player not on fire, for 1 ingot, and for 2 iron ingots. A criterion without the key, or without any conditions, passes the item test. - `native_criteria::tests::mods_fire_only_their_own_namespaced_triggers`. In the real game, Windows, with a temporary hook body (not committed) standing in for a mod's injection: `native_player_tick` fired `testmod:holding` for the acting player with `c.item("item", held)`, and `native_server_tick` fired `testmod:online` for every player from `native_server_players()`, with a test passing when `conditions.mode` is `"any"`. A world data pack held these advancements: - `two_logs` (`testmod:holding`, item `#minecraft:logs` with `count` min 2, 7 experience reward); - `creative_online` (`testmod:online`, `mode: any`, a `player` predicate requiring creative); - `wrong_mode` (`testmod:online`, `mode: never`); - `nether_online` (`testmod:online`, `mode: any`, a `player` predicate with `location.dimension` `minecraft:the_nether`; dedicated server run only). Starting in survival, on the single player server thread and again on a dedicated server (`--dedicated --nogui`) with a separate client joining it: - one oak log granted nothing; the second gave "Advancement Made! Two Logs" (toast and chat line) and level 1 (7 points); - `creative_online` came only after `/gamemode creative` ("has reached the goal [Creative Online]"), through the non-acting path; - `nether_online` came only after `execute in minecraft:the_nether run tp @s 0 100 0`, also through the non-acting path; - `wrong_mode` was never granted, and the saved `players/advancements/<uuid>.json` held the granted ones, done; - `minecraft:tick` and a UUID nobody has returned false. 🤖 Generated with [OpenCode](https://opencode.ai) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 06:18:16 +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#6323
No description provided.