Play the container close sound when a server-thread player closes it
This commit is contained in:
@@ -5627,26 +5627,7 @@ impl Game<'_> {
|
||||
Some(horizon_client::mobs::Who::Player),
|
||||
None,
|
||||
);
|
||||
let name = self
|
||||
.res
|
||||
.facts()
|
||||
.get(self.world.block(key.0, key.1, key.2))
|
||||
.name
|
||||
.clone();
|
||||
let sound = if storage::is_shulker_box(&name) {
|
||||
Some("minecraft:block.shulker_box.close")
|
||||
} else if &*name == "minecraft:ender_chest" {
|
||||
Some("minecraft:block.ender_chest.close")
|
||||
} else if name.contains("chest") {
|
||||
Some("minecraft:block.chest.close")
|
||||
} else if &*name == "minecraft:barrel" {
|
||||
Some("minecraft:block.barrel.close")
|
||||
} else {
|
||||
None
|
||||
};
|
||||
if let Some(sound) = sound {
|
||||
self.container_sound(sound, key, &name);
|
||||
}
|
||||
self.container_close_sound(key);
|
||||
self.world.modified.insert((key.0 >> 4, key.2 >> 4));
|
||||
}
|
||||
self.close_ender_chest();
|
||||
|
||||
@@ -854,13 +854,16 @@ impl Game<'_> {
|
||||
}
|
||||
|
||||
/// The guest's open container is closing (`AbstractContainerMenu.removed`):
|
||||
/// it no longer counts among the openers of the lid.
|
||||
/// it no longer counts among the openers of the lid, and the lid's close
|
||||
/// sound is played for everyone around (`ChestBlockEntity.onClose`, a
|
||||
/// `playSound` with no player), the guest included.
|
||||
pub(super) fn guest_container_closed(&mut self, host: &mut LanHost, conn: u32) {
|
||||
if let Some(g) = host.hub.guest(conn)
|
||||
&& let Some(pos) = g.menu.as_ref().and_then(|m| m.pos)
|
||||
&& !g.spectator()
|
||||
{
|
||||
self.container_openers_changed(pos, false);
|
||||
self.container_close_sound(pos);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -142,6 +142,27 @@ impl Game<'_> {
|
||||
let pitch = self.world.random.next_float() * 0.1 + 0.9;
|
||||
self.audio.play(sound, Some(at), 0.5, pitch);
|
||||
}
|
||||
/// The close sound of the container block at `key`, if it has one.
|
||||
pub(super) fn container_close_sound(&mut self, key: (i32, i32, i32)) {
|
||||
let name = self
|
||||
.res
|
||||
.facts()
|
||||
.get(self.world.block(key.0, key.1, key.2))
|
||||
.name
|
||||
.clone();
|
||||
let sound = if is_shulker_box(&name) {
|
||||
"minecraft:block.shulker_box.close"
|
||||
} else if &*name == "minecraft:ender_chest" {
|
||||
"minecraft:block.ender_chest.close"
|
||||
} else if name.contains("chest") {
|
||||
"minecraft:block.chest.close"
|
||||
} else if &*name == "minecraft:barrel" {
|
||||
"minecraft:block.barrel.close"
|
||||
} else {
|
||||
return;
|
||||
};
|
||||
self.container_sound(sound, key, &name);
|
||||
}
|
||||
/// The other half of a double chest at `key`, for neighbour updates.
|
||||
pub(super) fn chest_other_half(&self, key: (i32, i32, i32)) -> Option<(i32, i32, i32)> {
|
||||
self.chest_partner(key).map(|p| p.0)
|
||||
|
||||
Reference in New Issue
Block a user