SimpleSoundInstance .java

net.minecraft.client.resources.sounds.SimpleSoundInstance (class): members: forAmbientAddition, forLocalAmbience, forAmbientMood, forJukeboxSong, forMusic.

net.minecraft.client.resources.soundsclass116 linesclientextends AbstractSoundInstance3.8 KB

API Surface (8)

SimpleSoundInstance forUI(final SoundEvent sound, final float pitch)
SimpleSoundInstance forUI(final Holder<SoundEvent> sound, final float pitch)
SimpleSoundInstance forUI(final SoundEvent sound, final float pitch, final float volume)
SimpleSoundInstance forMusic(final SoundEvent sound)
SimpleSoundInstance forJukeboxSong(final SoundEvent sound, final Vec3 pos)
SimpleSoundInstance forLocalAmbience(final SoundEvent sound, final float pitch, final float volume)
SimpleSoundInstance forAmbientAddition(final SoundEvent sound)
SimpleSoundInstance forAmbientMood(final SoundEvent sound, final RandomSource random, final double x, final double y, final double z)

Fields & Constants (12)

random
sound
source
volume
pitch
x
y
looping
delay
attenuation
location
z

Full Source

SimpleSoundInstance.java116 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.core.BlockPos;
6
import net.minecraft.core.Holder;
7
import net.minecraft.resources.Identifier;
8
import net.minecraft.sounds.SoundEvent;
9
import net.minecraft.sounds.SoundSource;
10
import net.minecraft.util.RandomSource;
11
import net.minecraft.world.phys.Vec3;
12
13
@Environment(EnvType.CLIENT)
14
public class SimpleSoundInstance extends AbstractSoundInstance {
15
	public SimpleSoundInstance(
16
		final SoundEvent sound, final SoundSource source, final float volume, final float pitch, final RandomSource random, final BlockPos pos
17
	) {
18
		this(sound, source, volume, pitch, random, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5);
19
	}
20
21
	public static SimpleSoundInstance forUI(final SoundEvent sound, final float pitch) {
22
		return forUI(sound, pitch, 0.25F);
23
	}
24
25
	public static SimpleSoundInstance forUI(final Holder<SoundEvent> sound, final float pitch) {
26
		return forUI(sound.value(), pitch);
27
	}
28
29
	public static SimpleSoundInstance forUI(final SoundEvent sound, final float pitch, final float volume) {
30
		return new SimpleSoundInstance(
31
			sound.location(), SoundSource.UI, volume, pitch, SoundInstance.createUnseededRandom(), false, 0, SoundInstance.Attenuation.NONE, 0.0, 0.0, 0.0, true
32
		);
33
	}
34
35
	public static SimpleSoundInstance forMusic(final SoundEvent sound) {
36
		return new SimpleSoundInstance(
37
			sound.location(), SoundSource.MUSIC, 1.0F, 1.0F, SoundInstance.createUnseededRandom(), false, 0, SoundInstance.Attenuation.NONE, 0.0, 0.0, 0.0, true
38
		);
39
	}
40
41
	public static SimpleSoundInstance forJukeboxSong(final SoundEvent sound, final Vec3 pos) {
42
		return new SimpleSoundInstance(
43
			sound, SoundSource.RECORDS, 4.0F, 1.0F, SoundInstance.createUnseededRandom(), false, 0, SoundInstance.Attenuation.LINEAR, pos.x, pos.y, pos.z
44
		);
45
	}
46
47
	public static SimpleSoundInstance forLocalAmbience(final SoundEvent sound, final float pitch, final float volume) {
48
		return new SimpleSoundInstance(
49
			sound.location(), SoundSource.AMBIENT, volume, pitch, SoundInstance.createUnseededRandom(), false, 0, SoundInstance.Attenuation.NONE, 0.0, 0.0, 0.0, true
50
		);
51
	}
52
53
	public static SimpleSoundInstance forAmbientAddition(final SoundEvent sound) {
54
		return forLocalAmbience(sound, 1.0F, 1.0F);
55
	}
56
57
	public static SimpleSoundInstance forAmbientMood(final SoundEvent sound, final RandomSource random, final double x, final double y, final double z) {
58
		return new SimpleSoundInstance(sound, SoundSource.AMBIENT, 1.0F, 1.0F, random, false, 0, SoundInstance.Attenuation.LINEAR, x, y, z);
59
	}
60
61
	public SimpleSoundInstance(
62
		final SoundEvent sound,
63
		final SoundSource source,
64
		final float volume,
65
		final float pitch,
66
		final RandomSource random,
67
		final double x,
68
		final double y,
69
		final double z
70
	) {
71
		this(sound, source, volume, pitch, random, false, 0, SoundInstance.Attenuation.LINEAR, x, y, z);
72
	}
73
74
	private SimpleSoundInstance(
75
		final SoundEvent sound,
76
		final SoundSource source,
77
		final float volume,
78
		final float pitch,
79
		final RandomSource random,
80
		final boolean looping,
81
		final int delay,
82
		final SoundInstance.Attenuation attenuation,
83
		final double x,
84
		final double y,
85
		final double z
86
	) {
87
		this(sound.location(), source, volume, pitch, random, looping, delay, attenuation, x, y, z, false);
88
	}
89
90
	public SimpleSoundInstance(
91
		final Identifier location,
92
		final SoundSource source,
93
		final float volume,
94
		final float pitch,
95
		final RandomSource random,
96
		final boolean looping,
97
		final int delay,
98
		final SoundInstance.Attenuation attenuation,
99
		final double x,
100
		final double y,
101
		final double z,
102
		final boolean relative
103
	) {
104
		super(location, source, random);
105
		this.volume = volume;
106
		this.pitch = pitch;
107
		this.x = x;
108
		this.y = y;
109
		this.z = z;
110
		this.looping = looping;
111
		this.delay = delay;
112
		this.attenuation = attenuation;
113
		this.relative = relative;
114
	}
115
}
116

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