Class WeighedSoundEvents

java.lang.Object
net.minecraft.client.sounds.WeighedSoundEvents
All Implemented Interfaces:
Weighted<Sound>

public class WeighedSoundEvents extends Object implements Weighted<Sound>
The WeighedSoundEvents class represents a collection of weighted sound events. It implements the Weighted interface to provide weighted selection of sounds.
  • Field Details

  • Constructor Details

    • WeighedSoundEvents

      public WeighedSoundEvents(ResourceLocation pLocation, @Nullable String pSubtitleKey)
      Parameters:
      pLocation - The resource location of the sound events
      pSubtitleKey - The key for the subtitle translation component, or null if no subtitle is provided
  • Method Details

    • getWeight

      public int getWeight()
      Specified by:
      getWeight in interface Weighted<Sound>
    • getSound

      public Sound getSound(RandomSource pRandomSource)
      Retrieves a randomly selected sound from the sound events based on their weights. The selection is performed using the provided random source.

      Specified by:
      getSound in interface Weighted<Sound>
      Parameters:
      pRandomSource - the random source used for sound selection
      Returns:
      A randomly selected sound from the sound events The random source used for sound selection
    • addSound

      public void addSound(Weighted<Sound> pAccessor)
      Adds a sound event to the collection.
      Parameters:
      pAccessor - The weighted accessor for the sound event to be added
    • getSubtitle

      @Nullable public Component getSubtitle()
    • preloadIfRequired

      public void preloadIfRequired(SoundEngine pEngine)
      Preloads the sound events into the sound engine if required. This method is called to preload the sounds associated with the sound events into the sound engine, ensuring they are ready for playback.
      Specified by:
      preloadIfRequired in interface Weighted<Sound>
      Parameters:
      pEngine - The sound engine used for sound preloading