Class SoundFilters
java.lang.Object
net.ixdarklord.coolcatcanvas.api.client.sound.SoundFilters
Muffles, roughens and echoes the game's sounds: a player hiding in a chest hears the world through its walls, one
under a spell hears it from far away, a cave rings. Every sound gets the filters below combined
(
SoundFilter.then(net.ixdarklord.coolcatcanvas.api.client.sound.SoundFilter)): a low-pass filter on its OpenAL source, and as much of it as they say sent, filtered the
same, through a distortion and into a reverb.
Two ways to filter:
- Providers (
register(net.ixdarklord.coolcatcanvas.api.client.sound.SoundFilterProvider)) decide sound by sound, by where it is, what it is or its category. - Named filters (
set(net.minecraft.resources.ResourceLocation, net.ixdarklord.coolcatcanvas.api.client.sound.SoundFilter)) apply to every sound but the menus' clicks, music included, and fade in and out on their own. The server can set them too (api.sound.SoundFilterControl).
SoundFilters.register(SoundFilterProvider.inWorld(position -> hidden ? SoundFilter.muffled(0.8F) : SoundFilter.NONE));
SoundFilters.refresh(); // after `hidden` changed
SoundFilters.set(MyMod.id("underwater"), new SoundFilter(0.6F, 0.1F), 20); // fades in over a second
SoundFilters.clear(MyMod.id("underwater"), 40); // and out over two
A sound is filtered when it starts and each time it moves; named filters re-filter what is playing as they fade, and
refresh() does it for when a provider's answers change. Without OpenAL's EFX extension (rare: the game's own
OpenAL Soft has it) sounds are left as they are.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceA registered provider, to remove again. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidclear(net.minecraft.resources.ResourceLocation id) Takes a named filter off at once.static voidclear(net.minecraft.resources.ResourceLocation id, int fadeTicks) Fades a named filter out overfadeTicks, then removes it.static booleanisSet(net.minecraft.resources.ResourceLocation id) Whether a named filter is on (fading out still counts).static voidrefresh()Filters every sound playing again.static SoundFilters.Registrationregister(SoundFilterProvider provider) Adds a provider; its filter is combined with the others'.static voidset(net.minecraft.resources.ResourceLocation id, SoundFilter filter) Applies a named filter to every sound at once, replacing any of that name.static voidset(net.minecraft.resources.ResourceLocation id, SoundFilter filter, int fadeTicks) Fades a named filter in overfadeTicks, replacing any of that name (a filter already in fades from where it is to the new one).
-
Method Details
-
register
Adds a provider; its filter is combined with the others'. -
refresh
public static void refresh()Filters every sound playing again. Called from the game thread; the work is done on the sound thread. -
set
Applies a named filter to every sound at once, replacing any of that name. -
set
public static void set(net.minecraft.resources.ResourceLocation id, SoundFilter filter, int fadeTicks) Fades a named filter in overfadeTicks, replacing any of that name (a filter already in fades from where it is to the new one). -
clear
public static void clear(net.minecraft.resources.ResourceLocation id) Takes a named filter off at once. -
clear
public static void clear(net.minecraft.resources.ResourceLocation id, int fadeTicks) Fades a named filter out overfadeTicks, then removes it. -
isSet
public static boolean isSet(net.minecraft.resources.ResourceLocation id) Whether a named filter is on (fading out still counts).
-