Sound .java

net.minecraft.client.resources.sounds.Sound (class): members: getAttenuationDistance, attenuationDistance, shouldPreload, SOUND_LISTER, shouldStream, Type.

net.minecraft.client.resources.soundsclass124 linesclient2.6 KB

Implements

API Surface (13)

Identifier getLocation()
Identifier getPath()
SampledFloat getVolume()
SampledFloat getPitch()
int getWeight()
Sound getSound(final RandomSource random)
void preloadIfRequired(final SoundEngine soundEngine)
Sound.Type getType()
boolean shouldStream()
boolean shouldPreload()
int getAttenuationDistance()
float getAttenuationDistance(final float volume)
String toString()

Fields & Constants (9)

SOUND_LISTER
location
volume
pitch
weight
type
stream
preload
attenuationDistance

String literals (5)

"sounds"
".ogg"
"Sound["
"file"
"event"

Code Graph: Dependencies (6)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

Sound.java124 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.client.resources.sounds;
2
3
import net.fabricmc.api.EnvType;
4
import net.fabricmc.api.Environment;
5
import net.minecraft.client.sounds.SoundEngine;
6
import net.minecraft.client.sounds.Weighted;
7
import net.minecraft.resources.FileToIdConverter;
8
import net.minecraft.resources.Identifier;
9
import net.minecraft.util.RandomSource;
10
import net.minecraft.util.valueproviders.SampledFloat;
11
import org.jspecify.annotations.Nullable;
12
13
@Environment(EnvType.CLIENT)
14
public class Sound implements Weighted<Sound> {
15
	public static final FileToIdConverter SOUND_LISTER = new FileToIdConverter("sounds", ".ogg");
16
	private final Identifier location;
17
	private final SampledFloat volume;
18
	private final SampledFloat pitch;
19
	private final int weight;
20
	private final Sound.Type type;
21
	private final boolean stream;
22
	private final boolean preload;
23
	private final int attenuationDistance;
24
25
	public Sound(
26
		final Identifier location,
27
		final SampledFloat volume,
28
		final SampledFloat pitch,
29
		final int weight,
30
		final Sound.Type type,
31
		final boolean stream,
32
		final boolean preload,
33
		final int attenuationDistance
34
	) {
35
		this.location = location;
36
		this.volume = volume;
37
		this.pitch = pitch;
38
		this.weight = weight;
39
		this.type = type;
40
		this.stream = stream;
41
		this.preload = preload;
42
		this.attenuationDistance = attenuationDistance;
43
	}
44
45
	public Identifier getLocation() {
46
		return this.location;
47
	}
48
49
	public Identifier getPath() {
50
		return SOUND_LISTER.idToFile(this.location);
51
	}
52
53
	public SampledFloat getVolume() {
54
		return this.volume;
55
	}
56
57
	public SampledFloat getPitch() {
58
		return this.pitch;
59
	}
60
61
	@Override
62
	public int getWeight() {
63
		return this.weight;
64
	}
65
66
	public Sound getSound(final RandomSource random) {
67
		return this;
68
	}
69
70
	@Override
71
	public void preloadIfRequired(final SoundEngine soundEngine) {
72
		if (this.preload) {
73
			soundEngine.requestPreload(this);
74
		}
75
	}
76
77
	public Sound.Type getType() {
78
		return this.type;
79
	}
80
81
	public boolean shouldStream() {
82
		return this.stream;
83
	}
84
85
	public boolean shouldPreload() {
86
		return this.preload;
87
	}
88
89
	public int getAttenuationDistance() {
90
		return this.attenuationDistance;
91
	}
92
93
	public float getAttenuationDistance(final float volume) {
94
		return Math.max(volume, 1.0F) * this.attenuationDistance;
95
	}
96
97
	@Override
98
	public String toString() {
99
		return "Sound[" + this.location + "]";
100
	}
101
102
	@Environment(EnvType.CLIENT)
103
	public enum Type {
104
		FILE("file"),
105
		SOUND_EVENT("event");
106
107
		private final String name;
108
109
		Type(final String name) {
110
			this.name = name;
111
		}
112
113
		public static Sound.@Nullable Type getByName(final String name) {
114
			for (Sound.Type type : values()) {
115
				if (type.name.equals(name)) {
116
					return type;
117
				}
118
			}
119
120
			return null;
121
		}
122
	}
123
}
124

Decompiled Minecraft 26.3 source of Sound (net/minecraft/client/resources/sounds/Sound.java) with Mojang official mappings, stored verbatim on the site.