[PR #2573] [MERGED] A villager that loses its job site offers its new profession's trades #4437

Closed
opened 2026-11-03 04:17:08 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/2573
Author: @levzzz5154
Created: 10/26/2026
Status: ✅ Merged
Merged: 10/27/2026
Merged by: @ludovic111

Base: main ← Head: fix/villager-job-site-trades


📝 Commits (3)

  • e184ab7 A villager that loses its job site offers its new profession's trades
  • 209fa16 Merge remote-tracking branch 'upstream/main' into fix/villager-job-site-trades
  • db0a33d Merge remote-tracking branch 'upstream/main' into fix/villager-job-site-trades

📊 Changes

1 file changed (+47 additions, -0 deletions)

View changed files

📝 crates/horizon-client/src/mobs/villager.rs (+47 -0)

📄 Description

🤖 Opened by levzzz5154's AI agent (Claude Code), not by levzzz5154 himself.

What and why

The reported sequence in #1639: a villager is given a job, its work bench is destroyed, it is given another job, and then it does not open a trading menu.

The bug is already fixed on main, by #2009 ("A villager's new profession rolls its trades"), which added the t.unset = true to Villager.set_profession's Horizon twin. I verified the whole sequence on a build of main in a real world: the villager takes the composter's job, the composter is destroyed, a smithing table is placed, the villager takes the smithing table's job, and right-clicking it opens the merchant menu with the new profession's trades.

This pull request adds the regression test for that sequence, so a villager that keeps the old profession's offers marked as made cannot pass it again. The test fails on the pre-#2009 code (with t.unset = true removed it fails on assert!(t.unset)) and passes on main.

Fixes #1639

Vanilla reference

  • Villager.setVillagerData(VillagerData): when the profession differs from the current one, it sets this.offers = null. The next AbstractVillager.getOffers therefore rolls the new profession's trade set (VillagerProfession.getTrades(level)), instead of keeping the old profession's offers. Horizon's villager::set_profession is this method: it clears trade.offers and marks the offers as not made (trade.unset = true, vanilla's offers == null).
  • VillagerGoalPackages.getCorePackage: ValidateNearbyPoi.create(profession.value().heldJobSite(), MemoryModuleType.JOB_SITE) erases the JOB_SITE memory when the work bench is gone, and ResetProfession.create() then makes the villager unemployed (VillagerProfession.NONE) when it has no experience and is level 1. AssignProfessionFromJobSite.create() gives it the new job site and its profession, which drops the offers.
  • AbstractVillager.getOffers: the offers are made on the first request when they are null (this.offers = new MerchantOffers(); this.updateTrades(serverLevel);). Horizon's Game::ensure_offers is this method.

Self-check

cargo test -p horizon-client --lib -- a_villager_that_loses_its_job_site_offers_its_new_profession_trades a_new_profession_rolls_new_offers

running 2 tests
test mobs::villager::tests::a_new_profession_rolls_new_offers ... ok
test mobs::villager::tests::a_villager_that_loses_its_job_site_offers_its_new_profession_trades ... ok

test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 1213 filtered out; finished in 0.00s

The same test with #2009's t.unset = true removed (the pre-fix code) fails:

test mobs::villager::tests::a_villager_that_loses_its_job_site_offers_its_new_profession_trades ... FAILED

thread 'mobs::villager::tests::a_villager_that_loses_its_job_site_offers_its_new_profession_trades' panicked at crates/horizon-client/src/mobs/villager.rs:945:9:
assertion failed: t.unset

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 1214 filtered out; finished in 0.00s

Live check on a build of main (a fresh world, horizon-client --no-pause --offscreen plus horizon-ctl):

### 2. place the work bench: the villager takes the farmer's job
{"chat":["Changed the block at 3, 69, 0"],"ok":true}
{"entities":[{... "villager":{"level":1,"profession":"farmer","type":"plains"}}]}

### 3. right-click the villager: the trade menu opens with the farmer's trades
{"buttons":[],"carried":null,"container":null,"craft_size":2,"ok":true,"screen":"station",...}
{"chat":["Villager has the following entity data: {Recipes: [{maxUses: 16, buy: {count: 22, id: \"minecraft:carrot\"}, sell: {count: 1, id: \"minecraft:emerald\"}, ...}, {maxUses: 16, buy: {count: 15, id: \"minecraft:beetroot\"}, ...}]}"],"ok":true}

### 4. destroy the work bench
{"entities":[{... "villager":{"level":1,"profession":"none","type":"plains"}}]}
{"chat":["Found no elements matching Offers"],"ok":true}

### 5. give it another job: a smithing table
{"entities":[{... "villager":{"level":1,"profession":"toolsmith","type":"plains"}}]}

### 6. right-click it: the trade menu opens with the TOOLSMITH's trades
{"buttons":[],"carried":null,"container":null,"craft_size":2,"ok":true,"screen":"station",...}
station: Merchant
{"chat":["Villager has the following entity data: {Recipes: [{maxUses: 16, buy: {count: 15, id: \"minecraft:coal\"}, sell: {count: 1, id: \"minecraft:emerald\"}, ...}, {maxUses: 12, buy: {count: 1, id: \"minecraft:emerald\"}, sell: {count: 1, id: \"minecraft:stone_axe\"}, ...}]}"],"ok":true}
{"chat":["Villager has the following entity data: {profession: \"minecraft:toolsmith\", level: 1, type: \"minecraft:plains\"}"],"ok":true}

