-
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathVolumeData.java
More file actions
57 lines (44 loc) · 1.68 KB
/
Copy pathVolumeData.java
File metadata and controls
57 lines (44 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package com.bvengo.soundcontroller;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.sound.PositionedSoundInstance;
import net.minecraft.client.sound.SoundInstance;
import net.minecraft.client.sound.SoundManager;
import net.minecraft.sound.SoundEvent;
import net.minecraft.util.Identifier;
public class VolumeData {
public static final Float DEFAULT_VOLUME = 1.0f;
private final Identifier soundId;
private Float volume;
public VolumeData(Identifier id, float volume) {
this.soundId = id;
this.volume = volume; // Removed clamping to allow manually setting over / under the slider
}
public VolumeData(Identifier id) {
this(id, DEFAULT_VOLUME);
}
public Identifier getId() {
return soundId;
}
public Float getVolume() {
return volume;
}
public Float getAdjustedVolume(SoundInstance sound) {
float baseCategoryVolume = MinecraftClient.getInstance().options.getSoundVolume(sound.getCategory());
float adjustment = volume * baseCategoryVolume;
return Math.max(adjustment * sound.getVolume(), 0.0F);
}
public void setVolume(float volume) {
this.volume = volume;
}
public boolean isModified() {
return !this.volume.equals(DEFAULT_VOLUME);
}
public boolean inFilter(String search, boolean showModifiedOnly) {
return (this.soundId.toString().toLowerCase().contains(search) &&
(!showModifiedOnly || this.isModified()));
}
public void playSound(SoundManager soundManager) {
SoundEvent soundEvent = SoundEvent.of(soundId);
soundManager.play(PositionedSoundInstance.master(soundEvent, 1.0f));
}
}