| 1 | package net.minecraft.world.entity.animal.pig;
|
| 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 PigSoundVariants {
|
| 13 | public static final ResourceKey<PigSoundVariant> CLASSIC = createKey(PigSoundVariants.SoundSet.CLASSIC);
|
| 14 | public static final ResourceKey<PigSoundVariant> MINI = createKey(PigSoundVariants.SoundSet.MINI);
|
| 15 | public static final ResourceKey<PigSoundVariant> BIG = createKey(PigSoundVariants.SoundSet.BIG);
|
| 16 |
|
| 17 | private static ResourceKey<PigSoundVariant> createKey(final PigSoundVariants.SoundSet pigSoundVariant) {
|
| 18 | return ResourceKey.create(Registries.PIG_SOUND_VARIANT, Identifier.withDefaultNamespace(pigSoundVariant.getIdentifier()));
|
| 19 | }
|
| 20 |
|
| 21 | public static void bootstrap(final BootstrapContext<PigSoundVariant> context) {
|
| 22 | register(context, CLASSIC, PigSoundVariants.SoundSet.CLASSIC);
|
| 23 | register(context, BIG, PigSoundVariants.SoundSet.BIG);
|
| 24 | register(context, MINI, PigSoundVariants.SoundSet.MINI);
|
| 25 | }
|
| 26 |
|
| 27 | private static void register(
|
| 28 | final BootstrapContext<PigSoundVariant> context, final ResourceKey<PigSoundVariant> key, final PigSoundVariants.SoundSet PigSoundVariant
|
| 29 | ) {
|
| 30 | context.register(key, SoundEvents.PIG_SOUNDS.get(PigSoundVariant));
|
| 31 | }
|
| 32 |
|
| 33 | public static Holder<PigSoundVariant> pickRandomSoundVariant(final RegistryAccess registryAccess, final RandomSource random) {
|
| 34 | return registryAccess.lookupOrThrow(Registries.PIG_SOUND_VARIANT).getRandom(random).orElseThrow();
|
| 35 | }
|
| 36 |
|
| 37 | public enum SoundSet {
|
| 38 | CLASSIC("classic", "pig"),
|
| 39 | MINI("mini", "pig_mini"),
|
| 40 | BIG("big", "pig_big");
|
| 41 |
|
| 42 | private final String identifier;
|
| 43 | private final String soundEventIdentifier;
|
| 44 |
|
| 45 | SoundSet(final String identifier, final String soundEventIdentifier) {
|
| 46 | this.identifier = identifier;
|
| 47 | this.soundEventIdentifier = soundEventIdentifier;
|
| 48 | }
|
| 49 |
|
| 50 | public String getIdentifier() {
|
| 51 | return this.identifier;
|
| 52 | }
|
| 53 |
|
| 54 | public String getSoundEventIdentifier() {
|
| 55 | return this.soundEventIdentifier;
|
| 56 | }
|
| 57 | }
|
| 58 | }
|
| 59 |
|