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:
Look at and study these bugs again so that you understand what exactly I mean and learn more about this bug.
Linked issues
duplicates 6
Comments 5
Please do not intentionally duplicate reports. If you have additional information, please add it to the parent reports instead of creating your own.
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.