Class SoundUtils

java.lang.Object
com.minecolonies.api.util.SoundUtils

public final class SoundUtils extends Object
Utilities for playing sounds.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final net.minecraftforge.event.level.NoteBlockEvent.Note[]
    A much less chaotic scale (D major pentatonic) for random pitches
    static final float
    Standard pitch value.
    static final double
    Volume to play at.
  • Method Summary

    Modifier and Type
    Method
    Description
    static double
    getRandomPentatonic(net.minecraft.util.RandomSource random)
    Generates a random tone from the D major pentatonic scale
    static double
    getRandomPitch(net.minecraft.util.RandomSource random)
    Get a random pitch for a sound.
    static void
    playErrorSound(@NotNull net.minecraft.world.entity.player.Player player, @NotNull net.minecraft.core.BlockPos position)
    Play an error sound.
    static void
    playRandomSound(@NotNull net.minecraft.world.level.Level worldIn, @NotNull net.minecraft.core.BlockPos pos, @NotNull ICitizenData citizen)
    Play a random sound at the citizen.
    static void
    playSoundAtCitizen(@NotNull net.minecraft.world.level.Level worldIn, @NotNull net.minecraft.core.BlockPos position, @NotNull net.minecraft.sounds.SoundEvent event)
    Play a sound at a certain position.
    static void
    playSoundAtCitizenWith(@NotNull net.minecraft.world.level.Level worldIn, @NotNull net.minecraft.core.BlockPos position, @Nullable EventType type, @Nullable ICivilianData citizenData)
    Plays a sound with a certain chance at a certain position.
    static void
    playSoundAtCitizenWith(@NotNull net.minecraft.world.level.Level worldIn, @NotNull net.minecraft.core.BlockPos position, @Nullable EventType type, @Nullable ICivilianData citizenData, double chance)
    Plays a sound with a certain chance at a certain position.
    static void
    playSoundAtCitizenWith(@NotNull net.minecraft.world.level.Level worldIn, @NotNull net.minecraft.core.BlockPos position, @Nullable EventType type, @Nullable ICivilianData citizenData, double chance, double volume)
    Plays a sound with a certain chance at a certain position.
    static void
    playSoundForPlayer(net.minecraft.server.level.ServerPlayer playerEntity, net.minecraft.sounds.SoundEvent sound, float volume, float pitch)
    Plays a sound for the given player, but not for surrounding entities
    static void
    playSuccessSound(@NotNull net.minecraft.world.entity.player.Player player, @NotNull net.minecraft.core.BlockPos position)
    Play a success sound.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • PITCH

      public static final float PITCH
      Standard pitch value.
      See Also:
    • VOLUME

      public static final double VOLUME
      Volume to play at.
      See Also:
    • PENTATONIC

      public static final net.minecraftforge.event.level.NoteBlockEvent.Note[] PENTATONIC
      A much less chaotic scale (D major pentatonic) for random pitches
  • Method Details

    • playRandomSound

      public static void playRandomSound(@NotNull @NotNull net.minecraft.world.level.Level worldIn, @NotNull @NotNull net.minecraft.core.BlockPos pos, @NotNull @NotNull ICitizenData citizen)
      Play a random sound at the citizen.
      Parameters:
      worldIn - the world to play it in.
      pos - the pos to play it at.
      citizen - the citizen to play it for.
    • playSoundAtCitizen

      public static void playSoundAtCitizen(@NotNull @NotNull net.minecraft.world.level.Level worldIn, @NotNull @NotNull net.minecraft.core.BlockPos position, @NotNull @NotNull net.minecraft.sounds.SoundEvent event)
      Play a sound at a certain position.
      Parameters:
      worldIn - the world to play the sound in.
      position - the position to play the sound at.
      event - sound to play.
    • playSuccessSound

      public static void playSuccessSound(@NotNull @NotNull net.minecraft.world.entity.player.Player player, @NotNull @NotNull net.minecraft.core.BlockPos position)
      Play a success sound.
      Parameters:
      player - the player to play it for.
      position - the position it is played at.
    • playErrorSound

      public static void playErrorSound(@NotNull @NotNull net.minecraft.world.entity.player.Player player, @NotNull @NotNull net.minecraft.core.BlockPos position)
      Play an error sound.
      Parameters:
      player - the player to play it for.
      position - the position it is played at.
    • playSoundAtCitizenWith

      public static void playSoundAtCitizenWith(@NotNull @NotNull net.minecraft.world.level.Level worldIn, @NotNull @NotNull net.minecraft.core.BlockPos position, @Nullable @Nullable EventType type, @Nullable @Nullable ICivilianData citizenData)
      Plays a sound with a certain chance at a certain position.
      Parameters:
      worldIn - the world to play the sound in.
      position - position to play the sound at.
      type - sound to play.
      citizenData - the citizen.
    • playSoundAtCitizenWith

      public static void playSoundAtCitizenWith(@NotNull @NotNull net.minecraft.world.level.Level worldIn, @NotNull @NotNull net.minecraft.core.BlockPos position, @Nullable @Nullable EventType type, @Nullable @Nullable ICivilianData citizenData, double chance, double volume)
      Plays a sound with a certain chance at a certain position.
      Parameters:
      worldIn - the world to play the sound in.
      position - position to play the sound at.
      type - sound to play.
      citizenData - the citizen.
    • playSoundAtCitizenWith

      public static void playSoundAtCitizenWith(@NotNull @NotNull net.minecraft.world.level.Level worldIn, @NotNull @NotNull net.minecraft.core.BlockPos position, @Nullable @Nullable EventType type, @Nullable @Nullable ICivilianData citizenData, double chance)
      Plays a sound with a certain chance at a certain position.
      Parameters:
      worldIn - the world to play the sound in.
      position - position to play the sound at.
      type - sound to play.
      citizenData - the citizen.
    • getRandomPitch

      public static double getRandomPitch(net.minecraft.util.RandomSource random)
      Get a random pitch for a sound.
      Parameters:
      random - the random method.
      Returns:
      a random double for the pitch.
    • getRandomPentatonic

      public static double getRandomPentatonic(net.minecraft.util.RandomSource random)
      Generates a random tone from the D major pentatonic scale
      Parameters:
      random - the RNG instance
      Returns:
      a number representing the pitch to the sound engine
    • playSoundForPlayer

      public static void playSoundForPlayer(net.minecraft.server.level.ServerPlayer playerEntity, net.minecraft.sounds.SoundEvent sound, float volume, float pitch)
      Plays a sound for the given player, but not for surrounding entities