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, and does not
invalid reference
have a result
.
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 Details

    • music

      @Nullable private @Nullable Music music
    • originalMusic

      private final Music originalMusic
    • playingMusic

      @Nullable private final @Nullable SoundInstance playingMusic
  • Constructor Details

    • SelectMusicEvent

      public SelectMusicEvent(Music music, @Nullable @Nullable SoundInstance playingMusic)
  • Method Details

    • getOriginalMusic

      public Music getOriginalMusic()
      Returns the original situational music that was selected.
      Returns:
      the original situational music that was selected
    • getPlayingMusic

      @Nullable public @Nullable 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 Music 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 Music 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 Music 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