# Upcoming changes
+Fix volume handling of battle/silly music. (Previous implementation did not
+properly reduce volume based on Minecraft's "music volume" setting.)
+
# Version NeoForge-1.25.2
Fix invalid use of throwable potions. (Previously, the Player would "drink"
// set volume
FloatControl gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
- gainControl.setValue(volume * 20.0f - 20.0f); // in decibels
+ gainControl.setValue(BattleMusic.percentageToDecibels(volume));
clip.loop(Clip.LOOP_CONTINUOUSLY);
clip.start();
return !sillyMusic.isEmpty();
}
+ /// Percentage must be between 0 and 1.
+ public static float percentageToDecibels(float percentage) {
+ if (percentage > 1.0F) {
+ return 0.0F;
+ } else if (percentage <= 0.0F) {
+ return Float.NEGATIVE_INFINITY;
+ } else {
+ return (float) (Math.log10(percentage) * 20.0);
+ }
+ }
+
private class MP3Streamer implements Runnable
{
private AtomicBoolean keepPlaying;
sdl.open(audioFormat);
{
FloatControl volumeControl = (FloatControl) sdl.getControl(FloatControl.Type.MASTER_GAIN);
- volumeControl.setValue(volume * 20.0f - 20.0f); // in decibels
+ volumeControl.setValue(BattleMusic.percentageToDecibels(volume));
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
sdl.open(audioFormat);
{
FloatControl volumeControl = (FloatControl) sdl.getControl(FloatControl.Type.MASTER_GAIN);
- volumeControl.setValue(volume * 20.0f - 20.0f); // in decibels
+ volumeControl.setValue(BattleMusic.percentageToDecibels(volume));
}
AudioInputStream ais = reader.getAudioInputStream(oggVorbisFile);