mojira.dev
MC-237165

Block breaking sounds cannot be heard by other players

The Bug:

Block breaking sounds cannot be heard by other players.

Just for clarification reasons, block breaking sounds are the sounds produced when hitting blocks, and not actually breaking them. Try not to get confused with block breaking sounds and block broken sounds.

Steps to Reproduce:

  1. Get two players and label them "Player A" and "Player B".

  2. Get "Player A" to look at any block.

  3. Get "Player B" to start hitting the block that "Player A" is looking at.

  4. Take note as to whether or not block breaking sounds can be heard by other players.

Observed Behavior:

Block breaking sounds cannot be heard by other players. They can only be heard by the player who's hitting the block.

Expected Behavior:

Block breaking sounds would be able to be heard by all players and not just the player who's hitting the block.

Code Analysis:

The following is based on a decompiled version of Minecraft 26.3 Snapshot 4 using Mojang mappings.

net.minecraft.world.level.block.Block.java

public void spawnDestroyByEntityParticles(final Level level, final @Nullable Entity entity, final BlockPos pos, final BlockState state) {
   level.levelEvent(entity, 2001, pos, getId(state));
}

net.minecraft.client.multiplayer.MultiPlayerGameMode.java

if (this.destroyTicks % 4.0F == 0.0F) {
   SoundType soundType = state.getSoundType();
   this.minecraft
      .getSoundManager()
      .play(
         new SimpleSoundInstance(
            soundType.getHitSound(),
            ...

If we look at the above classes, we can see that the sound made when a block is finally broken is played through the level, which sends it to everyone nearby. The sound made while hitting a block is played straight into the hitting player's own sound manager instead, and nothing about it is ever sent to the server, so no other player can know that it happened.

The hitting sound is played once every four ticks for as long as the block is being hit.

Fixed Code:

net.minecraft.server.level.ServerPlayerGameMode.java

private float incrementDestroyProgress(final BlockState blockState, final BlockPos pos, final int destroyStartTick) {
   int ticksSpentDestroying = this.gameTicks - destroyStartTick;
   if (ticksSpentDestroying % 4 == 0) {
      SoundType soundType = blockState.getSoundType();
      this.level.playSound(
         this.player,
         pos.getX() + 0.5,
         pos.getY() + 0.5,
         pos.getZ() + 0.5,
         soundType.getHitSound(),
         SoundSource.BLOCKS,
         (soundType.getVolume() + 1.0F) / 8.0F,
         soundType.getPitch() * 0.5F
      );
   }
   ...
}

The above has the server play the hitting sound as well, so that other players can hear it. This method already runs once per tick while a player is hitting a block, and already knows how long they have been hitting it, so the same timing of once every four ticks that the client uses can be matched exactly.

The hitting player is passed as the excluded player, as they already play the sound themselves. Without that they would hear it twice. The volume and the pitch are copied from the client so that what other players hear matches what the hitting player hears.

This change was applied to a modified server and tested against the steps above, and other players can now hear the sound.

Linked issues

MC-247034 Particles produced from entities growing cannot be seen by other players Resolved MC-237053 Block breaking particles cannot be seen by other players Resolved MC-236515 The "minecraft:item.elytra.flying" sound cannot be heard by other players when flying with elytra Open MC-237252 The "minecraft:entity.puffer_fish.sting" sound cannot be heard by other players when being stung by pufferfish Open MC-238714 The "minecraft:item.book.page_turn" sound cannot be heard by other players when switching between pages in books held in the hand Open

Attachments

Comments 1

Avoma

bl4ckscor3

Confirmed

Platform

Normal

Networking, Sound

1.17.1, 21w37a, 21w38a, 21w40a, 1.18 Pre-release 1, , 23w18a, 1.20.1, 1.21, 1.21.4, 26.3 Snapshot 4

26.3 Pre-Release 2

Retrieved