Merge pull request #2994 from kacpherek/fix/particles-sounds-parity

🤖 Agent: read the diff at 0f8e3a9b0 ("Match vanilla mob and arrow sounds: horses, hostile fall and swim, hur") against the 26.3 source it cites; verify green, merges cleanly with main. Proof: cg25 union a051cc285 (local branch cg25/union in t3-ef805fdb: main 6d3489d30 + 38 contributor heads merged cleanly, no fixups): clippy -p horizon-client --all-targets -D warnings clean, horizon-client lib 1105 + bin 133 + integration tests pass, parity --changed 355/355 harnesses PASS on the Mac mini (Cargo.lock changed by #3210, so every harness ran; tab_list passed on its one retry).
This commit is contained in:
Ludovic Marie
2026-10-28 19:44:09 +01:00
committed by GitHub
7 changed files with 207 additions and 10 deletions
@@ -161,6 +161,7 @@ pub fn main() -> Result<()> {
"sound {} {:08x} {:08x}",
match sound {
ArrowSound::HitGround => "hit",
ArrowSound::CrossbowHit => "crossbow_hit",
ArrowSound::Splash => "splash",
ArrowSound::Extinguish => "extinguish",
ArrowSound::TridentHitGround => "trident_hit_ground",
+10
View File
@@ -130,6 +130,8 @@ pub enum ArrowSound {
Splash,
/// The arrow's `soundEvent` (`entity.arrow.hit`), for blocks and entities.
HitGround,
/// An arrow shot from a crossbow: `item.crossbow.hit`.
CrossbowHit,
/// `entity.generic.extinguish_fire`.
Extinguish,
/// A thrown trident's `getDefaultHitGroundSoundEvent` (`item.trident.hit_ground`).
@@ -782,8 +784,16 @@ impl Ticker<'_, '_, '_, '_> {
/// `playSound(soundEvent, 1, 1.2 / (random * 0.2 + 0.9))`.
fn hit_sound(&mut self) {
let pitch = 1.2 / (self.st.random.next_float() * 0.2 + 0.9);
// CrossbowItem.createProjectile: its arrows hit with the crossbow's sound.
let crossbow = self
.st
.fired_from_weapon
.as_ref()
.is_some_and(|s| &*s.item == "minecraft:crossbow");
let sound = if self.trident() {
ArrowSound::TridentHitGround
} else if crossbow {
ArrowSound::CrossbowHit
} else {
ArrowSound::HitGround
};
@@ -2657,6 +2657,7 @@ impl Game<'_> {
let name = match sound {
ArrowSound::Splash => "minecraft:entity.generic.splash",
ArrowSound::HitGround => "minecraft:entity.arrow.hit",
ArrowSound::CrossbowHit => "minecraft:item.crossbow.hit",
ArrowSound::Extinguish => "minecraft:entity.generic.extinguish_fire",
ArrowSound::TridentHitGround => "minecraft:item.trident.hit_ground",
ArrowSound::TridentHit => "minecraft:item.trident.hit",
+11 -1
View File
@@ -259,6 +259,7 @@ impl Game<'_> {
Species::CamelHusk => "minecraft:entity.camel_husk.eat",
Species::Donkey => "minecraft:entity.donkey.eat",
Species::Mule => "minecraft:entity.mule.eat",
Species::Horse if m.is_baby() => "minecraft:entity.baby_horse.eat",
_ => "minecraft:entity.horse.eat",
};
let pitch = (self.world.random.next_float() - self.world.random.next_float()) * 0.2 + 1.0;
@@ -337,7 +338,16 @@ impl Game<'_> {
}
// The nautilus plays its dash sound itself.
if equine::is_equine(m.species()) {
let sound = "minecraft:entity.horse.jump";
// playJumpSound: Donkey and Mule have their own; a skeleton
// horse in water splashes.
let sound = match m.species() {
Species::Donkey => "minecraft:entity.donkey.jump",
Species::Mule => "minecraft:entity.mule.jump",
Species::SkeletonHorse if m.fluids.in_water => {
"minecraft:entity.skeleton_horse.jump_water"
}
_ => "minecraft:entity.horse.jump",
};
let at = m.center();
self.audio.play(sound, Some(at), 0.4, 1.0);
}
+54
View File
@@ -1481,6 +1481,58 @@ pub fn voice_sounds(m: &Mob) -> [&'static str; 3] {
};
[ambient, m.kind.sounds[1], m.kind.sounds[2]]
}
// Horse.getAmbientSound, getHurtSound and getDeathSound by age.
Species::Horse if m.is_baby() => [
"entity.baby_horse.ambient",
"entity.baby_horse.hurt",
"entity.baby_horse.death",
],
// Drowned, Guardian and ElderGuardian: the hurt and death sounds by
// water or land.
Species::Drowned if m.fluids.in_water => [
"entity.drowned.ambient_water",
"entity.drowned.hurt_water",
"entity.drowned.death_water",
],
Species::Guardian if !m.fluids.in_water => [
m.kind.sounds[0],
"entity.guardian.hurt_land",
"entity.guardian.death_land",
],
Species::ElderGuardian if !m.fluids.in_water => [
m.kind.sounds[0],
"entity.elder_guardian.hurt_land",
"entity.elder_guardian.death_land",
],
// Slime and MagmaCube.getHurtSound and getDeathSound: tiny ones.
Species::Slime if m.extra.size <= 1 => [
m.kind.sounds[0],
"entity.slime.hurt_small",
"entity.slime.death_small",
],
Species::MagmaCube if m.extra.size <= 1 => [
m.kind.sounds[0],
"entity.magma_cube.hurt_small",
"entity.magma_cube.death_small",
],
// Shulker.getHurtSound: a closed shell.
Species::Shulker if m.extra.counter == 0 => [
m.kind.sounds[0],
"entity.shulker.hurt_closed",
m.kind.sounds[2],
],
// Turtle.getHurtSound and getDeathSound by age.
Species::Turtle if m.is_baby() => [
m.kind.sounds[0],
"entity.turtle.hurt_baby",
"entity.turtle.death_baby",
],
// SkeletonHorse.getAmbientSound: its own under water.
Species::SkeletonHorse if m.fluids.eye_in_water => [
"entity.skeleton_horse.ambient_water",
m.kind.sounds[1],
m.kind.sounds[2],
],
// The mob's sound variant set, the baby one for a baby.
Species::Pig | Species::Cow | Species::Chicken | Species::Wolf | Species::Cat => {
use super::finalize::variant_sound as v;
@@ -2128,6 +2180,8 @@ pub fn swim_sound(m: &Mob) -> &'static str {
Species::Nautilus => "entity.nautilus.swim",
Species::ZombieNautilus => "entity.zombie_nautilus.swim",
Species::Turtle => "entity.turtle.swim",
// Monster.getSwimSound, and Hoglin's own override of it.
s if s == Species::Hoglin || is_monster(s) => "entity.hostile.swim",
_ => "entity.generic.swim",
}
}
+115 -4
View File
@@ -292,13 +292,17 @@ pub fn make_mad(m: &mut Mob, events: &mut Vec<MobEvent>) {
m.extra.counter = 20;
m.extra.flag = false;
}
// getAngrySound: null (silent) for the skeleton horse.
let sound = match m.species() {
Species::SkeletonHorse => return,
Species::Donkey => "entity.donkey.angry",
Species::Mule => "entity.mule.angry",
Species::ZombieHorse => "entity.zombie_horse.angry",
Species::Llama | Species::TraderLlama => "entity.llama.angry",
_ if m.is_baby() => "entity.baby_horse.angry",
_ => "entity.horse.angry",
};
events.push(MobEvent::Sound(sound, m.center(), 1.0, 1.0));
m.voice(sound, events);
}
/// `RandomStandGoal`.
#[derive(Clone, Debug)]
@@ -324,10 +328,113 @@ impl Goal for RandomStand {
fn start(&mut self, m: &mut Mob, cx: &mut Cx) {
m.extra.counter = 20;
m.extra.flag = false;
if m.species() == Species::Horse {
cx.events
.push(MobEvent::Sound("entity.horse.angry", m.center(), 1.0, 1.0));
// playStandSound: getAmbientStandSound is the ambient sound, plain
// playSound(sound) at volume and pitch 1.
let sound = super::ai::voice_sounds(m)[0];
let at = [m.position.x, m.position.y, m.position.z];
cx.events.push(MobEvent::Sound(sound, at, 1.0, 1.0));
}
}
/// Horses that step with `AbstractHorse.playStepSound` (llamas and camels
/// have their own).
pub fn hoof_steps(s: Species) -> bool {
matches!(
s,
Species::Horse
| Species::Donkey
| Species::Mule
| Species::SkeletonHorse
| Species::ZombieHorse
)
}
/// `AbstractHorse.playStepSound` (and `Horse.playGallopSound`) on the block
/// `pos`: silent on liquids; a ridden horse walks on wood for five steps,
/// then gallops every third; unridden, wood or the plain step by age.
/// Donkeys and mules never gallop (`canGallop`).
pub fn play_step(
m: &mut Mob,
w: &MobWorld,
pos: [i32; 3],
state: horizon_world::registry::BlockStateId,
events: &mut Vec<MobEvent>,
) {
if matches!(
&*w.facts.get(state).name,
"minecraft:water" | "minecraft:lava" | "minecraft:bubble_column"
) {
return;
}
let above = w.world.block(pos[0], pos[1] + 1, pos[2]);
let sound_type = if &*w.facts.get(above).name == "minecraft:snow" {
&w.facts.get(above).sounds
} else {
&w.facts.get(state).sounds
};
let (volume, pitch) = (sound_type.volume, sound_type.pitch);
let at = [m.position.x, m.position.y, m.position.z];
let baby = m.is_baby();
let can_gallop = !matches!(m.species(), Species::Donkey | Species::Mule);
if m.rider.is_some() && can_gallop {
m.ai.steps.gallop += 1;
let count = m.ai.steps.gallop;
if count > 5 && count % 3 == 0 {
events.push(MobEvent::Sound(
"entity.horse.gallop",
at,
volume * 0.15,
pitch,
));
// Horse.playGallopSound: now and then it breathes too.
if m.species() == Species::Horse && m.random.next_int_bound(10).unwrap_or(1) == 0 {
let breathe = if baby {
"entity.baby_horse.breathe"
} else {
"entity.horse.breathe"
};
events.push(MobEvent::Sound(breathe, at, volume * 0.6, pitch));
}
} else if count <= 5 {
events.push(MobEvent::Sound(
"entity.horse.step_wood",
at,
volume * 0.15,
pitch,
));
}
} else if is_wood_sound_type(sound_type) {
events.push(MobEvent::Sound(
"entity.horse.step_wood",
at,
volume * 0.15,
pitch,
));
} else {
let step = if baby {
"entity.baby_horse.step"
} else {
"entity.horse.step"
};
events.push(MobEvent::Sound(step, at, volume * 0.15, pitch));
}
}
/// `AbstractHorse.isWoodSoundType`: WOOD, NETHER_WOOD, STEM, CHERRY_WOOD and
/// BAMBOO_WOOD (not HARD_CROP, which only shares WOOD's step).
fn is_wood_sound_type(sounds: &horizon_items::blocks::Sounds) -> bool {
let step = sounds
.step
.strip_prefix("minecraft:")
.unwrap_or(&sounds.step);
let place = sounds
.place
.strip_prefix("minecraft:")
.unwrap_or(&sounds.place);
match step {
"block.wood.step" => place == "block.wood.place",
"block.nether_wood.step"
| "block.stem.step"
| "block.cherry_wood.step"
| "block.bamboo_wood.step" => true,
_ => false,
}
}
/// The mount takes its rider's input (`getRiddenInput`, `tickRidden`).
@@ -335,6 +442,10 @@ pub fn ridden_step(m: &mut Mob) {
let Some(r) = m.rider else {
return;
};
// AbstractHorse.tickRidden: not pressing forward ends the gallop.
if hoof_steps(m.species()) && r.forward <= 0.0 {
m.ai.steps.gallop = 0;
}
// AbstractNautilus.tickRidden turns half way toward the rider.
if super::nautilus::is_nautilus(m.species()) {
return super::nautilus::ridden(m);
+15 -5
View File
@@ -25,6 +25,8 @@ pub struct Steps {
pub move_dist: f32,
pub fly_dist: f32,
pub next_step: f32,
/// `AbstractHorse.gallopSoundCounter`.
pub gallop: i32,
}
impl Default for Steps {
fn default() -> Self {
@@ -32,6 +34,7 @@ impl Default for Steps {
move_dist: 0.0,
fly_dist: 0.0,
next_step: 1.0,
gallop: 0,
}
}
}
@@ -706,7 +709,11 @@ impl Mob {
&& (self.on_ground || climbable)
&& !self.fluids_swimming();
if produced {
if let Some((sound, volume, pitch)) =
if super::equine::hoof_steps(self.species()) {
if !self.silent {
super::equine::play_step(self, w, legacy, legacy_state, events);
}
} else if let Some((sound, volume, pitch)) =
super::ai::step_sound(self, w, legacy, legacy_state)
&& !self.silent
{
@@ -863,10 +870,13 @@ impl Mob {
}
if damage > 0.0 {
let at = [self.position.x, self.position.y, self.position.z];
let sound = if damage > 4.0 {
"entity.generic.big_fall"
} else {
"entity.generic.small_fall"
// Monster.getFallSounds: the hostile pair.
let monster = super::ai::is_monster(self.species());
let sound = match (monster, damage > 4.0) {
(true, true) => "entity.hostile.big_fall",
(true, false) => "entity.hostile.small_fall",
(false, true) => "entity.generic.big_fall",
(false, false) => "entity.generic.small_fall",
};
events.push(MobEvent::Sound(sound, at, 1.0, 1.0));
self.damage(damage as f32, super::Damage::fall());