[GH-ISSUE #5027] Data packs: content_overlay ignores selected priority order, including after /reload #1525

Closed
opened 2026-11-02 15:47:42 +07:00 by bsakaguchi · 2 comments
Owner

Originally created by @Sugarl0ve on GitHub (Oct 31, 2026).
Original GitHub issue: https://github.com/horizon-rust/horizon/issues/5027

Originally assigned to: @Joansitoh on GitHub.

Summary

content_overlay() applies enabled data packs in alphabetical filename order instead of the priority order selected by the player.

When multiple data packs override the same recipe, the wrong pack may win, including after executing /reload in a running game.

Confirmed on main at commit 03fc2d3f2. The issue was also reproduced on 3d1b94f97.

Root cause

In crates/horizon-client/src/game/functions.rs, content_overlay() iterates through stack.packs and only filters for IDs present in stack.enabled.

However:

  • datapack::discover() sorts stack.packs alphabetically by pack ID.
  • stack.enabled stores the user-selected priority order, lowest to highest.
  • Filtering stack.packs preserves alphabetical order rather than the selected order.
  • DataStore::load() collects conflicting resources in that order, and PackOverlay::top() selects the final file.

As a result, the wrong override wins when the selected priority differs from filename order.

Steps to reproduce

  1. Create two data packs overriding the same crafting recipe ID:
    • a.zip (pack A): one stone crafts into 1 diamond.
    • z.zip (pack Z): one stone crafts into 2 emeralds.
  2. Install both in the world's datapacks/ directory.
  3. Set the enabled order to file/a.zip, then file/z.zip (Z has higher priority).
  4. Load the world and check the crafting result.
  5. Reverse the enabled order to file/z.zip, then file/a.zip (A has higher priority).
  6. Execute /reload and check the crafting result again.

Expected behavior

  • Order A → Z: the recipe produces 2 emeralds.
  • Order Z → A: the recipe produces 1 diamond.
  • /reload applies the new priority without restarting the game.

Actual behavior

  • Order A → Z: 2 emeralds — correct.
  • Order Z → A: 2 emeralds — incorrect.
  • After /reload, the unpatched game still produces 2 emeralds instead of 1 diamond.

The issue persists because the alphabetically last pack is applied last regardless of the selected priority.

Verification results

The regression suite used Horizon's real content_overlay(), Recipes::load(), and crafting-grid recipe matching.

Verification Unpatched main With minimal patch
Rust regression tests 5 passed, 3 failed (exit 101) 8 passed, 0 failed (exit 0)
In-game /reload scenarios 8/10 passed 10/10 passed
Reversed priority Z → A Wrong recipe: 2 emeralds Correct recipe: 1 diamond

The in-game verification launched the actual Horizon binary using Minecraft 26.3 resources, a world, server thread, and a connected headless client.

The real /reload command was executed, with reload messages and successful callbacks confirmed. The unpatched scenario was reproduced twice with the same result.

Additional validation passed:

  • 365 game binary tests.
  • 9 recipe tests.
  • 7 data-pack tests.
  • Formatting and git diff --check.
  • 4 tests were skipped as expected.

The regression suite also covered disabling individual packs, disabling both packs, re-reading changed recipes, and loading saved pack settings in a new Rust process.

Minimal fix

Replace the alphabetical iteration in content_overlay() with iteration over stack.enabled:

 let packs: Vec<&DataPack> = stack
-    .packs
+    .enabled
     .iter()
-    .filter(|p| stack.enabled.contains(&p.id))
+    .filter_map(|id| stack.packs.iter().find(|p| &p.id == id))
     .collect();

This follows the priority order already used by other data-pack loading paths.

Related: #3300 introduced data-pack content overlays for recipes, loot tables, advancements, and tags.

Originally created by @Sugarl0ve on GitHub (Oct 31, 2026). Original GitHub issue: https://github.com/horizon-rust/horizon/issues/5027 Originally assigned to: @Joansitoh on GitHub. ## Summary `content_overlay()` applies enabled data packs in alphabetical filename order instead of the priority order selected by the player. When multiple data packs override the same recipe, the wrong pack may win, including after executing `/reload` in a running game. **Confirmed on `main` at commit `03fc2d3f2`.** The issue was also reproduced on `3d1b94f97`. ## Root cause In `crates/horizon-client/src/game/functions.rs`, `content_overlay()` iterates through `stack.packs` and only filters for IDs present in `stack.enabled`. However: - `datapack::discover()` sorts `stack.packs` alphabetically by pack ID. - `stack.enabled` stores the user-selected priority order, lowest to highest. - Filtering `stack.packs` preserves alphabetical order rather than the selected order. - `DataStore::load()` collects conflicting resources in that order, and `PackOverlay::top()` selects the final file. As a result, the wrong override wins when the selected priority differs from filename order. ## Steps to reproduce 1. Create two data packs overriding the same crafting recipe ID: - `a.zip` (pack A): one stone crafts into **1 diamond**. - `z.zip` (pack Z): one stone crafts into **2 emeralds**. 2. Install both in the world's `datapacks/` directory. 3. Set the enabled order to `file/a.zip`, then `file/z.zip` (Z has higher priority). 4. Load the world and check the crafting result. 5. Reverse the enabled order to `file/z.zip`, then `file/a.zip` (A has higher priority). 6. Execute `/reload` and check the crafting result again. ## Expected behavior - Order A → Z: the recipe produces **2 emeralds**. - Order Z → A: the recipe produces **1 diamond**. - `/reload` applies the new priority without restarting the game. ## Actual behavior - Order A → Z: **2 emeralds** — correct. - Order Z → A: **2 emeralds** — incorrect. - After `/reload`, the unpatched game still produces **2 emeralds** instead of 1 diamond. The issue persists because the alphabetically last pack is applied last regardless of the selected priority. ## Verification results The regression suite used Horizon's real `content_overlay()`, `Recipes::load()`, and crafting-grid recipe matching. | Verification | Unpatched main | With minimal patch | |---|---|---| | Rust regression tests | 5 passed, 3 failed (exit 101) | 8 passed, 0 failed (exit 0) | | In-game `/reload` scenarios | 8/10 passed | 10/10 passed | | Reversed priority Z → A | Wrong recipe: 2 emeralds | Correct recipe: 1 diamond | The in-game verification launched the actual Horizon binary using Minecraft 26.3 resources, a world, server thread, and a connected headless client. The real `/reload` command was executed, with reload messages and successful callbacks confirmed. The unpatched scenario was reproduced twice with the same result. Additional validation passed: - 365 game binary tests. - 9 recipe tests. - 7 data-pack tests. - Formatting and `git diff --check`. - 4 tests were skipped as expected. The regression suite also covered disabling individual packs, disabling both packs, re-reading changed recipes, and loading saved pack settings in a new Rust process. ## Minimal fix Replace the alphabetical iteration in `content_overlay()` with iteration over `stack.enabled`: ~~~diff let packs: Vec<&DataPack> = stack - .packs + .enabled .iter() - .filter(|p| stack.enabled.contains(&p.id)) + .filter_map(|id| stack.packs.iter().find(|p| &p.id == id)) .collect(); ~~~ This follows the priority order already used by other data-pack loading paths. Related: #3300 introduced data-pack content overlays for recipes, loot tables, advancements, and tags.
Author
Owner

@ludovicthenot commented on GitHub (Oct 31, 2026):

🤖 Agent: by ludovicthenot's AI agent (Claude Code, Claude Opus 5.5), not by ludovicthenot personally.

@Sugarl0ve you already have the fix and the regression tests, so this should be your PR. Would you like to open it? If you'd rather not, say so and I'll take it, crediting your diagnosis and tests.

<!-- gh-comment-id:6542606175 --> @ludovicthenot commented on GitHub (Oct 31, 2026): 🤖 Agent: by ludovicthenot's AI agent (Claude Code, Claude Opus 5.5), not by ludovicthenot personally. @Sugarl0ve you already have the fix and the regression tests, so this should be your PR. Would you like to open it? If you'd rather not, say so and I'll take it, crediting your diagnosis and tests.
Author
Owner

@Joansitoh commented on GitHub (Oct 31, 2026):

🤖 Agent: /claim

Claimed by Joansitoh's AI agent (Claude Code, Sonnet 5.5), not by Joansitoh personally.

Cause: content_overlay (crates/horizon-client/src/game/functions.rs:104-108) builds its pack list from stack.packs.iter().filter(enabled), so it follows discovery order, while rebuild_store (same file, ~160-178) already walks stack.enabled in the selected order. Vanilla keeps an ordered selected list (PackRepository.selected, getSelectedPacks/openAllSelected), later packs override earlier ones.

Plan: iterate stack.enabled and map each id to its pack in content_overlay (shared helper with rebuild_store), add a regression test with two packs overriding the same file in both orders. content_overlay has two callers (game.rs, game/advancements.rs), both fixed by this. Will rebase over #5069 if it lands first.

<!-- gh-comment-id:6546454651 --> @Joansitoh commented on GitHub (Oct 31, 2026): 🤖 Agent: /claim Claimed by Joansitoh's AI agent (Claude Code, Sonnet 5.5), not by Joansitoh personally. Cause: `content_overlay` (`crates/horizon-client/src/game/functions.rs:104-108`) builds its pack list from `stack.packs.iter().filter(enabled)`, so it follows discovery order, while `rebuild_store` (same file, ~160-178) already walks `stack.enabled` in the selected order. Vanilla keeps an ordered selected list (`PackRepository.selected`, `getSelectedPacks`/`openAllSelected`), later packs override earlier ones. Plan: iterate `stack.enabled` and map each id to its pack in `content_overlay` (shared helper with `rebuild_store`), add a regression test with two packs overriding the same file in both orders. `content_overlay` has two callers (`game.rs`, `game/advancements.rs`), both fixed by this. Will rebase over #5069 if it lands first.
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#1525
No description provided.