CowSoundVariants .java

net.minecraft.world.entity.animal.cow.CowSoundVariants (class, 56 lines): members: MOODY, pickRandomSoundVariant, SoundSet, CLASSIC, key, bootstrap.

net.minecraft.world.entity.animal.cowclass56 linescommon2.0 KB

API Surface (4)

void bootstrap(final BootstrapContext<CowSoundVariant> context)
Holder<CowSoundVariant> pickRandomSoundVariant(final RegistryAccess registryAccess, final RandomSource random)
String getIdentifier()
String getSoundEventIdentifier()

Fields & Constants (3)

CLASSIC
MOODY
key

String literals (3)

"classic"
"moody"
"cow_moody"

Full Source

CowSoundVariants.java56 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.entity.animal.cow;
2
3
import net.minecraft.core.Holder;
4
import net.minecraft.core.RegistryAccess;
5
import net.minecraft.core.registries.Registries;
6
import net.minecraft.data.worldgen.BootstrapContext;
7
import net.minecraft.resources.Identifier;
8
import net.minecraft.resources.ResourceKey;
9
import net.minecraft.sounds.SoundEvents;
10
import net.minecraft.util.RandomSource;
11
12
public class CowSoundVariants {
13
	public static final ResourceKey<CowSoundVariant> CLASSIC = createKey(CowSoundVariants.SoundSet.CLASSIC);
14
	public static final ResourceKey<CowSoundVariant> MOODY = createKey(CowSoundVariants.SoundSet.MOODY);
15
16
	private static ResourceKey<CowSoundVariant> createKey(final CowSoundVariants.SoundSet cowSoundVariant) {
17
		return ResourceKey.create(Registries.COW_SOUND_VARIANT, Identifier.withDefaultNamespace(cowSoundVariant.getIdentifier()));
18
	}
19
20
	public static void bootstrap(final BootstrapContext<CowSoundVariant> context) {
21
		register(context, CLASSIC, CowSoundVariants.SoundSet.CLASSIC);
22
		register(context, MOODY, CowSoundVariants.SoundSet.MOODY);
23
	}
24
25
	private static void register(
26
		final BootstrapContext<CowSoundVariant> context, final ResourceKey<CowSoundVariant> key, final CowSoundVariants.SoundSet CowSoundVariant
27
	) {
28
		context.register(key, SoundEvents.COW_SOUNDS.get(CowSoundVariant));
29
	}
30
31
	public static Holder<CowSoundVariant> pickRandomSoundVariant(final RegistryAccess registryAccess, final RandomSource random) {
32
		return registryAccess.lookupOrThrow(Registries.COW_SOUND_VARIANT).getRandom(random).orElseThrow();
33
	}
34
35
	public enum SoundSet {
36
		CLASSIC("classic", "cow"),
37
		MOODY("moody", "cow_moody");
38
39
		private final String identifier;
40
		private final String soundEventIdentifier;
41
42
		SoundSet(final String identifier, final String soundEventIdentifier) {
43
			this.identifier = identifier;
44
			this.soundEventIdentifier = soundEventIdentifier;
45
		}
46
47
		public String getIdentifier() {
48
			return this.identifier;
49
		}
50
51
		public String getSoundEventIdentifier() {
52
			return this.soundEventIdentifier;
53
		}
54
	}
55
}
56

Decompiled Minecraft 26.3 source of CowSoundVariants (net/minecraft/world/entity/animal/cow/CowSoundVariants.java) with Mojang official mappings, stored verbatim on the site.