Play the step sound of the block above the floor for the player

Powder snow, lily pads, carpets, snow layers and similar blocks now sound like vanilla when walked on: inside blocks replace the floor's step, combination blocks play their own step with the floor's step muffled.
This commit is contained in:
Kacpherek
2026-10-26 15:13:58 +01:00
parent 8027cb4176
commit 66637220ef
4 changed files with 52 additions and 15 deletions
@@ -206,7 +206,7 @@ fn snapshot(out: &mut impl Write, player: &PlayerMotion) -> Result<()> {
)),
MotionEvent::Emission {
state,
in_water: true,
muffled: true,
..
} => Some(format!("muffled-step {}", state.0)),
MotionEvent::BubbleColumnParticle { bubble, position } => Some(format!(
+2 -4
View File
@@ -4349,13 +4349,11 @@ impl Game<'_> {
for event in events {
match event {
MotionEvent::HurtSound(sound) => self.player_hurt_sound(sound, feet),
MotionEvent::Emission {
state, in_water, ..
} if !crouching => {
MotionEvent::Emission { state, muffled, .. } if !crouching => {
let sounds = self.res.facts().get(state).sounds.clone();
// Entity.playStepSound: the block's step sound at 0.15 volume,
// muffled under the swim sound in water.
let (volume, pitch) = if in_water {
let (volume, pitch) = if muffled {
(sounds.volume * 0.05, sounds.pitch * 0.8)
} else {
(sounds.volume * 0.15, sounds.pitch)
+4 -4
View File
@@ -3233,12 +3233,12 @@ impl Game<'_> {
let feet = [player.position.x, player.position.y, player.position.z];
for event in events {
match event {
horizon_client::motion::MotionEvent::Emission {
state, in_water, ..
} if !crouching => {
horizon_client::motion::MotionEvent::Emission { state, muffled, .. }
if !crouching =>
{
let sounds = self.res.facts().get(state).sounds.clone();
// Player.playStepSound: muffled under the swim sound in water.
let (volume, pitch) = if in_water {
let (volume, pitch) = if muffled {
(sounds.volume * 0.05, sounds.pitch * 0.8)
} else {
(sounds.volume * 0.15, sounds.pitch)
+45 -6
View File
@@ -51,6 +51,10 @@ pub struct MotionResources {
pub blocks: BoundMovementProperties,
pub climbable: BTreeSet<String>,
pub fall_reset: BTreeSet<String>,
/// `BlockTags.INSIDE_STEP_SOUND_BLOCKS`.
pub inside_step_sound: BTreeSet<String>,
/// `BlockTags.COMBINATION_STEP_SOUND_BLOCKS`.
pub combination_step_sound: BTreeSet<String>,
pub landing: BlockLandingRegistry,
pub health: crate::health::HealthResources,
pub fluids: FluidResources,
@@ -109,6 +113,8 @@ impl MotionResources {
})?,
climbable: tag("minecraft:climbable")?,
fall_reset: tag("minecraft:fall_damage_resetting")?,
inside_step_sound: tag("minecraft:inside_step_sound_blocks")?,
combination_step_sound: tag("minecraft:combination_step_sound_blocks")?,
})
}
}
@@ -136,11 +142,12 @@ pub enum MotionEvent {
position: BlockPos,
},
/// `Entity.walkingStepSound` on this block: `Player.playStepSound`
/// muffles it under a swim sound when `in_water`.
/// mutes it (`playMuffledStepSound`) under a swim sound in water or
/// under a combination block's own step.
Emission {
position: BlockPos,
state: BlockStateId,
in_water: bool,
muffled: bool,
},
/// `Entity.waterSwimSound`: `entity.player.swim`.
Swim {
@@ -1973,16 +1980,48 @@ impl MovementEmissionWorld for MotionWorld<'_, '_, '_> {
fn in_water(&mut self) -> Result<bool> {
Ok(self.player.fluids.was_touching_water)
}
/// `Player.playStepSound`: in water a swim sound, then the step muffled.
/// `Player.playStepSound`: in water a swim sound, then the step muffled;
/// on land the step of an inside-sound block above the floor, or of a
/// combination block above it with the floor's step muffled.
fn walking_step_sound(&mut self, position: BlockPos, state: BlockStateId) -> Result<()> {
let in_water = self.player.fluids.was_touching_water;
if in_water {
let muffled = self.player.fluids.was_touching_water;
if muffled {
self.water_swim_sound()?;
} else {
// Entity.getPrimaryStepSoundBlockPos.
let above = BlockPos {
y: position.y + 1,
..position
};
let above_state = self.block(above);
let name = &self
.assets
.registry
.state(above_state)
.ok_or("missing scene state")?
.name;
let combination = self.resources.combination_step_sound.contains(name);
if combination || self.resources.inside_step_sound.contains(name) {
self.player.events.push(MotionEvent::Emission {
position: above,
state: above_state,
muffled: false,
});
if combination {
// Entity.playCombinationStepSounds.
self.player.events.push(MotionEvent::Emission {
position,
state,
muffled: true,
});
}
return Ok(());
}
}
self.player.events.push(MotionEvent::Emission {
position,
state,
in_water,
muffled,
});
Ok(())
}