From e184ab7a424f4b1d9155c284a44bbada9244015c Mon Sep 17 00:00:00 2001 From: levzzz <86072227+levzzz5154@users.noreply.github.com> Date: Tue, 27 Oct 2026 04:35:26 +0500 Subject: [PATCH] A villager that loses its job site offers its new profession's trades The reported sequence in #1639: a villager works at a bench, the bench is destroyed and it takes another bench's job, and then it does not open a trading menu. `Villager.setVillagerData` drops the offers (`offers = null`) when the profession changes, so the next `AbstractVillager.getOffers` rolls the new profession's trade set. The brain reaches that through `set_profession`, which now also marks the offers as not made (#2009); this test covers the whole reported sequence, from the lost job site to the new profession's trades, so a villager that keeps the old profession's offers marked as made cannot pass it. Co-Authored-By: minimax-m3.1-flash (Claude Code) --- crates/horizon-client/src/mobs/villager.rs | 47 ++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/crates/horizon-client/src/mobs/villager.rs b/crates/horizon-client/src/mobs/villager.rs index aad0ec911..20280b190 100644 --- a/crates/horizon-client/src/mobs/villager.rs +++ b/crates/horizon-client/src/mobs/villager.rs @@ -905,6 +905,53 @@ mod tests { assert!(t.unset); assert_eq!(m.extra.variant2, 2); } + /// The reported sequence: a villager works at a bench, the bench is + /// destroyed (its job site is gone, so `ResetProfession` makes it + /// unemployed) and it takes another bench's job. The new profession's + /// trades are offered again. + /// + /// `Villager.setVillagerData` drops the offers (`offers = null`) when the + /// profession changes, so `AbstractVillager.getOffers` rolls the new + /// profession's trade set the next time the offers are asked for. A + /// villager that keeps its old offers marked as made never trades again: + /// it shakes its head instead of opening the trading menu. + #[test] + fn a_villager_that_loses_its_job_site_offers_its_new_profession_trades() { + let mut m = villager(); + // The composter's job: the villager is a farmer. + set_profession(&mut m, 5); + assert_eq!(m.extra.variant2, 5); + // Its trades were made, so the offers are there. + let trade = m.extra.trade.get_or_insert_default(); + trade.unset = false; + trade.offers = vec![crate::merchant::MerchantOffer { + base_cost_a: crate::merchant::ItemCost { + stack: ItemStack::new("minecraft:wheat", 20), + }, + cost_b: None, + result: ItemStack::new("minecraft:emerald", 1), + uses: 0, + max_uses: 16, + reward_exp: true, + special_price_diff: 0, + demand: 0, + price_multiplier: 0.0, + xp: 1, + }]; + // The work bench is destroyed: the job site is gone, so the villager + // is unemployed and its offers are dropped (`offers = null`). + set_profession(&mut m, NONE); + let t = m.extra.trade.as_ref().unwrap(); + assert!(t.offers.is_empty()); + assert!(t.unset); + // It takes the smithing table's job. The new profession's trades are + // rolled by the next `getOffers` (ensure_offers). + set_profession(&mut m, 13); + let t = m.extra.trade.as_ref().unwrap(); + assert!(t.offers.is_empty()); + assert!(t.unset); + assert_eq!(m.extra.variant2, 13); + } fn stack(item: &str, count: u32) -> ItemStack { ItemStack::new(item, count)