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 class
The 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 Sound
static final ResourceLocation
private static final com.google.gson.Gson
static final Sound
static final WeighedSoundEvents
static final ResourceLocation
(package private) static final org.slf4j.Logger
private final Map
<ResourceLocation, WeighedSoundEvents> private static final com.google.gson.reflect.TypeToken
<Map<String, SoundEventRegistration>> private final Map
<ResourceLocation, Resource> private final SoundEngine
private static final String
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addListener
(SoundEventListener pListener) protected void
apply
(SoundManager.Preparations pObject, ResourceManager pResourceManager, ProfilerFiller pProfiler) Applies the prepared sound event registrations and caches to the sound manager.void
destroy()
void
getSoundEvent
(ResourceLocation pLocation) Returns The sound event associated with the specific ResourceLocation, ornull
if not found.boolean
isActive
(SoundInstance pSound) Checks if the specified sound is active (playing or scheduled to be played).void
pause()
void
play
(SoundInstance pSound) Play a soundvoid
playDelayed
(SoundInstance pSound, int pDelay) Plays a sound with a delay in ticks.protected SoundManager.Preparations
prepare
(ResourceManager pResourceManager, ProfilerFiller pProfiler) Performs any reloading that can be done off-thread, such as file IOvoid
queueTickingSound
(TickableSoundInstance pTickableSound) Queues a ticking sound to be played.void
reload()
void
removeListener
(SoundEventListener pListener) void
resume()
void
stop()
void
stop
(SoundInstance pSound) void
stop
(ResourceLocation pId, SoundSource pCategory) Stops all sounds associated with the specified ID and category.void
tick
(boolean pIsGamePaused) Updates the sound manager's tick state.void
updateSource
(Camera pActiveRenderInfo) Updates the sound source position based on the active render info.void
updateSourceVolume
(SoundSource pCategory, float pVolume) Updates the volume of the specified sound source category.(package private) static boolean
validateSoundResource
(Sound pSound, ResourceLocation pLocation, ResourceProvider pResourceProvider) Validates a sound resourceMethods inherited from class net.minecraft.server.packs.resources.SimplePreparableReloadListener
reload
Methods inherited from class net.neoforged.neoforge.resource.ContextAwareReloadListener
getContext, getRegistryLookup, injectContext, makeConditionalOps
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods 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 pResourceManager, ProfilerFiller pProfiler) Performs any reloading that can be done off-thread, such as file IO- Specified by:
prepare
in classSimplePreparableReloadListener<SoundManager.Preparations>
- Parameters:
pResourceManager
- The resource manager in-charge of loading sound filespProfiler
- The sound profiler
-
apply
protected void apply(SoundManager.Preparations pObject, ResourceManager pResourceManager, ProfilerFiller pProfiler) Applies the prepared sound event registrations and caches to the sound manager.- Specified by:
apply
in classSimplePreparableReloadListener<SoundManager.Preparations>
- Parameters:
pObject
- The prepared sound event registrations and cachespResourceManager
- The resource managerpProfiler
- The profiler
-
getAvailableSoundDevices
-
getListenerTransform
-
validateSoundResource
static boolean validateSoundResource(Sound pSound, ResourceLocation pLocation, ResourceProvider pResourceProvider) Validates a sound resource- Parameters:
pSound
- The sound to validatepLocation
- The location of the sound eventpResourceProvider
- The resource provider- Returns:
true
if the sound resource is valid,false
otherwise
-
getSoundEvent
Returns The sound event associated with the specific ResourceLocation, ornull
if not found.- Parameters:
pLocation
- The location of the sound event- Returns:
- The sound event associated with the specific ResourceLocation, or
null
if not found
-
getAvailableSounds
-
queueTickingSound
Queues a ticking sound to be played.- Parameters:
pTickableSound
- The ticking sound instance
-
play
Play a sound -
playDelayed
Plays a sound with a delay in ticks.- Parameters:
pSound
- The sound instance to playpDelay
- The delay in ticks before playing the sound
-
updateSource
Updates the sound source position based on the active render info.- Parameters:
pActiveRenderInfo
- 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 pIsGamePaused) Updates the sound manager's tick state.- Parameters:
pIsGamePaused
-true
if the game is paused,false
otherwise
-
resume
public void resume() -
updateSourceVolume
Updates the volume of the specified sound source category.- Parameters:
pCategory
- The sound source categorypVolume
- The new volume
-
stop
-
isActive
Checks if the specified sound is active (playing or scheduled to be played).- Parameters:
pSound
- The sound instance to check- Returns:
true
if the sound is active,false
otherwise
-
addListener
-
removeListener
-
stop
Stops all sounds associated with the specified ID and category.- Parameters:
pId
- The ID of the sounds to stop, or null to stop all soundspCategory
- The category of the sounds to stop, or null to stop sounds from all categories
-
getDebugString
-
reload
public void reload()
-