Interface FabricSoundInstance
SoundInstance
.
This interface is implicitly implemented on all SoundInstance
s via a mixin and interface injection.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final Identifier
An empty sound, which may be used as a placeholder in yoursounds.json
file for sounds with custom audio streams. -
Method Summary
Modifier and TypeMethodDescriptiondefault CompletableFuture<AudioStream>
getAudioStream
(SoundLoader loader, Identifier id, boolean repeatInstantly) Loads the audio stream for this sound.
-
Field Details
-
EMPTY_SOUND
An empty sound, which may be used as a placeholder in yoursounds.json
file for sounds with custom audio streams.- See Also:
-
-
Method Details
-
getAudioStream
default CompletableFuture<AudioStream> getAudioStream(SoundLoader loader, Identifier id, boolean repeatInstantly) Loads the audio stream for this sound.By default this will load
.ogg
files from active resource packs. It may be overridden to provide a customAudioStream
implementation which provides audio from another source, such as over the network or driven from user input.Usage Example
Creating a sound with a custom audio stream requires the following:
Firstly, an entry in
sounds.json
. The name can be set to any sound (though it is recommended to use the dummyEMPTY_SOUND
), and the "stream" property set to true:{ "custom_sound": {"sounds": [{"name": "fabric-sound-api-v1:empty", "stream": true}]} }
You should then define your own implementation of
AudioStream
, which provides audio data to the sound engine.Finally, you'll need an implementation of
SoundInstance
which overridesgetAudioStream(net.minecraft.client.sound.SoundLoader, net.minecraft.util.Identifier, boolean)
to return your custom implementation.SoundInstance.getSound()
should return the newly-added entry insounds.json
.class CustomSound extends AbstractSoundInstance { CustomSound() { // Use the sound defined in sounds.json super(new Identifier("mod_id", "custom_sound"), SoundCategory.BLOCKS, SoundInstance.createRandom()); } @Override public CompletableFuture<AudioStream> getAudioStream(SoundLoader loader, Identifier id, boolean repeatInstantly) { // Return your custom AudioStream implementation. return CompletableFuture.completedFuture(new CustomStream()); } }
- Parameters:
loader
- The default sound loader, capable of loading.ogg
files.id
- The resolved sound ID, equal toSoundInstance.getSound()
's location.repeatInstantly
- Whether this sound should loop. This is true when the sound is repeatable and has no delay.- Returns:
- the loaded audio stream
-