Minecraft Modding: Organizing And Using Sound Assets

Introduction


In 1.7.2 and later, the way sounds are organized is bit different than in previous versions and it can take a little bit of attention to get it right.  Also, sounds now must use a special format called OGG that some people may not be that familiar with.  All these need to be described in a JSON file which is a human-readable format for hierarchical tagged information.

This tutorial gives an introduction to these topics.  My examples are related to entity sounds, but the concepts should apply to other sound types in your mods.

    Convert Entity Sound Assets Into OGG Format


    For use in Minecraft, all your sound asset files should be OGG format. The OGG format (also called "Ogg Vorbis") has the benefit of being entirely open source and patent-free.

    Your sound assets cannot be in MP3, WAV, or other such common formats but if you have such files you want to use it is easy to convert them.

    Tip: Free converters are available to convert MP3 and WAV to OGG (I use one called “FreeMP3WMAOGGConverter”).

    Tip: To listen to OGG files (perhaps to test that your file conversions worked) you can use the open source VLC media player.

    Name Your Sound Asset Files Meaningfully


    As you make mods, you'll find that for some mods you'll have a lot of sound assets.  Like everything in programming, I suggest you name your files meaningfully.

    Warning: I'm not certain but it seems like it may be necessary (or at least common practice) to use all lowercase names for your sound asset files.

    Put Entity Sound Assets Into Proper Folders


    Warning: For those coming from earlier versions, in 1.7.2 the assets folder for Minecraft sounds changed to “sounds” (plural). So an example sounds path for one of my mods is:
    ModdingWorkspace\WildAnimalsPlus\src\main\resources\assets\wildanimals\sounds\mob\elephant


    Update sounds.json File As You Add Sound Assets


    In 1.7.2 we use a JSON format to index our sounds assets (the assets themselves are arranged in various subfolders).  JSON has the advantages of being open source, human-readable, and supported well in Java.

    Ensure The sounds.json File Is In Correct Folder


    Key point: The sounds.json file should not be in the actual sounds asset folder, but rather at top level of assets for the mod.

    Tip: Make sure the sounds.json is "seen" by Eclipse in the package explorer.  You may need to import the file (rather than just saving it).

    For example, in one of my mods, the sounds.json is in: ModdingWorkspace\WildAnimalsPlus\src\main\resources\assets\wildanimals 

    Edit The sounds.json File


    Minecraft has defined a series of JSON tags to serve as an index to sound files.  In particular it maps names that you can reference in your mod code to actual file names.

    In that mapping you can categorize the types of sound (this mostly is used for the volume slider controls), but also allows for some interesting functionality such as you can have an array of sounds associated with a tag which allows for some randomness, or you can chain together "events" (according to Dinnerbone).

    Tip:  It is easy to mess up the JSON because it has a lot of nested brackets.  So you can use an online JSON validator to check that the JSON is properly constructed.  It is cool because they will allow you to collapse and expand the hierarchy.

    Key point: The file names in your JSON should omit the .ogg file extension.

    Example from one of my mod's sounds.json:

    {
        "mob.bigCat.bark":
        {
            "category": "neutral",
            "sounds":
            [
                "mob/tiger/bark1",
                "mob/tiger/bark2",
                "mob/tiger/bark3"
            ]
        },
        "mob.bigCat.death":
        {
            "category": "neutral",
            "sounds":
            [
                "mob/tiger/death"
            ]
        },
        "mob.bigCat.growl":
        {
            "category": "neutral",
            "sounds":
            [
                "mob/tiger/growl1",
                "mob/tiger/growl2",
                "mob/tiger/growl3",
                "mob/tiger/growl4"
            ]
        }
    }
    

    It  should be fairly self-explanatory.  You can see that I'm simply giving names to sounds, along with a category, and associating them with actual sound files.  The interesting thing is that for some names I give multiple files -- this creates some variety (they will be randomly selected).  In this example, the growl will have variety between four actual growl sounds.

    Referencing A Sound Asset From Your Code


    Once the sounds.json is set up, you can reference the sound asset by using the name tag for the sound.

    For example, to play a growl within an entity class:

    playSound("wildanimals:mob.bigCat.growl", getSoundVolume(), getSoundPitch())

    Where wildanimals is the name of the mod as reflected in your assets file path.  In other words, the above example would play the sound from the assets.wildanimals.sounds.mob.bigCat folder.

    Conclusion


    Hope this helps.  Please feel free to write suggestions for corrections or clarifications!

    13 comments:

    1. Its not working:
      Error [16:42:08] [Client thread/WARN]: Unable to play unknown soundEvent: gamecity:mob.kees98nl.death

      Path: C:\Users\rik_robots\Desktop\forge\src\main\resources\assets\gamecity\sounds\mob\kees98nl\death.ogg

      Java:
      @Override
      protected String getDeathSound(){
      return "gamecity:mob.kees98nl.death";
      }
      Json:

      {
      "mob.kees98nl.death":
      {
      "category": "neutral",
      "sounds":
      [
      "mob/kees98nl/death"
      ]
      }
      }

      ReplyDelete
      Replies
      1. A couple things to check. Where is the sounds.json file located? I think it should be in C:\Users\rik_robots\Desktop\forge\src\main\resources\assets\gamecity. A lot of people make a mistake of putting it into the sounds folder, but it should be in the mod's asset top level.

        The other things is ensuring that "gamecity" is properly recognized as your mod's id? What is your code that set's the mod id name? It should be an annotation in your main class.

        Delete
      2. its an string in the class "ref" and sounds.json is located in C:\Users\rik_robots\Desktop\forge\src\main\resources\assets\gamecity

        Delete
    2. And textures and other things are loading only the sound wont work

      ReplyDelete
    3. i using mcreator a modmaker. i have the same problem the sounds wont work. this is possably i think... important:



      /**
      * Returns the sound this mob makes while it's alive.
      */
      protected String getLivingSound()
      {
      return "ModName:mob.gooselive";
      }

      /**
      * Returns the sound this mob makes when it is hurt.
      */
      protected String getHurtSound()
      {
      return "ModName:mob.goosehit";
      }

      /**
      * Returns the sound this mob makes on death.
      */
      protected String getDeathSound()
      {
      return "ModName:mob.goosedie";
      }

      My sound.json is locatat in my minecraft folder in mods in a .zip and than assets/ModName and my sounds are in sounds\mob folder inside the ModName folder.

      this is my sound.json:

      {
      "mob.goosedie": {"category": "neutral","sounds": ["mob/goosedie"]},
      "mob.goosehit": {"category": "neutral","sounds": ["mob/goosehit"]},
      "mob.gooselive": {"category": "neutral","sounds": ["mob/gooselive"]},


      Sooooo :D PLEAS HELP . THANKS A LOT!

      ReplyDelete
      Replies
      1. You keep saying sound.json but do you mean sounds.json? You have to spell the name exactly right which is sounds plural.

        Otherwise, can you give the full path for where your sounds.json file is? Most people put it in the wrong location.

        Are other assets like textures working?

        Delete
      2. Im using a programm named Mcreator, its a one man project, and this program has a bug, the custom mobsounds wont work. if you will fix it ,then youre an awsome HERO MAN!!! Here look at it: http://mcreator.pylo.co/ Thanks ;)

        Delete
      3. Have you considered using Eclipse instead Marcell? Most modding tutorials online assume you're using some form of Java IDE rather than MCreator. I would personally suggest Eclipse as it's easy to get to grips with as long as you understand the fundamentals of Java

        Delete
      4. Have you considered using Eclipse instead Marcell? Most modding tutorials online assume you're using some form of Java IDE rather than MCreator. I would personally suggest Eclipse as it's easy to get to grips with as long as you understand the fundamentals of Java

        Delete
    4. Just a quick question... how would I call a default Minecraft sound instead of a custom one? If I'm being thick and looking at the wrong tutorial I'd appreciate a link to one that explains that! Thanks :)

      ReplyDelete
      Replies
      1. Instead of putting your mod id in the beginning of the string you just put nothing -- or you can put "minecraft:".

        Delete
    5. Just a quick question... how would I call a default Minecraft sound instead of a custom one? If I'm being thick and looking at the wrong tutorial I'd appreciate a link to one that explains that! Thanks :)

      ReplyDelete
    6. This comment has been removed by the author.

      ReplyDelete