[PR #6189] [MERGED] Keep a villager quiet in bed and loud at the trade table #6709

Closed
opened 2026-11-03 06:25:14 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/6189
Author: @MSedgeMC
Created: 11/1/2026
Status: ✅ Merged
Merged: 11/1/2026
Merged by: @ludovic111

Base: main ← Head: fix/villager-ambient


📝 Commits (3)

  • 4cc8041 Keep a villager quiet in bed and loud at the trade table
  • 63d6129 Name the trading closure instead of splitting it
  • 736fe7c Merge main into pr-6189

📊 Changes

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

View changed files

📝 crates/horizon-client/src/mobs/ai.rs (+69 -0)

📄 Description

Villager.getAmbientSound has two branches Mob's plain ambient does not:

// javap -p -c on Villager
0: aload_0  1: invokevirtual isSleeping  4: ifeq 9
7: aconst_null  8: areturn                          // asleep: silent
9: aload_0  10: invokevirtual isTrading  13: ifeq 20
16: getstatic SoundEvents.VILLAGER_TRADE  19: areturn
20: getstatic SoundEvents.VILLAGER_AMBIENT  23: areturn

WanderingTrader.getAmbientSound has only the trade branch (it never sleeps), and
entity.wandering_trader.trade was missing for it too.

Horizon's play_ambient had no villager arm at all, so it always fell through to the plain
ambient: a villager asleep in a bed kept talking, and one with a trade screen open never
played the trade line. Sleeping comes from the brain's sleep state (villager::sleeping,
ints[1]), trading from the open merchant session (extra.flag2, set by
Villager.setTradingPlayer).

Proven: on the build VM, cargo test -q -p horizon-client --lib villager_ambient_tests
→ 1 passed, asserting ambient / trade / silence while asleep / sleep wins over trade, plus
the wandering trader's trade line.

Not proven: not checked in game; the audible check is a villager in a bed and one with its
menu open.

One thing left deliberately: villager::sleeping also answers true for a wandering trader with
the sleep bit set, but vanilla's WanderingTrader.getAmbientSound has no sleep branch, so no
sleep arm was added for it.


🔄 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/6189 **Author:** [@MSedgeMC](https://github.com/MSedgeMC) **Created:** 11/1/2026 **Status:** ✅ Merged **Merged:** 11/1/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/villager-ambient` --- ### 📝 Commits (3) - [`4cc8041`](https://github.com/horizon-rust/horizon/commit/4cc8041d8be3024c20c9b3d90b5b87cff499495a) Keep a villager quiet in bed and loud at the trade table - [`63d6129`](https://github.com/horizon-rust/horizon/commit/63d612913b9a3ac8b33931c68a7ab051d66d6967) Name the trading closure instead of splitting it - [`736fe7c`](https://github.com/horizon-rust/horizon/commit/736fe7c62e6b0c7dcb6451c32429d05a1443546c) Merge main into pr-6189 ### 📊 Changes **1 file changed** (+69 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/mobs/ai.rs` (+69 -0) </details> ### 📄 Description `Villager.getAmbientSound` has two branches `Mob`'s plain ambient does not: ```java // javap -p -c on Villager 0: aload_0 1: invokevirtual isSleeping 4: ifeq 9 7: aconst_null 8: areturn // asleep: silent 9: aload_0 10: invokevirtual isTrading 13: ifeq 20 16: getstatic SoundEvents.VILLAGER_TRADE 19: areturn 20: getstatic SoundEvents.VILLAGER_AMBIENT 23: areturn ``` `WanderingTrader.getAmbientSound` has only the trade branch (it never sleeps), and `entity.wandering_trader.trade` was missing for it too. Horizon's `play_ambient` had no villager arm at all, so it always fell through to the plain ambient: a villager asleep in a bed kept talking, and one with a trade screen open never played the trade line. Sleeping comes from the brain's sleep state (`villager::sleeping`, `ints[1]`), trading from the open merchant session (`extra.flag2`, set by `Villager.setTradingPlayer`). **Proven:** on the build VM, `cargo test -q -p horizon-client --lib villager_ambient_tests` → `1 passed`, asserting ambient / trade / silence while asleep / sleep wins over trade, plus the wandering trader's trade line. **Not proven:** not checked in game; the audible check is a villager in a bed and one with its menu open. One thing left deliberately: `villager::sleeping` also answers true for a wandering trader with the sleep bit set, but vanilla's `WanderingTrader.getAmbientSound` has no sleep branch, so no sleep arm was added for it. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 06:25:14 +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#6709
No description provided.