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

  • Constructor Details

    • SoundManager

      public SoundManager(Options options)
  • Method Details

    • prepare

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

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

      public List<String> getAvailableSoundDevices()
    • getListenerTransform

      public ListenerTransform getListenerTransform()
    • validateSoundResource

      static boolean validateSoundResource(Sound sound, Identifier location, ResourceProvider resourceProvider)
      Validates a sound resource
      Parameters:
      sound - The sound to validate
      location - 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)
      Parameters:
      location - The location of the sound event
      Returns:
      The sound event associated with the specific Identifier, or null if not found
    • getAvailableSounds

      public Collection<Identifier> getAvailableSounds()
    • queueTickingSound

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

    • playDelayed

      public void playDelayed(SoundInstance sound, int delay)
      Plays a sound with a delay in ticks.
      Parameters:
      sound - 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 camera.
      Parameters:
      camera - The active camera
    • pauseAllExcept

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

      public void stop()
    • destroy

      public void destroy()
    • emergencyShutdown

      public void emergencyShutdown()
    • tick

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

      public void resume()
    • refreshCategoryVolume

      public void refreshCategoryVolume(SoundSource soundSource)
    • stop

      public void stop(SoundInstance sound)
    • updateCategoryVolume

      public void updateCategoryVolume(SoundSource soundSource, float volume)
    • isActive

      public boolean isActive(SoundInstance sound)
      Checks if the specified sound is active (playing or scheduled to be played).
      Parameters:
      sound - 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 id, @Nullable SoundSource source)
      Stops all sounds associated with the specified ID and category.
      Parameters:
      id - The ID of the sounds to stop, or null to stop all sounds
      source - The source of the sounds to stop, or null to stop sounds from all sources
    • getDebugString

      public String getDebugString()
    • reload

      public void reload()