mojira.dev
MC-310788

Loop sounds vanish reload packs:nether.loop, water.loop, others. Code help Mojang fix 26.3 Snapshot8

The bug is that after reloading resource packs, all looping sounds disappear. This bug is many years old, I'm asking Mojang to fix it by version 26.3 snapshot 8. I even know how to fix it. I created a mixin to fix this:

package mixin;

import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.sounds.SoundInstance;
import net.minecraft.client.sounds.SoundEngine;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@Mixin(SoundEngine.class)
public class SoundEngineFixMixin {
@Shadow
private Map<SoundInstance, Object> instanceToChannel;
@Unique
private static List<SoundInstance> savedLoopingSounds = new ArrayList<>();
@Unique
private static boolean needsRestore = false;
@Unique
private static int delay = 0;
@Inject(method = "reload", at = @At("HEAD"))
private void onReloadStart(CallbackInfo ci) {
savedLoopingSounds.clear();
for (SoundInstance sound : instanceToChannel.keySet()) {
if (sound.isLooping()) {
savedLoopingSounds.add(sound);
}
}
needsRestore = true;
delay = 0;
}
@Inject(method = "reload", at = @At("RETURN"))
private void onReloadComplete(CallbackInfo ci) {
needsRestore = true;
delay = 0;
}
@Inject(method = "tick", at = @At("HEAD"))
private void onTick(boolean paused, CallbackInfo ci) {
if (!needsRestore) return;
if (paused) return;
delay++;
if (delay < 0) return;
needsRestore = false;
Minecraft client = Minecraft.getInstance();
if (client.player == null || client.level == null) return;
client.execute(() -> {
for (SoundInstance sound : savedLoopingSounds) {
try {
client.getSoundManager().play(sound);
} catch (Exception ignored) {}
}
savedLoopingSounds.clear();
});
}
}

As I understand it, the SoundEngine class, after reloading the resource packs. In the code itself, it doesn't return Looping Sounds. These are the sounds of bees buzzing, minecraft:ambient.nether_biome.loop sounds, minecraft:ambient.underwater.loop sounds, Elytra sounds, and so on.

I think you, Mojang, will figure out my code that fixes this and have it fixed by snapshot 8, because this bug is annoying everyone.

This code will fix all these bugs:

MC-194284

MC-200131

MC-218145

MC-274182
MC-274183

MC-274184

Look at and study these bugs again so that you understand what exactly I mean and learn more about this bug.

Linked issues

Comments 5

Please do not make this Bug Tracker a duplicate because this Bug Tracker shows how to fix this bug which other bugs could not explain what is going on.

Please vote to fix this bug!

Please do not intentionally duplicate reports. If you have additional information, please add it to the parent reports instead of creating your own.

Will Mojang fix this bug? The point isn't that someone posted this bug, I showed how to fix it.

I run into this all the time too. Every time I reload resource packs, all looping ambient sounds just vanish—it really kills the immersion. Huge thanks for compiling all this info!

Nektoryny

(Unassigned)

Unconfirmed

26.3 Snapshot 7

Retrieved