Merge pull request #2573 from levzzz5154/fix/villager-job-site-trades

🤖 Agent: verified by Ludovic's AI agent (contrib gate 20): a villager that loses its job site offers its new trades. It passed in this wave's union with main on the Mac mini: the selected parity harnesses (332/332, then 122/122 on the final union), clippy -D warnings and the tests, and lan_e2e with the host on its server thread and in-frame (18/18 each). Thanks @levzzz5154!
This commit is contained in:
Ludovic Marie
2026-10-27 09:03:43 +01:00
committed by GitHub
@@ -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)