Package de.mrjulsen.dragnsounds.api
Klasse ClientApi
java.lang.Object
de.mrjulsen.dragnsounds.api.ClientApi
Contains useful methods to play and manipulate custom sounds on the client side. For server-side sound management see
ServerApi.- Siehe auch:
-
Verschachtelte Klassen - Übersicht
Verschachtelte KlassenModifizierer und TypKlasseBeschreibungstatic final recordstatic enum -
Konstruktorübersicht
Konstruktoren -
Methodenübersicht
Modifizierer und TypMethodeBeschreibungstatic booleancanCancelUpload(long uploadId) Checks if the upload can be cancelled at this moment.static booleancancelUpload(long uploadId) Cancels an active file upload.static voiddeleteSound(SoundFile file, Consumer<de.mrjulsen.mcdragonlib.data.StatusResult> callback) Deletes the sound at the given location.static voiddeleteSound(SoundLocation location, String id, Consumer<de.mrjulsen.mcdragonlib.data.StatusResult> callback) Deletes the sound at the given location.static voidgetAllSoundFiles(Collection<IFilter<SoundFile>> filters, Consumer<SoundFile[]> callback) Get a list of all sound files.static voidReads all metadata from the sound file.static Optional<SoundPlaybackData> getPlaybackData(long soundId) Gets the sound playback data for the given sound id.static Optional<ChannelContext> getSound(long soundId) Returns the current sound channel instance of the given sound.static voidgetSoundFile(SoundLocation location, String id, Consumer<Optional<SoundFile>> callback) Get aSoundFilefrom the server at the given location.static voidgetSoundFilesAt(SoundLocation location, Collection<IFilter<SoundFile>> filters, Consumer<SoundFile[]> callback) Get a list of all sound files at the given location.static booleanisAnyPlaying(SoundFile file) Checks if the sound is still playing.static booleanisPlaying(long soundId) Checks if the sound is still playing.static longplaySound(SoundFile file, PlaybackConfig playback, Consumer<Long> responseCallback) Send aplaySoundrequest to the server for the given custom sound.static voidseek(long soundId, int ticks) Starts playing the sound at the given number of ticks.static voidsetAttenuationDistance(long soundId, float distance) Changes the attenuation distance of the sound.static voidsetCone(long soundId, net.minecraft.world.phys.Vec3 direction, float angleA, float angleB, float outerGain) Define the cone in which the sound can be heard.static voidsetDirection(long soundId, net.minecraft.world.phys.Vec3 direction) Set the direction of the sound source.static voidsetDoppler(long soundId, float dopplerValue, net.minecraft.world.phys.Vec3 velocity) Enable the doppler effect for the given sound if the custom sound is available.static voidsetPitch(long soundId, float pitch) Changes the pitch of the sound.static voidsetPosition(long soundId, net.minecraft.world.phys.Vec3 pos) Changes the position of the sound.static voidsetVolume(long soundId, float volume) Changes the volume of the sound.static voidshowFileDialog(boolean multiselect, Consumer<Optional<Path[]>> callback) Opens a file dialog to select one or more audio files which can then be uploaded to the server.static voidStops all playing instances the given sound.static voidstopSound(long soundId) Stops the currently playing sound.static longuploadSound(String srcFilePath, SoundFile.Builder builder, AudioSettings settings, Consumer<Optional<SoundFile>> callback, BiConsumer<ClientApi.UploadProgress, ClientApi.UploadProgress> progress, Consumer<de.mrjulsen.mcdragonlib.data.StatusResult> error) Converts the given sound file into theoggformat and uploads it to the server.
-
Konstruktordetails
-
ClientApi
public ClientApi()
-
-
Methodendetails
-
playSound
public static long playSound(SoundFile file, PlaybackConfig playback, Consumer<Long> responseCallback) Send aplaySoundrequest to the server for the given custom sound.- Parameter:
file- Information about the sound file. Do not create your own instance ofSoundFile. UsegetAllSoundFiles()instead.playback- Playback configuration with information such as position, volume, pitch and more.responseCallback- Called after the server responds with the sound id.- Gibt zurück:
- The id of the request. (NOT the id of the sound!)
-
getSound
Returns the current sound channel instance of the given sound.- Parameter:
soundId- The id of the custom sound.- Gibt zurück:
- An optional containing the
ChannelContextif available.
-
setDoppler
public static void setDoppler(long soundId, float dopplerValue, net.minecraft.world.phys.Vec3 velocity) Enable the doppler effect for the given sound if the custom sound is available. If not, nothing happens.- Parameter:
soundId- The id of the cusotm sound.dopplerValue- The doppler factor.velocity- The velocity of the sound source.
-
setCone
public static void setCone(long soundId, net.minecraft.world.phys.Vec3 direction, float angleA, float angleB, float outerGain) Define the cone in which the sound can be heard. Nothing happens if the given sound does not exist.- Parameter:
soundId- The id of the cusotm sound.direction- The doppler factor.angleA- The first angle of the cone.angleB- The second angle of the cone.outerGain- The gain at the outside of the cone.
-
setDirection
public static void setDirection(long soundId, net.minecraft.world.phys.Vec3 direction) Set the direction of the sound source. Nothing happens if the sound does not exist.- Parameter:
soundId- The id of the custom sound.direction- The direction of the sound source.
-
setVolume
public static void setVolume(long soundId, float volume) Changes the volume of the sound.- Parameter:
soundId- The id of the custom sound.volume- The new volume.
-
setPitch
public static void setPitch(long soundId, float pitch) Changes the pitch of the sound.- Parameter:
soundId- The id of the custom sound.pitch- The new pitch.
-
setAttenuationDistance
public static void setAttenuationDistance(long soundId, float distance) Changes the attenuation distance of the sound.- Parameter:
soundId- The id of the custom sound.distance- The new distance.
-
setPosition
public static void setPosition(long soundId, net.minecraft.world.phys.Vec3 pos) Changes the position of the sound.- Parameter:
soundId- The id of the custom sound.pos- The new position.
-
isPlaying
public static boolean isPlaying(long soundId) Checks if the sound is still playing.- Parameter:
soundId- The id of the custom sound.- Gibt zurück:
truewhen a sound with the given id is playing.
-
isAnyPlaying
Checks if the sound is still playing.- Parameter:
file- The custom sound file object.- Gibt zurück:
truewhen a instance of this sound is playing.
-
seek
public static void seek(long soundId, int ticks) Starts playing the sound at the given number of ticks.- Parameter:
soundId- The id of the custom sound.ticks- The amount of time in ticks to skip.
-
getPlaybackData
Gets the sound playback data for the given sound id.- Parameter:
soundId- The sound id to get the data from.- Gibt zurück:
- The playback data if available.
-
stopSound
public static void stopSound(long soundId) Stops the currently playing sound. This method will also send a notification to the server.- Parameter:
soundId- The id of the custom sound.
-
stopAllSoundInstances
Stops all playing instances the given sound. This method will also send a notification to the server.- Parameter:
file- The sound file object of the sound.
-
uploadSound
public static long uploadSound(String srcFilePath, SoundFile.Builder builder, AudioSettings settings, Consumer<Optional<SoundFile>> callback, BiConsumer<ClientApi.UploadProgress, ClientApi.UploadProgress> progress, Consumer<de.mrjulsen.mcdragonlib.data.StatusResult> error) Converts the given sound file into theoggformat and uploads it to the server.- Parameter:
srcFilePath- The path to the source audio file.builder- A Builder to define how the sound file should look like on the server (contains information such as the location, the name and more)settings- Settings for the sound conversion.callback- Called after the server returns that the upload was successfull.progress- Called when the progress changes. The first value is the client-side progress, the second value is the server-side progress. Both values may differ a bit.error- Called when an error occurs, either on the client or the server side.or if the upload was cancelled.- Gibt zurück:
- The id of the upload. Use it to cancel the upload.
-
canCancelUpload
public static boolean canCancelUpload(long uploadId) Checks if the upload can be cancelled at this moment.- Parameter:
uploadId- The id of the upload.- Gibt zurück:
trueif the upload can be cancelled.
-
cancelUpload
public static boolean cancelUpload(long uploadId) Cancels an active file upload. Does nothing if the upload cannot be cancelled at the moment.- Parameter:
uploadId- The id of the upload.- Gibt zurück:
trueif the cancellation was successfull.
-
getAllSoundFiles
public static void getAllSoundFiles(Collection<IFilter<SoundFile>> filters, Consumer<SoundFile[]> callback) Get a list of all sound files.- Parameter:
filters- Filter for the result.callback- Contains the response of the server.- Siehe auch:
- Impl Note:
- All used custom filters MUST be registered in the
FilterRegistryfirst!
-
getSoundFilesAt
public static void getSoundFilesAt(SoundLocation location, Collection<IFilter<SoundFile>> filters, Consumer<SoundFile[]> callback) Get a list of all sound files at the given location.- Parameter:
location- The location to get the sounds from.filters- Filter for the result.callback- Contains the response of the server.- Siehe auch:
- Impl Note:
- All used custom filters MUST be registered in the
FilterRegistryfirst!
-
getSoundFile
public static void getSoundFile(SoundLocation location, String id, Consumer<Optional<SoundFile>> callback) Get aSoundFilefrom the server at the given location.- Parameter:
location- The location where the sound is saved at.id- The id of the custom sound.callback- Contains the response of the server.
-
deleteSound
public static void deleteSound(SoundLocation location, String id, Consumer<de.mrjulsen.mcdragonlib.data.StatusResult> callback) Deletes the sound at the given location.- Parameter:
location- The location where the sound is saved at.id- The id of the custom sound.callback- Called after the server has responded.
-
deleteSound
public static void deleteSound(SoundFile file, Consumer<de.mrjulsen.mcdragonlib.data.StatusResult> callback) Deletes the sound at the given location.- Parameter:
file- The sound file to delete.callback- Called after the server has responded.
-
getFileMetadata
Reads all metadata from the sound file.- Parameter:
file- The custom sound file.callback- Contains all the metadata from the server response.
-
showFileDialog
Opens a file dialog to select one or more audio files which can then be uploaded to the server.- Parameter:
multiselect- Whether one or more files can be selected at once. Please note that only one file can be uploaded at once!callback- Called after the user has closed the dialog. If the user selected some files, their paths are then available. Otherwise theOptionalis empty.
-