Danger
The Adventure docs are currently a work in progress. Some areas may have limited coverage or may not be entirely up to date. Feel free to join our discord at https://discord.gg/MMfhJ8F if you have any questions.
Sound¶
Adventure contains an API to play any built-in or resource pack-provided sound. Note that not all platforms implement playing sound.
Sending a Sound¶
Sounds are referred to using Minecraft’s Keys (also known as Identifier
or ResourceLocation
). Any custom sounds from resource packs can be used. If a client does not know about sounds, it will ignore the sound (though a warning will be printed to the client log).
public void playMySound(final @NonNull Audience target) {
// Play a built-in sound at the target's location with standard volume and pitch
target.playSound(Sound.sound(Key.key("music_disc.13"), Sound.Source.MUSIC, 1f, 1f));
// Play a sound from our resource pack, with a higher pitch
target.playSound(Sound.sound(Key.key("adventure", "rawr"), Sound.Source.AMBIENT, 1f, 1.1f));
}
Stopping Sounds¶
A sound stop will stop the chosen sounds – ranging from every sound the client is playing, to specific named sounds.
public void stopMySound(final @NonNull Audience target) {
// Stop a sound for the target
target.stopSound(SoundStop.named(Key.key("music_disc.13"));
// Stop all weather sounds for the target
target.stopSound(SoundStop.source(Sound.Source.WEATHER));
// Stop all sounds for the target
target.stopSound(SoundStop.all());
}
Creating a custom sound¶
Use the sounds.json
to define sounds in a resource pack.