mojira.dev
MC-91803

Cave / ambiance music can play far away from the player and is not audible

The bug

Ambiance / cave music can play far away from the player. This way the player might hear it less often than it should appear.

Report history

This report used to include in-game and title music as well. These were fixed in previous versions.

Code analysis

Based on 1.11 decompiled using MCP 9.35 rc1

The problem is that the method net.minecraft.client.multiplayer.WorldClient.playMoodSoundAndCheckLight(int, int, Chunk), which plays the ambient cave sound, is called with chunk coordinates of all visible chunks and only tests if the position tested is at least 2 meters away. This means the position can be hundreds of blocks away.

Example fix (1.11)

protected void playMoodSoundAndCheckLight(int p_147467_1_, int p_147467_2_, Chunk chunkIn)
{
    super.playMoodSoundAndCheckLight(p_147467_1_, p_147467_2_, chunkIn);

    if (this.ambienceTicks == 0)
    {
        this.updateLCG = this.updateLCG * 3 + 1013904223;
        int i = this.updateLCG >> 2;
        int j = i & 15;
        int k = i >> 8 & 15;
        int l = i >> 16 & 255;
        BlockPos blockpos = new BlockPos(j + p_147467_1_, l, k + p_147467_2_);
        IBlockState iblockstate = chunkIn.getBlockState(blockpos);
        j = j + p_147467_1_;
        k = k + p_147467_2_;

        // Old code
        //if (iblockstate.getMaterial() == Material.AIR && this.getLight(blockpos) <= this.rand.nextInt(8) && this.getLightFor(EnumSkyBlock.SKY, blockpos) <= 0 && this.mc.player != null && this.mc.player.getDistanceSq((double)j + 0.5D, (double)l + 0.5D, (double)k + 0.5D) > 4.0D)
        //{
        //    this.playSound((double)j + 0.5D, (double)l + 0.5D, (double)k + 0.5D, SoundEvents.AMBIENT_CAVE, SoundCategory.AMBIENT, 0.7F, 0.8F + this.rand.nextFloat() * 0.2F, false);
        //    this.ambienceTicks = this.rand.nextInt(12000) + 6000;
        //}
        
        if (this.mc.player != null) {
            double distanceToPlayerSquared = this.mc.player.getDistanceSq((double)j + 0.5D, (double)l + 0.5D, (double)k + 0.5D);
            
            // The player cannot hear the sound if it is played more than 15 (sqrt(255)) blocks away
            if (distanceToPlayerSquared > 4.0 && distanceToPlayerSquared <= 255.0 && iblockstate.getMaterial() == Material.AIR && this.getLight(blockpos) <= this.rand.nextInt(8) && this.getLightFor(EnumSkyBlock.SKY, blockpos) <= 0)
            {
                this.playSound((double)j + 0.5D, (double)l + 0.5D, (double)k + 0.5D, SoundEvents.AMBIENT_CAVE, SoundCategory.AMBIENT, 0.7F, 0.8F + this.rand.nextFloat() * 0.2F, false);
                this.ambienceTicks = this.rand.nextInt(12000) + 6000;
            }
        }
    }
}

Linked issues

MC-4299 Unable to interact with any blocks while sneaking Resolved MC-92138 In-game music problem Resolved MC-92278 Music not playing Resolved MC-92353 No Music Resolved MC-92488 Title Screen Music Never Plays Resolved

Comments 108

Can confirm. Most likely due to sound rewrites.

Confirmed, but the commande /playsound music.game @a 1000 still works.

Using /playsound isn't really the same since you're basically manually telling the game to play the music instead of letting it happen naturally.

David Pecora Jr.

Can confirm, also this bug report is a duplicate of MC-91610.

@@unknown: MC-91610 is about not having any sound at all, this is only about having no automatic background music but rest of sounds.

98 more comments

Confirm, but its working only in survival without night vision and happens pretty rare, also in minecraft 1.2.1 (ios), its still missed

Someone in MC-139255 reported that this is an issue in 18w45a again. Can anyone confirm this?

Made a quick test world with two meters of dark space beneath a flat layer of stone, perfect to provoce cave ambient sounds. Tested it in 1.13.2, heard the first one after 10 min. Then tested it in 18w45a, none after 30 min. They might really be broken again.

I did my test again, and it turns out that cave ambiance just doesn't play at all in 18w46a. Probably has to do with the new light engine changes, but that's just a guess.

I'd like to point out that this is technically no longer the same bug due to cave ambiance not playing at all (where before it only played away from the player).

[Mod]Les3awe

Erik Broes

Confirmed

ambient, ambient-sound, cave, music, player, position

Minecraft 15w44b, Minecraft 15w45a, Minecraft 15w46a, Minecraft 15w47a, Minecraft 15w47b, ..., Minecraft 1.12 Pre-Release 7, Minecraft 1.12, Minecraft 1.12.1 Pre-Release 1, Minecraft 1.12.1, Minecraft 18w46a

Minecraft 16w02a, Minecraft 16w06a, Minecraft 1.9 Pre-Release 4, Minecraft 1.12.2 Pre-Release 1

Retrieved