Class SelectMusicEvent

java.lang.Object
net.neoforged.bus.api.Event
net.neoforged.neoforge.client.event.SelectMusicEvent
All Implemented Interfaces:
net.neoforged.bus.api.ICancellableEvent

public class SelectMusicEvent extends net.neoforged.bus.api.Event implements net.neoforged.bus.api.ICancellableEvent
Fired when the MusicManager checks what situational music should be used. This fires before the music begins playing.
If the music is set to null by a modder, it will cancel any music that was already playing.

Note that the higher priority you make your event listener, the earlier the music will be set.
Because of this, if you want your music to take precedence over others (perhaps you want to have seperate nighttime music for a biome for instance) then you may want it to have a lower priority.

To make your music instantly play rather than waiting for the playing music to stop, set the music to one that is set to replace the current music.

Higher priorities would likely be better suited for biome-based or dimension-based musics, whereas lower priority is likely good for specific structures or situations.

This event is cancellable.
If the event is canceled, then whatever the latest music set was will be used as the music.
This event is fired on the main Forge event bus,
only on the logical client.
  • Field Summary

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

    Constructors
    Constructor
    Description
    SelectMusicEvent(net.minecraft.client.sounds.MusicInfo music, @Nullable net.minecraft.client.resources.sounds.SoundInstance playingMusic)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    @Nullable net.minecraft.client.sounds.MusicInfo
    Returns the Music to be played, or null if any playing music should be cancelled.
    net.minecraft.client.sounds.MusicInfo
    Returns the original situational music that was selected.
    @Nullable net.minecraft.client.resources.sounds.SoundInstance
    Returns the current track that the MusicManager is playing, or null if there is none.
    void
    overrideMusic(@Nullable net.minecraft.client.sounds.MusicInfo newMusic)
    Sets the music and then cancels the event so that other listeners will not be invoked.
    Note that listeners using SubscribeEvent.receiveCanceled() will still be able to override this, but by default they will not
    void
    setMusic(@Nullable net.minecraft.client.sounds.MusicInfo newMusic)
    Changes the situational music.

    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

    • music

      @Nullable private @Nullable net.minecraft.client.sounds.MusicInfo music
    • originalMusic

      private final net.minecraft.client.sounds.MusicInfo originalMusic
    • playingMusic

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

    • SelectMusicEvent

      public SelectMusicEvent(net.minecraft.client.sounds.MusicInfo music, @Nullable @Nullable net.minecraft.client.resources.sounds.SoundInstance playingMusic)
  • Method Details

    • getOriginalMusic

      public net.minecraft.client.sounds.MusicInfo getOriginalMusic()
      Returns the original situational music that was selected.
      Returns:
      the original situational music that was selected
    • getPlayingMusic

      @Nullable public @Nullable net.minecraft.client.resources.sounds.SoundInstance getPlayingMusic()
      Returns the current track that the MusicManager is playing, or null if there is none.
      Returns:
      the current track that the MusicManager is playing, or null if there is none
    • getMusic

      @Nullable public @Nullable net.minecraft.client.sounds.MusicInfo getMusic()
      Returns the Music to be played, or null if any playing music should be cancelled.
      Returns:
      the Music to be played, or null if any playing music should be cancelled
    • setMusic

      public void setMusic(@Nullable @Nullable net.minecraft.client.sounds.MusicInfo newMusic)
      Changes the situational music. If this is set to null, any currently playing music will be cancelled.
      If this was null but on the next tick isn't, the music given will be immediately played.

    • overrideMusic

      public void overrideMusic(@Nullable @Nullable net.minecraft.client.sounds.MusicInfo newMusic)
      Sets the music and then cancels the event so that other listeners will not be invoked.
      Note that listeners using SubscribeEvent.receiveCanceled() will still be able to override this, but by default they will not