generated from MrSphay/codex-agent-repository-kit
72 lines
2.4 KiB
Java
72 lines
2.4 KiB
Java
/*
|
|
* Decompiled with CFR 0.152.
|
|
*/
|
|
package com.vinlanx.explosionoverhaul.client;
|
|
|
|
import net.minecraft.client.resources.sounds.AbstractTickableSoundInstance;
|
|
import net.minecraft.client.resources.sounds.SoundInstance;
|
|
import net.minecraft.sounds.SoundEvent;
|
|
import net.minecraft.sounds.SoundSource;
|
|
import net.minecraft.util.RandomSource;
|
|
|
|
public class FadingMusicInstance
|
|
extends AbstractTickableSoundInstance {
|
|
private float targetVolume = 1.0f;
|
|
private float fadeSpeed = 0.0f;
|
|
private boolean shouldStop = false;
|
|
|
|
public FadingMusicInstance(SoundEvent sound, float volume, SoundSource source) {
|
|
super(sound, source, RandomSource.m_216327_());
|
|
this.f_119578_ = true;
|
|
this.f_119579_ = 0;
|
|
this.f_119573_ = volume;
|
|
this.f_119574_ = 1.0f;
|
|
this.f_119575_ = 0.0;
|
|
this.f_119576_ = 0.0;
|
|
this.f_119577_ = 0.0;
|
|
this.f_119582_ = true;
|
|
this.f_119580_ = SoundInstance.Attenuation.NONE;
|
|
this.targetVolume = volume;
|
|
}
|
|
|
|
public void m_7788_() {
|
|
if (Math.abs(this.f_119573_ - this.targetVolume) > 0.001f) {
|
|
if (this.fadeSpeed != 0.0f) {
|
|
this.f_119573_ += this.fadeSpeed;
|
|
if (this.fadeSpeed > 0.0f && this.f_119573_ >= this.targetVolume) {
|
|
this.f_119573_ = this.targetVolume;
|
|
} else if (this.fadeSpeed < 0.0f && this.f_119573_ <= this.targetVolume) {
|
|
this.f_119573_ = this.targetVolume;
|
|
}
|
|
this.f_119573_ = Math.max(0.0f, Math.min(1.0f, this.f_119573_));
|
|
} else {
|
|
this.f_119573_ = this.targetVolume;
|
|
}
|
|
}
|
|
if (this.shouldStop && this.f_119573_ <= 0.001f) {
|
|
this.m_119609_();
|
|
}
|
|
}
|
|
|
|
public void fadeTo(float targetVolume, float durationSeconds) {
|
|
this.targetVolume = Math.max(0.0f, Math.min(1.0f, targetVolume));
|
|
float totalTicks = durationSeconds * 20.0f;
|
|
float volumeDifference = this.targetVolume - this.f_119573_;
|
|
this.fadeSpeed = volumeDifference / totalTicks;
|
|
}
|
|
|
|
public void fadeOutAndStop(float durationSeconds) {
|
|
this.fadeTo(0.0f, durationSeconds);
|
|
this.shouldStop = true;
|
|
}
|
|
|
|
public float getCurrentVolume() {
|
|
return this.f_119573_;
|
|
}
|
|
|
|
public boolean hasFinishedFading() {
|
|
return this.shouldStop && this.f_119573_ <= 0.001f;
|
|
}
|
|
}
|
|
|