🤖 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/2573 **Author:** [@levzzz5154](https://github.com/levzzz5154) **Created:** 10/26/2026 **Status:** ✅ Merged **Merged:** 10/27/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/villager-job-site-trades` --- ### 📝 Commits (3) - [`e184ab7`](https://github.com/horizon-rust/horizon/commit/e184ab7a424f4b1d9155c284a44bbada9244015c) A villager that loses its job site offers its new profession's trades - [`209fa16`](https://github.com/horizon-rust/horizon/commit/209fa169cd3b15c57ac0433b3dca9faffb22096c) Merge remote-tracking branch 'upstream/main' into fix/villager-job-site-trades - [`db0a33d`](https://github.com/horizon-rust/horizon/commit/db0a33da3fc9fa979f42a5d1cb52201e2243fbf5) Merge remote-tracking branch 'upstream/main' into fix/villager-job-site-trades ### 📊 Changes **1 file changed** (+47 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/mobs/villager.rs` (+47 -0) </details> ### 📄 Description > 🤖 Opened by levzzz5154's AI agent (Claude Code), not by levzzz5154 himself. ## What and why The reported sequence in #1639: a villager is given a job, its work bench is destroyed, it is given another job, and then it does not open a trading menu. **The bug is already fixed on `main`**, by #2009 ("A villager's new profession rolls its trades"), which added the `t.unset = true` to `Villager.set_profession`'s Horizon twin. I verified the whole sequence on a build of `main` in a real world: the villager takes the composter's job, the composter is destroyed, a smithing table is placed, the villager takes the smithing table's job, and right-clicking it opens the merchant menu with the **new** profession's trades. This pull request adds the regression test for that sequence, so a villager that keeps the old profession's offers marked as made cannot pass it again. The test fails on the pre-#2009 code (with `t.unset = true` removed it fails on `assert!(t.unset)`) and passes on `main`. Fixes #1639 ## Vanilla reference - `Villager.setVillagerData(VillagerData)`: when the profession differs from the current one, it sets `this.offers = null`. The next `AbstractVillager.getOffers` therefore rolls the **new** profession's trade set (`VillagerProfession.getTrades(level)`), instead of keeping the old profession's offers. Horizon's `villager::set_profession` is this method: it clears `trade.offers` and marks the offers as not made (`trade.unset = true`, vanilla's `offers == null`). - `VillagerGoalPackages.getCorePackage`: `ValidateNearbyPoi.create(profession.value().heldJobSite(), MemoryModuleType.JOB_SITE)` erases the `JOB_SITE` memory when the work bench is gone, and `ResetProfession.create()` then makes the villager unemployed (`VillagerProfession.NONE`) when it has no experience and is level 1. `AssignProfessionFromJobSite.create()` gives it the new job site and its profession, which drops the offers. - `AbstractVillager.getOffers`: the offers are made on the first request when they are null (`this.offers = new MerchantOffers(); this.updateTrades(serverLevel);`). Horizon's `Game::ensure_offers` is this method. ## Self-check `cargo test -p horizon-client --lib -- a_villager_that_loses_its_job_site_offers_its_new_profession_trades a_new_profession_rolls_new_offers` ``` running 2 tests test mobs::villager::tests::a_new_profession_rolls_new_offers ... ok test mobs::villager::tests::a_villager_that_loses_its_job_site_offers_its_new_profession_trades ... ok test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 1213 filtered out; finished in 0.00s ``` The same test with #2009's `t.unset = true` removed (the pre-fix code) fails: ``` test mobs::villager::tests::a_villager_that_loses_its_job_site_offers_its_new_profession_trades ... FAILED thread 'mobs::villager::tests::a_villager_that_loses_its_job_site_offers_its_new_profession_trades' panicked at crates/horizon-client/src/mobs/villager.rs:945:9: assertion failed: t.unset test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 1214 filtered out; finished in 0.00s ``` Live check on a build of `main` (a fresh world, `horizon-client --no-pause --offscreen` plus `horizon-ctl`): ``` ### 2. place the work bench: the villager takes the farmer's job {"chat":["Changed the block at 3, 69, 0"],"ok":true} {"entities":[{... "villager":{"level":1,"profession":"farmer","type":"plains"}}]} ### 3. right-click the villager: the trade menu opens with the farmer's trades {"buttons":[],"carried":null,"container":null,"craft_size":2,"ok":true,"screen":"station",...} {"chat":["Villager has the following entity data: {Recipes: [{maxUses: 16, buy: {count: 22, id: \"minecraft:carrot\"}, sell: {count: 1, id: \"minecraft:emerald\"}, ...}, {maxUses: 16, buy: {count: 15, id: \"minecraft:beetroot\"}, ...}]}"],"ok":true} ### 4. destroy the work bench {"entities":[{... "villager":{"level":1,"profession":"none","type":"plains"}}]} {"chat":["Found no elements matching Offers"],"ok":true} ### 5. give it another job: a smithing table {"entities":[{... "villager":{"level":1,"profession":"toolsmith","type":"plains"}}]} ### 6. right-click it: the trade menu opens with the TOOLSMITH's trades {"buttons":[],"carried":null,"container":null,"craft_size":2,"ok":true,"screen":"station",...} station: Merchant {"chat":["Villager has the following entity data: {Recipes: [{maxUses: 16, buy: {count: 15, id: \"minecraft:coal\"}, sell: {count: 1, id: \"minecraft:emerald\"}, ...}, {maxUses: 12, buy: {count: 1, id: \"minecraft:emerald\"}, sell: {count: 1, id: \"minecraft:stone_axe\"}, ...}]}"],"ok":true} {"chat":["Villager has the following entity data: {profession: \"minecraft:toolsmith\", level: 1, type: \"minecraft:plains\"}"],"ok":true} ``` 🤖 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-03 04:17:08 +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#4437
No description provided.