Class SoundManager

All Implemented Interfaces:
PreparableReloadListener

The SoundManager class is responsible for managing sound events and playing sounds. It handles sound event registrations, caching of sound resources, and sound playback.
  • Field Details

    • EMPTY_SOUND_LOCATION

      public static final Identifier EMPTY_SOUND_LOCATION
    • EMPTY_SOUND

      public static final Sound EMPTY_SOUND
    • INTENTIONALLY_EMPTY_SOUND_LOCATION

      public static final Identifier INTENTIONALLY_EMPTY_SOUND_LOCATION
    • INTENTIONALLY_EMPTY_SOUND_EVENT

      public static final WeighedSoundEvents INTENTIONALLY_EMPTY_SOUND_EVENT
    • INTENTIONALLY_EMPTY_SOUND

      public static final Sound INTENTIONALLY_EMPTY_SOUND
    • LOGGER

      private static final org.slf4j.Logger LOGGER
    • SOUNDS_PATH

      private static final String SOUNDS_PATH
      See Also:
    • GSON

      private static final Gson GSON
    • SOUND_EVENT_REGISTRATION_TYPE

      private static final TypeToken<Map<String, SoundEventRegistration>> SOUND_EVENT_REGISTRATION_TYPE
    • registry

      private final Map<Identifier, WeighedSoundEvents> registry
    • soundEngine

      private final SoundEngine soundEngine
    • soundCache

      private final Map<Identifier, Resource> soundCache
  • Constructor Details

    • SoundManager

      public SoundManager(Options options)
  • Method Details

    • prepare

      protected SoundManager.Preparations prepare(ResourceManager manager, ProfilerFiller profiler)
      Performs any reloading that can be done off-thread, such as file IO
      Specified by:
      prepare in class SimplePreparableReloadListener<SoundManager.Preparations>
      Parameters:
      manager - The resource manager in-charge of loading sound files
      profiler - The sound profiler
    • apply

      protected void apply(SoundManager.Preparations preparations, ResourceManager manager, ProfilerFiller profiler)
      Applies the prepared sound event registrations and caches to the sound manager.
      Specified by:
      apply in class SimplePreparableReloadListener<SoundManager.Preparations>
      Parameters:
      preparations - The prepared sound event registrations and caches
      manager - The resource manager
      profiler - The profiler
    • getAvailableSoundDevices

      public List<String> getAvailableSoundDevices()
    • getListenerTransform

      public ListenerTransform getListenerTransform()
    • validateSoundResource

      private static boolean validateSoundResource(Sound sound, Identifier eventLocation, ResourceProvider resourceProvider)
      Validates a sound resource

      Parameters:
      sound - The sound to validate
      eventLocation - The location of the sound event
      resourceProvider - The resource provider
      Returns:
      true if the sound resource is valid, false otherwise
    • getSoundEvent

      public @Nullable WeighedSoundEvents getSoundEvent(Identifier location)
      Returns The sound event associated with the specific
      invalid reference
      ResourceLocation
      , or null if not found.
      Parameters:
      location - The location of the sound event
      Returns:
      The sound event associated with the specific
      invalid reference
      ResourceLocation
      , or null if not found
    • getAvailableSounds

      public Collection<Identifier> getAvailableSounds()
    • queueTickingSound

      public void queueTickingSound(TickableSoundInstance instance)
      Queues a ticking sound to be played.
      Parameters:
      instance - The ticking sound instance
    • play

      public SoundEngine.PlayResult play(SoundInstance instance)
    • playDelayed

      public void playDelayed(SoundInstance instance, int delay)
      Plays a sound with a delay in ticks.
      Parameters:
      instance - The sound instance to play
      delay - The delay in ticks before playing the sound
    • updateSource

      public void updateSource(Camera camera)
      Updates the sound source position based on the active render info.
      Parameters:
      camera - The active render info
    • pauseAllExcept

      public void pauseAllExcept(SoundSource... ignoredSources)
    • stop

      public void stop()
    • destroy

      public void destroy()
    • emergencyShutdown

      public void emergencyShutdown()
    • tick

      public void tick(boolean paused)
      Updates the sound manager's tick state.
      Parameters:
      paused - true if the game is paused, false otherwise
    • resume

      public void resume()
    • refreshCategoryVolume

      public void refreshCategoryVolume(SoundSource category)
    • stop

      public void stop(SoundInstance soundInstance)
    • updateCategoryVolume

      public void updateCategoryVolume(SoundSource source, float gain)
    • isActive

      public boolean isActive(SoundInstance instance)
      Checks if the specified sound is active (playing or scheduled to be played).
      Parameters:
      instance - The sound instance to check
      Returns:
      true if the sound is active, false otherwise
    • addListener

      public void addListener(SoundEventListener listener)
    • removeListener

      public void removeListener(SoundEventListener listener)
    • stop

      public void stop(@Nullable Identifier sound, @Nullable SoundSource source)
      Stops all sounds associated with the specified ID and category.
      Parameters:
      sound - The ID of the sounds to stop, or null to stop all sounds
      source - The category of the sounds to stop, or null to stop sounds from all categories
    • getDebugString

      public String getDebugString()
    • reload

      public void reload()