Files
Explosion-Overhaul/build/decompiled/com/vinlanx/explosionoverhaul/client/IntroMusicManager.java
2026-05-04 10:03:58 +00:00

141 lines
5.0 KiB
Java

/*
* Decompiled with CFR 0.152.
*/
package com.vinlanx.explosionoverhaul.client;
import com.vinlanx.explosionoverhaul.ExplosionOverhaul;
import com.vinlanx.explosionoverhaul.ModSounds;
import com.vinlanx.explosionoverhaul.client.FadingMusicInstance;
import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.sounds.SimpleSoundInstance;
import net.minecraft.client.resources.sounds.SoundInstance;
import net.minecraft.client.sounds.SoundManager;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundSource;
public class IntroMusicManager {
private static IntroMusicManager INSTANCE;
private static final float FADE_OUT_DURATION = 3.0f;
private FadingMusicInstance musicInstance;
private SimpleSoundInstance boomInstance;
private boolean isPlaying = false;
private boolean isFadingOut = false;
private boolean vanillaMusicBlocked = false;
private IntroMusicManager() {
}
public static IntroMusicManager getInstance() {
if (INSTANCE == null) {
INSTANCE = new IntroMusicManager();
}
return INSTANCE;
}
public void start() {
if (this.isPlaying) {
return;
}
SoundManager soundManager = Minecraft.m_91087_().m_91106_();
this.musicInstance = new FadingMusicInstance((SoundEvent)ModSounds.INTRO_MUSIC.get(), 0.25f, SoundSource.MASTER);
soundManager.m_120367_((SoundInstance)this.musicInstance);
ExplosionOverhaul.LOGGER.info("Started intro music with FadingMusicInstance");
this.boomInstance = SimpleSoundInstance.m_119755_((SoundEvent)((SoundEvent)ModSounds.INTRO_BOOM.get()), (float)1.0f, (float)1.0f);
soundManager.m_120367_((SoundInstance)this.boomInstance);
this.isPlaying = true;
this.vanillaMusicBlocked = true;
this.stopVanillaMusic();
}
public void startFadeOut() {
ExplosionOverhaul.LOGGER.info("startFadeOut called. isPlaying={}, isFadingOut={}", (Object)this.isPlaying, (Object)this.isFadingOut);
if (!this.isPlaying || this.isFadingOut) {
ExplosionOverhaul.LOGGER.warn("Cannot start fade out - already fading or not playing");
return;
}
if (this.musicInstance != null) {
this.musicInstance.fadeOutAndStop(3.0f);
ExplosionOverhaul.LOGGER.info("Started smooth fade out over {} seconds", (Object)Float.valueOf(3.0f));
}
this.isFadingOut = true;
}
public void stopBoomSound() {
if (this.boomInstance != null) {
try {
SoundManager soundManager = Minecraft.m_91087_().m_91106_();
soundManager.m_120399_((SoundInstance)this.boomInstance);
this.boomInstance = null;
ExplosionOverhaul.LOGGER.info("Boom sound stopped.");
}
catch (Exception e) {
ExplosionOverhaul.LOGGER.warn("Failed to stop boom sound: {}", (Object)e.toString());
}
}
}
public void stop() {
ExplosionOverhaul.LOGGER.info("stop() called! Stack trace:", (Throwable)new Exception("Music stop trace"));
SoundManager soundManager = Minecraft.m_91087_().m_91106_();
if (this.musicInstance != null) {
soundManager.m_120399_((SoundInstance)this.musicInstance);
this.musicInstance = null;
}
if (this.boomInstance != null) {
soundManager.m_120399_((SoundInstance)this.boomInstance);
this.boomInstance = null;
}
this.isPlaying = false;
this.isFadingOut = false;
this.vanillaMusicBlocked = false;
ExplosionOverhaul.LOGGER.info("Music stopped completely.");
}
public void tick(float deltaTime) {
if (!this.isPlaying) {
return;
}
if (this.isFadingOut && this.musicInstance != null) {
if (this.musicInstance.hasFinishedFading()) {
ExplosionOverhaul.LOGGER.info("Music fade out complete!");
this.stop();
return;
}
float currentVolume = this.musicInstance.getCurrentVolume();
if (currentVolume % 0.1f < 0.05f) {
ExplosionOverhaul.LOGGER.info("Fade out progress - volume: {}", (Object)Float.valueOf(currentVolume));
}
}
if (this.vanillaMusicBlocked) {
this.stopVanillaMusic();
}
}
private void stopVanillaMusic() {
Minecraft mc = Minecraft.m_91087_();
if (mc.m_91397_() != null) {
mc.m_91397_().m_120186_();
}
}
public boolean isPlaying() {
return this.isPlaying;
}
public boolean isFadingOut() {
return this.isFadingOut;
}
public boolean isVanillaMusicBlocked() {
return this.vanillaMusicBlocked;
}
public float getFadeProgress() {
if (!this.isFadingOut || this.musicInstance == null) {
return 0.0f;
}
return 1.0f - this.musicInstance.getCurrentVolume();
}
}