[PR #53] [MERGED] Villager trading to vanilla parity (offers, prices, menu, network, NBT) #2301

Closed
opened 2026-11-02 15:54:46 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/53
Author: @ludovic111
Created: 10/13/2026
Status: ✅ Merged
Merged: 10/13/2026
Merged by: @ludovic111

Base: main ← Head: trading


📝 Commits (6)

  • a3dd34a Trading parity harness: offers, prices, restocks, the merchant menu and NBT against vanilla
  • 43cff3b Trade in game through the verified merchant menu
  • 5cb14ee Trade over the network: LAN guests and Horizon as a client
  • 92209dd Trading on the dedicated server, compared with vanilla's
  • 393d113 Merchant screen: the restock tooltip over an out-of-stock result
  • c810a32 Wandering traders trade again: only villagers refuse while asleep

📊 Changes

30 files changed (+3541 additions, -464 deletions)

View changed files

📝 crates/horizon-client/examples/cauldron_fixture.rs (+1 -0)
📝 crates/horizon-client/examples/menu_fixture.rs (+1 -0)
📝 crates/horizon-client/examples/place_recipe_fixture.rs (+1 -0)
➕ crates/horizon-client/examples/trading_fixture.rs (+548 -0)
📝 crates/horizon-client/src/crafting.rs (+1 -1)
📝 crates/horizon-client/src/entity_nbt.rs (+75 -39)
📝 crates/horizon-client/src/game.rs (+56 -3)
📝 crates/horizon-client/src/game/creatures.rs (+1 -0)
📝 crates/horizon-client/src/game/lan_actions.rs (+17 -1)
➕ crates/horizon-client/src/game/lan_trading.rs (+409 -0)
📝 crates/horizon-client/src/game/maps.rs (+18 -0)
📝 crates/horizon-client/src/game/potions.rs (+0 -3)
📝 crates/horizon-client/src/game/remote.rs (+85 -3)
📝 crates/horizon-client/src/game/stations.rs (+26 -6)
📝 crates/horizon-client/src/game/trading.rs (+363 -218)
📝 crates/horizon-client/src/game/villagers.rs (+10 -3)
📝 crates/horizon-client/src/item_data.rs (+6 -4)
📝 crates/horizon-client/src/lan/containers.rs (+21 -0)
📝 crates/horizon-client/src/lan/guest.rs (+25 -0)
📝 crates/horizon-client/src/menu.rs (+228 -14)

...and 10 more files

📄 Description

Villager trading to vanilla parity (reported: trading didn't work in v2026.10.13.1). Single-player trading opened, but generation, prices, the menu and the network side were not vanilla, and LAN/dedicated players couldn't trade at all.

What changed

  • Generation (merchant.rs): every trade-set modifier vanilla uses — random dyes, random potions (#tradeable), suspicious stew effects, exploration maps (found through the generator's /locate, new filled map with its target decoration), sum/binomial number providers, max uses / xp / discount providers in vanilla's order. Offers draw from the world's RandomSequences, now saved as data/minecraft/random_sequences.dat. The villager type is namespaced, so desert/snow/... only trades appear; the loot origin is the villager.
  • Menu: a Merchant kind in the verified menu engine (menu.rs) over a merchant::Session: MerchantContainer/updateSellItem (selection hint rules of getRecipeFor), MerchantResultSlot, quick move, tryMoveItems, close (carried stack then payment). The game routes the trading screen through it.
  • Merchant: notifyTrade / rewardTradeXp with the merchant's own random (orbs at the villager, yes/no voice pitch draws), level-ups with new offers while the screen is open plus regeneration, TRADE reputation event a tick later (one per tick), special prices kept after closing (as vanilla). Wandering traders, babies, sleeping villagers, unhappy head shake.
  • NBT: Offers as MerchantOffers.CODEC (defaults left out, empty list omitted), Xp / LastRestock / RestocksToday kept even before offers exist; suspicious stew default duration left out.
  • Network: MerchantOffers / SelectTrade packets. LAN host and dedicated server open the trading window for the guest who right-clicked (OpenScreen with vanilla's display-name title, offers, clicks on the merchant menu, reputation by guest UUID). As a client, Horizon shows a server's trading window. Stored enchantments, dyed colours and map ids now go over the wire.
  • Screen: the out-of-stock restock tooltip.

Harnesses

  • New test_trading_parity.py (VanillaTradingOracle on a real flat vanilla server vs trading_fixture): 5,364 cases, 28,358 lines, 0 differences — offers of every profession × type × level across seeds and wandering traders with the shared sequences (gen 1864), updateSpecialPrices under gossip/Hero/demand (1000), restocks over days (600), full trading-screen sessions with clicks, level-ups, orbs and the merchant random (1500), NBT round trip (400).
  • test_dedicated_server_parity.py now right-clicks a summoned librarian: OpenScreen + MerchantOffers identical to vanilla's server (541 lines identical).
  • Regression: trading, mob_ai, finalize_spawn, menu_click, place_recipe, cauldron, entity_death_loot, datafix ×6, command_exec, lan, natural_spawn, raid, recipe_book, enchanting, dispenser, spawn_rules (21 passed on macmini) and save_roundtrip (passed locally); gate.py --quick passes; cargo tests pass.

Checked in game (vscreen)

Librarian: trading screen opens, paper → emerald trades (shift-click), XP bar, level-up to Apprentice with new offers and the trade-reputation discount; offers and XP persist across reopen; wandering trader screen.

Not done / limits

  • No merchant-screen drawing harness (the screen was checked against MerchantScreen by reading; the loom/crafter screen harness could be extended).
  • Exploration maps: the flat oracle world finds no structures, so only "none found" is compared; in game the map has its id and target decoration but no pre-rendered biome preview.
  • LAN guests: no Hero of the Village for guests; a second Horizon client in a vscreen test rendered black and a guest's /tp @s moved the host (pre-existing LAN issues, not touched).

🤖 Generated with Claude Code


🔄 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/53 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/13/2026 **Status:** ✅ Merged **Merged:** 10/13/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `trading` --- ### 📝 Commits (6) - [`a3dd34a`](https://github.com/horizon-rust/horizon/commit/a3dd34a8f3e6d7f77c26d940051d220d995e9cfc) Trading parity harness: offers, prices, restocks, the merchant menu and NBT against vanilla - [`43cff3b`](https://github.com/horizon-rust/horizon/commit/43cff3b44e1c9c447664d667316c40d5e52ae40c) Trade in game through the verified merchant menu - [`5cb14ee`](https://github.com/horizon-rust/horizon/commit/5cb14ee4963001abc3959ddeec6ba68bb06f72eb) Trade over the network: LAN guests and Horizon as a client - [`92209dd`](https://github.com/horizon-rust/horizon/commit/92209ddeee57823e860fb08430c8f7e857d6b2a8) Trading on the dedicated server, compared with vanilla's - [`393d113`](https://github.com/horizon-rust/horizon/commit/393d113dfb79fc724e2281d379e510c0cb03f941) Merchant screen: the restock tooltip over an out-of-stock result - [`c810a32`](https://github.com/horizon-rust/horizon/commit/c810a3213cb87d749bd158cab4a3649db4dd8894) Wandering traders trade again: only villagers refuse while asleep ### 📊 Changes **30 files changed** (+3541 additions, -464 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/examples/cauldron_fixture.rs` (+1 -0) 📝 `crates/horizon-client/examples/menu_fixture.rs` (+1 -0) 📝 `crates/horizon-client/examples/place_recipe_fixture.rs` (+1 -0) ➕ `crates/horizon-client/examples/trading_fixture.rs` (+548 -0) 📝 `crates/horizon-client/src/crafting.rs` (+1 -1) 📝 `crates/horizon-client/src/entity_nbt.rs` (+75 -39) 📝 `crates/horizon-client/src/game.rs` (+56 -3) 📝 `crates/horizon-client/src/game/creatures.rs` (+1 -0) 📝 `crates/horizon-client/src/game/lan_actions.rs` (+17 -1) ➕ `crates/horizon-client/src/game/lan_trading.rs` (+409 -0) 📝 `crates/horizon-client/src/game/maps.rs` (+18 -0) 📝 `crates/horizon-client/src/game/potions.rs` (+0 -3) 📝 `crates/horizon-client/src/game/remote.rs` (+85 -3) 📝 `crates/horizon-client/src/game/stations.rs` (+26 -6) 📝 `crates/horizon-client/src/game/trading.rs` (+363 -218) 📝 `crates/horizon-client/src/game/villagers.rs` (+10 -3) 📝 `crates/horizon-client/src/item_data.rs` (+6 -4) 📝 `crates/horizon-client/src/lan/containers.rs` (+21 -0) 📝 `crates/horizon-client/src/lan/guest.rs` (+25 -0) 📝 `crates/horizon-client/src/menu.rs` (+228 -14) _...and 10 more files_ </details> ### 📄 Description Villager trading to vanilla parity (reported: trading didn't work in v2026.10.13.1). Single-player trading opened, but generation, prices, the menu and the network side were not vanilla, and LAN/dedicated players couldn't trade at all. ## What changed - **Generation** (`merchant.rs`): every trade-set modifier vanilla uses — random dyes, random potions (`#tradeable`), suspicious stew effects, exploration maps (found through the generator's `/locate`, new filled map with its target decoration), sum/binomial number providers, max uses / xp / discount providers in vanilla's order. Offers draw from the world's `RandomSequences`, now saved as `data/minecraft/random_sequences.dat`. The villager type is namespaced, so desert/snow/... only trades appear; the loot origin is the villager. - **Menu**: a `Merchant` kind in the verified menu engine (`menu.rs`) over a `merchant::Session`: MerchantContainer/updateSellItem (selection hint rules of `getRecipeFor`), MerchantResultSlot, quick move, `tryMoveItems`, close (carried stack then payment). The game routes the trading screen through it. - **Merchant**: `notifyTrade` / `rewardTradeXp` with the merchant's own random (orbs at the villager, yes/no voice pitch draws), level-ups with new offers while the screen is open plus regeneration, TRADE reputation event a tick later (one per tick), special prices kept after closing (as vanilla). Wandering traders, babies, sleeping villagers, unhappy head shake. - **NBT**: Offers as `MerchantOffers.CODEC` (defaults left out, empty list omitted), Xp / LastRestock / RestocksToday kept even before offers exist; suspicious stew default duration left out. - **Network**: `MerchantOffers` / `SelectTrade` packets. LAN host and dedicated server open the trading window for the guest who right-clicked (OpenScreen with vanilla's display-name title, offers, clicks on the merchant menu, reputation by guest UUID). As a client, Horizon shows a server's trading window. Stored enchantments, dyed colours and map ids now go over the wire. - **Screen**: the out-of-stock restock tooltip. ## Harnesses - New `test_trading_parity.py` (VanillaTradingOracle on a real flat vanilla server vs `trading_fixture`): 5,364 cases, 28,358 lines, **0 differences** — offers of every profession × type × level across seeds and wandering traders with the shared sequences (gen 1864), `updateSpecialPrices` under gossip/Hero/demand (1000), restocks over days (600), full trading-screen sessions with clicks, level-ups, orbs and the merchant random (1500), NBT round trip (400). - `test_dedicated_server_parity.py` now right-clicks a summoned librarian: OpenScreen + MerchantOffers identical to vanilla's server (541 lines identical). - Regression: trading, mob_ai, finalize_spawn, menu_click, place_recipe, cauldron, entity_death_loot, datafix ×6, command_exec, lan, natural_spawn, raid, recipe_book, enchanting, dispenser, spawn_rules (21 passed on macmini) and save_roundtrip (passed locally); `gate.py --quick` passes; cargo tests pass. ## Checked in game (vscreen) Librarian: trading screen opens, paper → emerald trades (shift-click), XP bar, level-up to Apprentice with new offers and the trade-reputation discount; offers and XP persist across reopen; wandering trader screen. ## Not done / limits - No merchant-screen drawing harness (the screen was checked against `MerchantScreen` by reading; the loom/crafter screen harness could be extended). - Exploration maps: the flat oracle world finds no structures, so only "none found" is compared; in game the map has its id and target decoration but no pre-rendered biome preview. - LAN guests: no Hero of the Village for guests; a second Horizon client in a vscreen test rendered black and a guest's `/tp @s` moved the host (pre-existing LAN issues, not touched). 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 15:54:46 +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#2301
No description provided.