Class SoundFilters

java.lang.Object
net.ixdarklord.coolcatcanvas.api.client.sound.SoundFilters

public final class SoundFilters extends Object
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(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(SoundFilterProvider)) decide sound by sound, by where it is, what it is or its category.
  • Named filters (set(Identifier, 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 Classes
    Modifier and Type
    Class
    Description
    static interface 
    A registered provider, to remove again.
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    clear(net.minecraft.resources.Identifier id)
    Takes a named filter off at once.
    static void
    clear(net.minecraft.resources.Identifier id, int fadeTicks)
    Fades a named filter out over fadeTicks, then removes it.
    static boolean
    isSet(net.minecraft.resources.Identifier id)
    Whether a named filter is on (fading out still counts).
    static void
    Filters every sound playing again.
    Adds a provider; its filter is combined with the others'.
    static void
    set(net.minecraft.resources.Identifier id, SoundFilter filter)
    Applies a named filter to every sound at once, replacing any of that name.
    static void
    set(net.minecraft.resources.Identifier id, SoundFilter filter, int fadeTicks)
    Fades a named filter in over fadeTicks, replacing any of that name (a filter already in fades from where it is to the new one).

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • register

      public static SoundFilters.Registration register(SoundFilterProvider provider)
      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

      public static void set(net.minecraft.resources.Identifier id, SoundFilter filter)
      Applies a named filter to every sound at once, replacing any of that name.
    • set

      public static void set(net.minecraft.resources.Identifier id, SoundFilter filter, int fadeTicks)
      Fades a named filter in over fadeTicks, 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.Identifier id)
      Takes a named filter off at once.
    • clear

      public static void clear(net.minecraft.resources.Identifier id, int fadeTicks)
      Fades a named filter out over fadeTicks, then removes it.
    • isSet

      public static boolean isSet(net.minecraft.resources.Identifier id)
      Whether a named filter is on (fading out still counts).