[PR #7657] Two dyes mix by the recipe that combines them: a test for the breeding colour #7743

Open
opened 2026-11-03 07:23:30 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/7657
Author: @MSedgeMC
Created: 11/2/2026
Status: 🔄 Open

Base: main ← Head: test/dye-color-mix


📝 Commits (3)

  • d435ad7 dye_mix: the two DyeColor lookups are free functions
  • 775472a test: two dyes mix by the crafting recipe that combines them
  • b1b2929 port_map: the dye mix rows name the free functions

📊 Changes

3 files changed (+107 additions, -36 deletions)

View changed files

📝 crates/horizon-client/src/game/creatures.rs (+104 -33)
📝 tools/port_map/game2-008.tsv (+2 -2)
📝 tools/port_map/rest-008.tsv (+1 -1)

📄 Description

Vanilla

DyeColor.getMixedColor(ServerLevel, DyeColor, DyeColor) asks findColorMixInRecipes first and falls back to level.getRandom().nextBoolean() ? first : second. findColorMixInRecipes collects the items that carry a DYE component of each colour, lays the two in a CraftingInput.of(2, 1, ...) and asks the recipe manager for it; the assembled result's DYE component is the answer. Sheep.getBreedOffspring, Cat.getBreedOffspring and Wolf.getBreedOffspring colour the offspring with it, so a lamb born to two dyed parents wears the colour of the recipe that would mix their dyes (red + yellow is orange, blue + green cyan, blue + red purple, green + white lime).

What Horizon got wrong

Nothing behaviourally: game/creatures.rs already had both steps, wired into all three breed paths. But they were methods on Game, so no unit test could reach them without building a whole game, and the ledger rows have said port with no test behind them.

This PR is the test, plus the move that lets it reach the game's own code path: dye_mix(recipes, random, a, b) and dye_color_mix_in_recipes(recipes, a, b) are now free functions in game/creatures.rs, and the three breed call sites pass self.res.recipes() and &mut self.world.random — the same values the methods read, no behaviour change. tools/port_map/game2-008.tsv:57, :58 and rest-008.tsv:81 name the new functions.

Tests

game::creatures::dye_mix_tests::two_dyes_mix_by_their_crafting_recipe builds the recipe table from the prepared data (.local/horizon-client/26.3, skipped without it, like the data tests beside it) and calls dye_mix — the function the breed path calls, not a helper written for the test — for four pairs vanilla ships a two-dye recipe for, then for orange + cyan, which has none, where it must keep one of the two.

Fails without the fix, through the path the game calls: with the recipe lookup taken out of dye_color_mix_in_recipes (recipes.find(&grid, 2) made to answer nothing, which is the whole mix), the first pair fails:

assertion `left == right` failed: red + yellow makes orange
  left: None
 right: Some(1)

Some(1) is orange — the recipe's answer — so the test proves the recipe is what decides the offspring's colour, not the coin. Checked against the shipped data/minecraft/recipe/*.json (red_dye + yellow_dye → 2 orange_dye, blue_dye + green_dye → 2 cyan_dye, blue_dye + red_dye → 2 purple_dye, green_dye + white_dye → 2 lime_dye).

Not proven: the breed call sites themselves (which mob gets which colour) are not driven; the test starts at the colour function they call. Items/BlockFacts/the registry come from the prepared data, so the test skips on a checkout without .local; I ran the same assertions here against the four shipped recipe files with Items::for_tests, which is how the left: None / right: Some(1) above was measured.

cargo clippy -q -p horizon-client --lib is silent, cargo fmt --all -- --check is clean, and cargo test -q -p horizon-client --lib passes (694 passed, 5 ignored).


🔄 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/7657 **Author:** [@MSedgeMC](https://github.com/MSedgeMC) **Created:** 11/2/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `test/dye-color-mix` --- ### 📝 Commits (3) - [`d435ad7`](https://github.com/horizon-rust/horizon/commit/d435ad75cf137feeaaca5204bfc5231f88eb4a30) dye_mix: the two DyeColor lookups are free functions - [`775472a`](https://github.com/horizon-rust/horizon/commit/775472a053b835ff5620e79f76091c76f43f4624) test: two dyes mix by the crafting recipe that combines them - [`b1b2929`](https://github.com/horizon-rust/horizon/commit/b1b292900634b4d9b720a3dbf378976506a15f40) port_map: the dye mix rows name the free functions ### 📊 Changes **3 files changed** (+107 additions, -36 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game/creatures.rs` (+104 -33) 📝 `tools/port_map/game2-008.tsv` (+2 -2) 📝 `tools/port_map/rest-008.tsv` (+1 -1) </details> ### 📄 Description ## Vanilla `DyeColor.getMixedColor(ServerLevel, DyeColor, DyeColor)` asks `findColorMixInRecipes` first and falls back to `level.getRandom().nextBoolean() ? first : second`. `findColorMixInRecipes` collects the items that carry a `DYE` component of each colour, lays the two in a `CraftingInput.of(2, 1, ...)` and asks the recipe manager for it; the assembled result's `DYE` component is the answer. `Sheep.getBreedOffspring`, `Cat.getBreedOffspring` and `Wolf.getBreedOffspring` colour the offspring with it, so a lamb born to two dyed parents wears the colour of the recipe that would mix their dyes (red + yellow is orange, blue + green cyan, blue + red purple, green + white lime). ## What Horizon got wrong Nothing behaviourally: `game/creatures.rs` already had both steps, wired into all three breed paths. But they were methods on `Game`, so no unit test could reach them without building a whole game, and the ledger rows have said `port` with no test behind them. This PR is the test, plus the move that lets it reach the game's own code path: `dye_mix(recipes, random, a, b)` and `dye_color_mix_in_recipes(recipes, a, b)` are now free functions in `game/creatures.rs`, and the three breed call sites pass `self.res.recipes()` and `&mut self.world.random` — the same values the methods read, no behaviour change. `tools/port_map/game2-008.tsv:57`, `:58` and `rest-008.tsv:81` name the new functions. ## Tests `game::creatures::dye_mix_tests::two_dyes_mix_by_their_crafting_recipe` builds the recipe table from the prepared data (`.local/horizon-client/26.3`, skipped without it, like the data tests beside it) and calls `dye_mix` — the function the breed path calls, not a helper written for the test — for four pairs vanilla ships a two-dye recipe for, then for orange + cyan, which has none, where it must keep one of the two. **Fails without the fix, through the path the game calls:** with the recipe lookup taken out of `dye_color_mix_in_recipes` (`recipes.find(&grid, 2)` made to answer nothing, which is the whole mix), the first pair fails: ``` assertion `left == right` failed: red + yellow makes orange left: None right: Some(1) ``` `Some(1)` is orange — the recipe's answer — so the test proves the recipe is what decides the offspring's colour, not the coin. Checked against the shipped `data/minecraft/recipe/*.json` (`red_dye` + `yellow_dye` → 2 `orange_dye`, `blue_dye` + `green_dye` → 2 `cyan_dye`, `blue_dye` + `red_dye` → 2 `purple_dye`, `green_dye` + `white_dye` → 2 `lime_dye`). **Not proven:** the breed call sites themselves (which mob gets which colour) are not driven; the test starts at the colour function they call. `Items`/`BlockFacts`/the registry come from the prepared data, so the test skips on a checkout without `.local`; I ran the same assertions here against the four shipped recipe files with `Items::for_tests`, which is how the `left: None / right: Some(1)` above was measured. `cargo clippy -q -p horizon-client --lib` is silent, `cargo fmt --all -- --check` is clean, and `cargo test -q -p horizon-client --lib` passes (694 passed, 5 ignored). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
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#7743
No description provided.