Skip to content

Creating Custom Sounds

Preparing the audio file

Your audio files need to be formatted in a specific way. OGG Vorbis is an open container format for multimedia data, such as audio, and is used in case of Minecraft's sound files. To avoid problems with how Minecraft handles distance of sound the audio data needs to have only a single channel (Mono).

Many modern DAWs (Digital Audio Workstation) software can import and export using this file format. In the following example the free and open-source software "Audacity" will be used to bring the audio file into the right shape, however any other DAW should suffice as well.

unprepared audio file in Audacity

In this example, a sound of a whistle is imported into Audacity. It currently is saved as a .wav file and has two audio channels (Stereo). Edit the sound to your liking and make sure to delete one of the channels using the drop-down element at the top of the "track head".

splitting Stereo track

deleting one of the channels

When exporting or rendering the audio file, make sure to choose the OGG file format. Some DAWs like REAPER might support multiple OGG audio layer formats. In this case OGG Vorbis should work just fine.

exporting as OGG file

Also keep in mind that audio files can increase the file size of your mod drastically. If needed, compress the audio when editing and exporting the file to keep the file size of your finished product to a minimum.

Adding the audio file to the mod

Add the new resources/assets/<mod id here>/sounds directory for the sounds in your mod, and put the exported audio file metal_whistle.ogg in there.

Continue with creating the resources/assets/<mod id here>/sounds.json file if it doesn't exist yet and add your sound to the sound entries.

json
{
  "metal_whistle": {
    "subtitle": "sound.mod_id.metal_whistle",
    "sounds": [
      "mod_id:metal_whistle"
    ]
  }
}

The subtitle entry provides more context for the player. The subtitle name is used in the language files in the resources/assets/<mod id here>/lang directory and will be displayed if the in-game subtitle setting is turned on and this custom sound is being played.

Register the custom sound

To add the custom sound to the mod, register a SoundEvent in the class which implements the ModInitializer entrypoint.

java
public class MyMod implements ModInitializer {		
    
    public static final String MOD_ID = "mod_id";
    public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);

	@Override
	public void onInitialize() {
		Registry.register(Registries.SOUND_EVENT, new Identifier(MyMod.MOD_ID, "metal_whistle"), SoundEvent.of(new Identifier(MyMod.MOD_ID, "metal-whistle")));
	}
}

Cleaning up the mess

Depending on how many Registry entries there are, this can get messy quickly. To avoid that, we can create a helper class called ModSounds

Add two new methods. One, which registers all the sounds and one which is used to initialize this class in the first place. After that you can comfortably add new custom SoundEvents as needed.

java
public class ModSounds {
    // ITEM_METAL_WHISTLE is the name of the custom sound event
    // and is called in the mod to use the custom sound
    public static SoundEvent ITEM_METAL_WHISTLE = registerSound("metal_whistle");

    // actual registration of all the custom SoundEvents
    static SoundEvent registerSound(String id) {
        SoundEvent sound = SoundEvent.of(new Identifier(MyMod.MOD_ID, id));
        return Registry.register(Registries.SOUND_EVENT, new Identifier(MyMod.MOD_ID, id), sound);
    }
    
    // called in the ModInitializer implementing class
    // to initialize the ModSounds class
    public static void initializeSounds() {        
        MyMod.LOGGER.info("Registering " + MyMod.MOD_ID + " Sounds");
    }
}

This way, the ModInitializer implementing entrypoint class needs to only implement one line to register all custom SoundEvents.

java
public class MyMod implements ModInitializer {		
    
    public static final String MOD_ID = "mod_id";
    public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);

	@Override
	public void onInitialize() {
		MyModSounds.initializeSounds();
	}
}

Using the custom SoundEvent

Use the ModSounds class to access the custom SoundEvent.

Checkout the Playing SoundEvents page to learn how to play sounds.

Not affiliated with Mojang Studios or the Fabric Project.