Class RaccoonSoundProvider

java.lang.Object
net.kamkeyke.raccooncore.datagen.RaccoonSoundProvider
All Implemented Interfaces:
net.minecraft.data.DataProvider
Direct Known Subclasses:
AutoSoundProvider, ManualModSoundProvider

public abstract class RaccoonSoundProvider extends Object implements net.minecraft.data.DataProvider
Base data provider for generating sounds.json. To see an example of usage head to ManualModSoundProvider or AutoModSoundProvider.

This class simplifies sound registration by providing helper methods for common use cases such as single sounds, variations, and custom lists.

All sound files must be placed inside: assets/<modid>/sounds/

Supported structures:

  • Flat: sounds/my_sound.ogg
  • Subfolders: sounds/music/my_song.ogg
  • Nested: sounds/sfx/voices/voice_1.ogg

Variation rule:

  • Use the pattern name_# starting at 1
  • Example: sound_1.ogg, sound_2.ogg, sound_3.ogg

Usage:


 @Override
 protected void registerSounds(JsonObject root) {
     sound(root, "vine_boom", "misc/vine_boom");
     variations(root, "fire_cracking", "sfx/fire_crackings/fire_cracking.ogg", 5);
 }
 

This provider only generates the JSON file. Missing sound files will result in silent or broken sounds in-game.

  • Nested Class Summary

    Nested classes/interfaces inherited from interface net.minecraft.data.DataProvider

    net.minecraft.data.DataProvider.Factory<T extends net.minecraft.data.DataProvider>
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final String
     
    protected final net.minecraft.data.PackOutput
     

    Fields inherited from interface net.minecraft.data.DataProvider

    FIXED_ORDER_FIELDS, KEY_COMPARATOR, LOGGER
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    RaccoonSoundProvider(net.minecraft.data.PackOutput output, String modid)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    customPaths(com.google.gson.JsonObject root, String name, String... pathsAndFileNames)
    Registers a sound event with multiple variations from different places.
    @NotNull String
     
    protected abstract void
    registerSounds(com.google.gson.JsonObject root)
     
    @NotNull CompletableFuture<?>
    run(@NotNull net.minecraft.data.CachedOutput cache)
     
    protected void
    singleSound(com.google.gson.JsonObject root, String soundName, String pathAndFileName)
    Registers a single sound event.
    protected void
    variedSound(com.google.gson.JsonObject root, String soundName, String pathAndFileName, int count)
    Registers a sound event with multiple numbered variations.

    Methods inherited from class java.lang.Object

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

    • output

      protected final net.minecraft.data.PackOutput output
    • modid

      protected final String modid
  • Constructor Details

    • RaccoonSoundProvider

      protected RaccoonSoundProvider(net.minecraft.data.PackOutput output, String modid)
  • Method Details

    • run

      @NotNull public @NotNull CompletableFuture<?> run(@NotNull @NotNull net.minecraft.data.CachedOutput cache)
      Specified by:
      run in interface net.minecraft.data.DataProvider
    • registerSounds

      protected abstract void registerSounds(com.google.gson.JsonObject root)
    • singleSound

      protected void singleSound(com.google.gson.JsonObject root, String soundName, String pathAndFileName)
      Registers a single sound event.

      The sound file must exist inside assets/<modid>/sounds/. If it's inside a subfolder, you need to specify that subfolder as well.

      Example:

      
         singleSound(root, "cool_music", "music/cool_music.ogg");
       
      Generates:
      
         "cool_music": {
           "subtitles": "sound.<modid>.cool_music",
           "sounds": [
             "<modid>:music/cool_music"
           ]
         }
       
    • variedSound

      protected void variedSound(com.google.gson.JsonObject root, String soundName, String pathAndFileName, int count)
      Registers a sound event with multiple numbered variations.

      Files must follow the pattern: name_1, name_2, name3, ...

      Example:

      
         variedSound(root, "fire_crackling", "sfx/fire_cracklings/fire_crackling", 5);
       
      Generates:
      
         "fire_crackling": {
           "subtitles": "sound.<modid>.fire_crackling",
           "sounds": [
             "<modid>:sfx/fire_cracklings/fire_crackling_1"
             "<modid>:sfx/fire_cracklings/fire_crackling_2"
             ...
           ]
         }
       
    • customPaths

      protected void customPaths(com.google.gson.JsonObject root, String name, String... pathsAndFileNames)
      Registers a sound event with multiple variations from different places.

      Useful when you're disorganized or your sounds come from different folders for some reason. Can be used if your sounds have variations with different names too.

      Example:

      
         customPaths(root, "weird_sound",
           "music/a.ogg",
           "music/b.ogg",
           "sfx/c.ogg"
         );
       
    • getName

      @NotNull public @NotNull String getName()
      Specified by:
      getName in interface net.minecraft.data.DataProvider