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