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, ResourceLocation 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

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

      public Collection<ResourceLocation> getAvailableSounds()
    • queueTickingSound

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

      public void play(SoundInstance sound)
      Play a sound
    • 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 activeRenderInfo)
      Updates the sound source position based on the active render info.
      Parameters:
      activeRenderInfo - The active render info
    • pause

      public void pause()
    • 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()
    • updateSourceVolume

      public void updateSourceVolume(SoundSource category, float volume)
      Updates the volume of the specified sound source category.
      Parameters:
      category - The sound source category
      volume - The new volume
    • stop

      public void stop(SoundInstance sound)
    • 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 ResourceLocation id, @Nullable SoundSource category)
      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
      category - The category of the sounds to stop, or null to stop sounds from all categories
    • getDebugString

      public String getDebugString()
    • reload

      public void reload()