Play horse hoof, wood, gallop and breathing steps
AbstractHorse.playStepSound plays entity.horse.step (baby_horse.step), step_wood on wood or for the first five ridden steps, and gallops every third step with Horse.playGallopSound's breathing. Horizon played the block's step sound.
This commit is contained in:
@@ -330,11 +330,96 @@ impl Goal for RandomStand {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/// 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`).
|
/// The mount takes its rider's input (`getRiddenInput`, `tickRidden`).
|
||||||
pub fn ridden_step(m: &mut Mob) {
|
pub fn ridden_step(m: &mut Mob) {
|
||||||
let Some(r) = m.rider else {
|
let Some(r) = m.rider else {
|
||||||
return;
|
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.
|
// AbstractNautilus.tickRidden turns half way toward the rider.
|
||||||
if super::nautilus::is_nautilus(m.species()) {
|
if super::nautilus::is_nautilus(m.species()) {
|
||||||
return super::nautilus::ridden(m);
|
return super::nautilus::ridden(m);
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ pub struct Steps {
|
|||||||
pub move_dist: f32,
|
pub move_dist: f32,
|
||||||
pub fly_dist: f32,
|
pub fly_dist: f32,
|
||||||
pub next_step: f32,
|
pub next_step: f32,
|
||||||
|
/// `AbstractHorse.gallopSoundCounter`.
|
||||||
|
pub gallop: i32,
|
||||||
}
|
}
|
||||||
impl Default for Steps {
|
impl Default for Steps {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
@@ -32,6 +34,7 @@ impl Default for Steps {
|
|||||||
move_dist: 0.0,
|
move_dist: 0.0,
|
||||||
fly_dist: 0.0,
|
fly_dist: 0.0,
|
||||||
next_step: 1.0,
|
next_step: 1.0,
|
||||||
|
gallop: 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -706,7 +709,11 @@ impl Mob {
|
|||||||
&& (self.on_ground || climbable)
|
&& (self.on_ground || climbable)
|
||||||
&& !self.fluids_swimming();
|
&& !self.fluids_swimming();
|
||||||
if produced {
|
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)
|
super::ai::step_sound(self, w, legacy, legacy_state)
|
||||||
&& !self.silent
|
&& !self.silent
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user