Class PlaySoundEvent

java.lang.Object
net.neoforged.bus.api.Event
net.neoforged.neoforge.client.event.sound.SoundEvent
net.neoforged.neoforge.client.event.sound.PlaySoundEvent

public class PlaySoundEvent extends SoundEvent
Fired when a sound is about to be played by the sound engine. This fires before the sound is played and before any checks on the sound (such as a zeroed volume, an empty Sound, and others). This can be used to change or prevent (by passing null) a sound from being played through setSound(SoundInstance)).

This event is not

invalid reference
cancellable
, and does not
invalid reference
have a result
.

This event is fired on the main Forge event bus, only on the logical client.

See Also:
  • Field Details

  • Constructor Details

  • Method Details

    • getName

      public String getName()
      Returns the name of the original sound. This is equivalent to the path of the location of the original sound.
      Returns:
      the name of the original sound
    • getOriginalSound

      public SoundInstance getOriginalSound()
      Returns the original sound that was to be played.
      Returns:
      the original sound that was to be played
    • getSound

      @Nullable public @Nullable SoundInstance getSound()
      Returns the sound to be played, or null if no sound will be played.
      Returns:
      the sound to be played, or null if no sound will be played
    • setSound

      public void setSound(@Nullable @Nullable SoundInstance newSound)
      Sets the sound to be played, which may be null to prevent any sound from being played.
      Parameters:
      newSound - the new sound to be played, or null for no sound