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:
  • Nested Class Summary

    Nested classes/interfaces inherited from class net.neoforged.neoforge.client.event.sound.SoundEvent

    SoundEvent.SoundSourceEvent
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final String
     
    private final net.minecraft.client.resources.sounds.SoundInstance
     
    private @Nullable net.minecraft.client.resources.sounds.SoundInstance
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    PlaySoundEvent(net.minecraft.client.sounds.SoundEngine manager, net.minecraft.client.resources.sounds.SoundInstance sound)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the name of the original sound.
    net.minecraft.client.resources.sounds.SoundInstance
    Returns the original sound that was to be played.
    @Nullable net.minecraft.client.resources.sounds.SoundInstance
    Returns the sound to be played, or null if no sound will be played.
    void
    setSound(@Nullable net.minecraft.client.resources.sounds.SoundInstance newSound)
    Sets the sound to be played, which may be null to prevent any sound from being played.

    Methods inherited from class net.neoforged.neoforge.client.event.sound.SoundEvent

    getEngine

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • name

      private final String name
    • originalSound

      private final net.minecraft.client.resources.sounds.SoundInstance originalSound
    • sound

      @Nullable private @Nullable net.minecraft.client.resources.sounds.SoundInstance sound
  • Constructor Details

    • PlaySoundEvent

      @Internal public PlaySoundEvent(net.minecraft.client.sounds.SoundEngine manager, net.minecraft.client.resources.sounds.SoundInstance sound)
  • 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 net.minecraft.client.resources.sounds.SoundInstance getOriginalSound()
      Returns the original sound that was to be played.
      Returns:
      the original sound that was to be played
    • getSound

      @Nullable public @Nullable net.minecraft.client.resources.sounds.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 net.minecraft.client.resources.sounds.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