| 1 | package net.minecraft.world.entity.animal.feline;
|
| 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 CatSoundVariants {
|
| 13 | public static final ResourceKey<CatSoundVariant> CLASSIC = createKey(CatSoundVariants.SoundSet.CLASSIC);
|
| 14 | public static final ResourceKey<CatSoundVariant> ROYAL = createKey(CatSoundVariants.SoundSet.ROYAL);
|
| 15 |
|
| 16 | private static ResourceKey<CatSoundVariant> createKey(final CatSoundVariants.SoundSet catSoundVariant) {
|
| 17 | return ResourceKey.create(Registries.CAT_SOUND_VARIANT, Identifier.withDefaultNamespace(catSoundVariant.getIdentifier()));
|
| 18 | }
|
| 19 |
|
| 20 | public static void bootstrap(final BootstrapContext<CatSoundVariant> context) {
|
| 21 | register(context, CLASSIC, CatSoundVariants.SoundSet.CLASSIC);
|
| 22 | register(context, ROYAL, CatSoundVariants.SoundSet.ROYAL);
|
| 23 | }
|
| 24 |
|
| 25 | private static void register(
|
| 26 | final BootstrapContext<CatSoundVariant> context, final ResourceKey<CatSoundVariant> key, final CatSoundVariants.SoundSet CatSoundVariant
|
| 27 | ) {
|
| 28 | context.register(key, SoundEvents.CAT_SOUNDS.get(CatSoundVariant));
|
| 29 | }
|
| 30 |
|
| 31 | public static Holder<CatSoundVariant> pickRandomSoundVariant(final RegistryAccess registryAccess, final RandomSource random) {
|
| 32 | return registryAccess.lookupOrThrow(Registries.CAT_SOUND_VARIANT).getRandom(random).orElseThrow();
|
| 33 | }
|
| 34 |
|
| 35 | public enum SoundSet {
|
| 36 | CLASSIC("classic", "cat"),
|
| 37 | ROYAL("royal", "cat_royal");
|
| 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 |
|