Class PlayLevelSoundEvent

java.lang.Object
net.neoforged.bus.api.Event
net.neoforged.neoforge.event.PlayLevelSoundEvent
All Implemented Interfaces:
net.neoforged.bus.api.ICancellableEvent
Direct Known Subclasses:
PlayLevelSoundEvent.AtEntity, PlayLevelSoundEvent.AtPosition

public class PlayLevelSoundEvent extends net.neoforged.bus.api.Event implements net.neoforged.bus.api.ICancellableEvent
PlayLevelSoundEvent is fired when a sound is played on a Level. This event is fired from Level.playSound(net.minecraft.world.entity.Entity, net.minecraft.core.BlockPos, net.minecraft.sounds.SoundEvent, net.minecraft.sounds.SoundSource, float, float), Level.playSeededSound(net.minecraft.world.entity.player.Player, double, double, double, net.minecraft.core.Holder<net.minecraft.sounds.SoundEvent>, net.minecraft.sounds.SoundSource, float, float, long), and LocalPlayer.playSound(net.minecraft.sounds.SoundEvent, float, float).

getLevel() contains the level the sound is being played in. getSound() contains the sound event to be played. getOriginalVolume() contains the original volume for the sound to be played at. getOriginalPitch() contains the original pitch for the sound to be played at. getNewVolume() contains the volume the sound will be played at. getNewPitch() contains the pitch the sound will be played at.

This event is cancelable. If this event is canceled, the sound is not played.

This event does not have a result.

This event is fired on the NeoForge.EVENT_BUS.

  • Field Details Link icon

    • level Link icon

      private final Level level
    • originalVolume Link icon

      private final float originalVolume
    • originalPitch Link icon

      private final float originalPitch
    • sound Link icon

      private Holder<SoundEvent> sound
    • source Link icon

      private SoundSource source
    • newVolume Link icon

      private float newVolume
    • newPitch Link icon

      private float newPitch
  • Constructor Details Link icon

  • Method Details Link icon

    • getLevel Link icon

      public Level getLevel()
      Returns the level the sound is being played in.
      Returns:
      the level the sound is being played in
    • getSound Link icon

      @Nullable public @Nullable Holder<SoundEvent> getSound()
      Returns the sound event to be played.
      Returns:
      the sound event to be played
    • setSound Link icon

      public void setSound(@Nullable @Nullable Holder<SoundEvent> sound)
      Sets the sound event to be played.
    • getSource Link icon

      public SoundSource getSource()
      Returns the sound source.
      Returns:
      the sound source
    • setSource Link icon

      public void setSource(SoundSource source)
      Sets the sound source.
    • getOriginalVolume Link icon

      public float getOriginalVolume()
      Returns the original volume for the sound to be played at.
      Returns:
      the original volume for the sound to be played at
    • getOriginalPitch Link icon

      public float getOriginalPitch()
      Returns the original pitch for the sound to be played at.
      Returns:
      the original pitch for the sound to be played at
    • getNewVolume Link icon

      public float getNewVolume()
      Returns the volume the sound will be played at.
      Returns:
      the volume the sound will be played at
    • setNewVolume Link icon

      public void setNewVolume(float newVolume)
      Sets the volume the sound will be played at.
    • getNewPitch Link icon

      public float getNewPitch()
      Returns the pitch the sound will be played at.
      Returns:
      the pitch the sound will be played at
    • setNewPitch Link icon

      public void setNewPitch(float newPitch)
      Sets the pitch the sound will be played at.