Interface FabricSoundInstance
SoundInstance.
This interface is implicitly implemented on all SoundInstances via a mixin and interface injection.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final net.minecraft.resources.IdentifierAn empty sound, which may be used as a placeholder in yoursounds.jsonfile for sounds with custom audio streams. -
Method Summary
Modifier and TypeMethodDescriptiondefault CompletableFuture<net.minecraft.client.sounds.AudioStream> getAudioStream(net.minecraft.client.sounds.SoundBufferLibrary library, net.minecraft.resources.Identifier id, boolean repeatInstantly) Loads the audio stream for this sound.
-
Field Details
-
EMPTY_SOUND
static final net.minecraft.resources.Identifier EMPTY_SOUNDAn empty sound, which may be used as a placeholder in yoursounds.jsonfile for sounds with custom audio streams.- See Also:
-
-
Method Details
-
getAudioStream
default CompletableFuture<net.minecraft.client.sounds.AudioStream> getAudioStream(net.minecraft.client.sounds.SoundBufferLibrary library, net.minecraft.resources.Identifier id, boolean repeatInstantly) Loads the audio stream for this sound.By default this will load
.oggfiles from active resource packs. It may be overridden to provide a customAudioStreamimplementation 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
SoundInstancewhich overridesgetAudioStream(SoundBufferLibrary, 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(Identifier.fromNamespaceAndPath("modid", "custom_sound"), SoundSource.BLOCKS, SoundInstance.createUnseededRandom()); } @Override public CompletableFuture<AudioStream> getAudioStream(SoundBufferLibrary library, Identifier id, boolean repeatInstantly) { // Return your custom AudioStream implementation. return CompletableFuture.completedFuture(new CustomStream()); } }- Parameters:
library- The default buffer library, capable of loading.oggfiles.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
-