Package net.neoforged.neoforge.event
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.Entity, double, double, double, net.minecraft.core.Holder<net.minecraft.sounds.SoundEvent>, net.minecraft.sounds.SoundSource, float, float, long)
, and
invalid reference
LocalPlayer#playSound
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
.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
PlayLevelSoundEvent.AtEntity is fired when a sound is played on theLevel
at anEntity
's position.static class
PlayLevelSoundEvent.AtPosition is fired when a sound is played on theLevel
at a specific position. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final net.minecraft.world.level.Level
private float
private float
private final float
private final float
private net.minecraft.core.Holder
<net.minecraft.sounds.SoundEvent> private net.minecraft.sounds.SoundSource
-
Constructor Summary
ConstructorsConstructorDescriptionPlayLevelSoundEvent
(net.minecraft.world.level.Level level, net.minecraft.core.Holder<net.minecraft.sounds.SoundEvent> sound, net.minecraft.sounds.SoundSource source, float volume, float pitch) -
Method Summary
Modifier and TypeMethodDescriptionnet.minecraft.world.level.Level
getLevel()
Returns the level the sound is being played in.float
Returns the pitch the sound will be played at.float
Returns the volume the sound will be played at.float
Returns the original pitch for the sound to be played at.float
Returns the original volume for the sound to be played at.@Nullable net.minecraft.core.Holder
<net.minecraft.sounds.SoundEvent> getSound()
Returns the sound event to be played.net.minecraft.sounds.SoundSource
Returns the sound source.void
setNewPitch
(float newPitch) Sets the pitch the sound will be played at.void
setNewVolume
(float newVolume) Sets the volume the sound will be played at.void
setSound
(@Nullable net.minecraft.core.Holder<net.minecraft.sounds.SoundEvent> sound) Sets the sound event to be played.void
setSource
(net.minecraft.sounds.SoundSource source) Sets the sound source.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface net.neoforged.bus.api.ICancellableEvent
isCanceled, setCanceled
-
Field Details
-
level
private final net.minecraft.world.level.Level level -
originalVolume
private final float originalVolume -
originalPitch
private final float originalPitch -
sound
private net.minecraft.core.Holder<net.minecraft.sounds.SoundEvent> sound -
source
private net.minecraft.sounds.SoundSource source -
newVolume
private float newVolume -
newPitch
private float newPitch
-
-
Constructor Details
-
PlayLevelSoundEvent
public PlayLevelSoundEvent(net.minecraft.world.level.Level level, net.minecraft.core.Holder<net.minecraft.sounds.SoundEvent> sound, net.minecraft.sounds.SoundSource source, float volume, float pitch)
-
-
Method Details
-
getLevel
public net.minecraft.world.level.Level getLevel()Returns the level the sound is being played in.- Returns:
- the level the sound is being played in
-
getSound
@Nullable public @Nullable net.minecraft.core.Holder<net.minecraft.sounds.SoundEvent> getSound()Returns the sound event to be played.- Returns:
- the sound event to be played
-
setSound
public void setSound(@Nullable @Nullable net.minecraft.core.Holder<net.minecraft.sounds.SoundEvent> sound) Sets the sound event to be played. -
getSource
public net.minecraft.sounds.SoundSource getSource()Returns the sound source.- Returns:
- the sound source
-
setSource
public void setSource(net.minecraft.sounds.SoundSource source) Sets the sound source. -
getOriginalVolume
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
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
public float getNewVolume()Returns the volume the sound will be played at.- Returns:
- the volume the sound will be played at
-
setNewVolume
public void setNewVolume(float newVolume) Sets the volume the sound will be played at. -
getNewPitch
public float getNewPitch()Returns the pitch the sound will be played at.- Returns:
- the pitch the sound will be played at
-
setNewPitch
public void setNewPitch(float newPitch) Sets the pitch the sound will be played at.
-