Package net.minecraft.client.sounds
Class SoundManager
java.lang.Object
net.neoforged.neoforge.resource.ContextAwareReloadListener
net.minecraft.server.packs.resources.SimplePreparableReloadListener<SoundManager.Preparations>
net.minecraft.client.sounds.SoundManager
- All Implemented Interfaces:
PreparableReloadListener
The SoundManager class is responsible for managing sound events and playing sounds.
It handles sound event registrations, caching of sound resources, and sound playback.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classThe Preparations class represents the prepared sound event registrations and caches for applying to the sound manager.Nested classes/interfaces inherited from interface net.minecraft.server.packs.resources.PreparableReloadListener
PreparableReloadListener.PreparationBarrier -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Soundstatic final ResourceLocationprivate static final com.google.gson.Gsonstatic final Soundstatic final WeighedSoundEventsstatic final ResourceLocation(package private) static final org.slf4j.Loggerprivate final Map<ResourceLocation, WeighedSoundEvents> private static final com.google.gson.reflect.TypeToken<Map<String, SoundEventRegistration>> private final Map<ResourceLocation, Resource> private final SoundEngineprivate static final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddListener(SoundEventListener listener) protected voidapply(SoundManager.Preparations object, ResourceManager resourceManager, ProfilerFiller profiler) Applies the prepared sound event registrations and caches to the sound manager.voiddestroy()voidgetSoundEvent(ResourceLocation location) Returns The sound event associated with the specific ResourceLocation, ornullif not found.booleanisActive(SoundInstance sound) Checks if the specified sound is active (playing or scheduled to be played).voidpause()voidplay(SoundInstance sound) Play a soundvoidplayDelayed(SoundInstance sound, int delay) Plays a sound with a delay in ticks.protected SoundManager.Preparationsprepare(ResourceManager resourceManager, ProfilerFiller profiler) Performs any reloading that can be done off-thread, such as file IOvoidqueueTickingSound(TickableSoundInstance tickableSound) Queues a ticking sound to be played.voidreload()voidremoveListener(SoundEventListener listener) voidresume()voidstop()voidstop(SoundInstance sound) voidstop(ResourceLocation id, SoundSource category) Stops all sounds associated with the specified ID and category.voidtick(boolean isGamePaused) Updates the sound manager's tick state.voidupdateSource(Camera activeRenderInfo) Updates the sound source position based on the active render info.voidupdateSourceVolume(SoundSource category, float volume) Updates the volume of the specified sound source category.(package private) static booleanvalidateSoundResource(Sound sound, ResourceLocation location, ResourceProvider resourceProvider) Validates a sound resourceMethods inherited from class net.minecraft.server.packs.resources.SimplePreparableReloadListener
reloadMethods inherited from class net.neoforged.neoforge.resource.ContextAwareReloadListener
getContext, getRegistryLookup, injectContext, makeConditionalOpsMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.minecraft.server.packs.resources.PreparableReloadListener
getName
-
Field Details
-
EMPTY_SOUND_LOCATION
-
EMPTY_SOUND
-
INTENTIONALLY_EMPTY_SOUND_LOCATION
-
INTENTIONALLY_EMPTY_SOUND_EVENT
-
INTENTIONALLY_EMPTY_SOUND
-
LOGGER
static final org.slf4j.Logger LOGGER -
SOUNDS_PATH
- See Also:
-
GSON
private static final com.google.gson.Gson GSON -
SOUND_EVENT_REGISTRATION_TYPE
private static final com.google.gson.reflect.TypeToken<Map<String,SoundEventRegistration>> SOUND_EVENT_REGISTRATION_TYPE -
registry
-
soundEngine
-
soundCache
-
-
Constructor Details
-
SoundManager
-
-
Method Details
-
prepare
protected SoundManager.Preparations prepare(ResourceManager resourceManager, ProfilerFiller profiler) Performs any reloading that can be done off-thread, such as file IO- Specified by:
preparein classSimplePreparableReloadListener<SoundManager.Preparations>- Parameters:
resourceManager- The resource manager in-charge of loading sound filesprofiler- The sound profiler
-
apply
protected void apply(SoundManager.Preparations object, ResourceManager resourceManager, ProfilerFiller profiler) Applies the prepared sound event registrations and caches to the sound manager.- Specified by:
applyin classSimplePreparableReloadListener<SoundManager.Preparations>- Parameters:
object- The prepared sound event registrations and cachesresourceManager- The resource managerprofiler- The profiler
-
getAvailableSoundDevices
-
getListenerTransform
-
validateSoundResource
static boolean validateSoundResource(Sound sound, ResourceLocation location, ResourceProvider resourceProvider) Validates a sound resource- Parameters:
sound- The sound to validatelocation- The location of the sound eventresourceProvider- The resource provider- Returns:
trueif the sound resource is valid,falseotherwise
-
getSoundEvent
Returns The sound event associated with the specific ResourceLocation, ornullif not found.- Parameters:
location- The location of the sound event- Returns:
- The sound event associated with the specific ResourceLocation, or
nullif not found
-
getAvailableSounds
-
queueTickingSound
Queues a ticking sound to be played.- Parameters:
tickableSound- The ticking sound instance
-
play
Play a sound -
playDelayed
Plays a sound with a delay in ticks.- Parameters:
sound- The sound instance to playdelay- The delay in ticks before playing the sound
-
updateSource
Updates the sound source position based on the active render info.- Parameters:
activeRenderInfo- The active render info
-
pause
public void pause() -
stop
public void stop() -
destroy
public void destroy() -
emergencyShutdown
public void emergencyShutdown() -
tick
public void tick(boolean isGamePaused) Updates the sound manager's tick state.- Parameters:
isGamePaused-trueif the game is paused,falseotherwise
-
resume
public void resume() -
updateSourceVolume
Updates the volume of the specified sound source category.- Parameters:
category- The sound source categoryvolume- The new volume
-
stop
-
isActive
Checks if the specified sound is active (playing or scheduled to be played).- Parameters:
sound- The sound instance to check- Returns:
trueif the sound is active,falseotherwise
-
addListener
-
removeListener
-
stop
Stops all sounds associated with the specified ID and category.- Parameters:
id- The ID of the sounds to stop, or null to stop all soundscategory- The category of the sounds to stop, or null to stop sounds from all categories
-
getDebugString
-
reload
public void reload()
-