How to make a sound of your own in a Minecraft mod
A sound is a SoundEvent registered in the sound event registry; assets/<mod>/sounds.json says which .ogg files it plays and its subtitle. Play it with level.playSound(null, pos, sound, SoundSource.BLOCKS, volume, pitch) on the server, and everyone near hears it.
Works on Minecraft 1.20.1 to 26.3 on NeoForge; Minecraft 1.16.5 to 26.3 on Fabric; Minecraft 1.16.5 to 1.20.1 on Forge; Minecraft 1.12.2 on Forge. Each example was compiled against its loader and version before it shipped in Linen.
- Register a SoundEvent with the id (SoundEvent.createVariableRangeEvent(id) on 1.19.3 and newer, new SoundEvent(id) before).
- Add it to assets/<mod>/sounds.json with its .ogg file and subtitle.
- Put the sound in assets/<mod>/sounds/ as Ogg Vorbis.
- Play it with level.playSound(…).
What you can change
Section titled “What you can change”The example uses these values. Change them in the code.
| Setting | In the example | What it does |
|---|---|---|
| subtitle | Chime rings |
The subtitle players see with subtitles on. |
For each loader and version
Section titled “For each loader and version”The example mod is examplemod in the package com.example.examplemod. Use your own mod id and package.
Fabric 1.19.3 to 1.21
Section titled “Fabric 1.19.3 to 1.21”Uses:
SoundEvent.createVariableRangeEventBuiltInRegistries.SOUND_EVENTLevel.playSound
src/main/java/com/example/examplemod/registry/ModSounds.java
package com.example.examplemod.registry;
import com.example.examplemod.ExampleMod;import net.minecraft.core.Registry;import net.minecraft.core.registries.BuiltInRegistries;import net.minecraft.sounds.SoundEvent;
// The mod's sounds; assets/examplemod/sounds.json says which files each plays.public final class ModSounds { public static final SoundEvent CHIME = Registry.register(BuiltInRegistries.SOUND_EVENT, ExampleMod.id("chime"), SoundEvent.createVariableRangeEvent(ExampleMod.id("chime")));
private ModSounds() { }
// Called from ExampleMod#onInitialize; loading this class registers the sounds above. public static void register() { }}In your main mod class, inside onInitialize:
ModSounds.register();In src/main/resources/assets/examplemod/sounds.json, add this entry to the top level:
"chime": { "subtitle": "subtitles.examplemod.chime", "sounds": [ "examplemod:chime" ]}In src/main/resources/assets/examplemod/lang/en_us.json:
{ "subtitles.examplemod.chime": "Chime rings"}Forge 1.17.1
Section titled “Forge 1.17.1”Uses:
SoundEvent.createVariableRangeEventDeferredRegister.createForgeRegistries.SOUND_EVENTSLevel.playSound
src/main/java/com/example/examplemod/registry/ModSounds.java
package com.example.examplemod.registry;
import com.example.examplemod.ExampleMod;import net.minecraft.resources.ResourceLocation;import net.minecraft.sounds.SoundEvent;import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;import net.minecraftforge.registries.DeferredRegister;import net.minecraftforge.registries.ForgeRegistries;import net.minecraftforge.fmllegacy.RegistryObject;
// The mod's sounds; assets/examplemod/sounds.json says which files each plays.public final class ModSounds { public static final DeferredRegister<SoundEvent> SOUND_EVENTS = DeferredRegister.create(ForgeRegistries.SOUND_EVENTS, ExampleMod.MOD_ID);
public static final RegistryObject<SoundEvent> CHIME = SOUND_EVENTS.register("chime", () -> new SoundEvent(new ResourceLocation(ExampleMod.MOD_ID, "chime")));
private ModSounds() { }
// Called from the ExampleMod constructor: puts the sounds on the mod event bus. public static void register() { SOUND_EVENTS.register(FMLJavaModLoadingContext.get().getModEventBus()); }}In your main mod class, inside <init>:
ModSounds.register();In src/main/resources/assets/examplemod/sounds.json, add this entry to the top level:
"chime": { "subtitle": "subtitles.examplemod.chime", "sounds": [ "examplemod:chime" ]}In src/main/resources/assets/examplemod/lang/en_us.json:
{ "subtitles.examplemod.chime": "Chime rings"}Forge 1.18.2 to 1.19.2
Section titled “Forge 1.18.2 to 1.19.2”Uses:
SoundEvent.createVariableRangeEventDeferredRegister.createForgeRegistries.SOUND_EVENTSLevel.playSound
src/main/java/com/example/examplemod/registry/ModSounds.java
package com.example.examplemod.registry;
import com.example.examplemod.ExampleMod;import net.minecraft.resources.ResourceLocation;import net.minecraft.sounds.SoundEvent;import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;import net.minecraftforge.registries.DeferredRegister;import net.minecraftforge.registries.ForgeRegistries;import net.minecraftforge.registries.RegistryObject;
// The mod's sounds; assets/examplemod/sounds.json says which files each plays.public final class ModSounds { public static final DeferredRegister<SoundEvent> SOUND_EVENTS = DeferredRegister.create(ForgeRegistries.SOUND_EVENTS, ExampleMod.MOD_ID);
public static final RegistryObject<SoundEvent> CHIME = SOUND_EVENTS.register("chime", () -> new SoundEvent(new ResourceLocation(ExampleMod.MOD_ID, "chime")));
private ModSounds() { }
// Called from the ExampleMod constructor: puts the sounds on the mod event bus. public static void register() { SOUND_EVENTS.register(FMLJavaModLoadingContext.get().getModEventBus()); }}In your main mod class, inside <init>:
ModSounds.register();In src/main/resources/assets/examplemod/sounds.json, add this entry to the top level:
"chime": { "subtitle": "subtitles.examplemod.chime", "sounds": [ "examplemod:chime" ]}In src/main/resources/assets/examplemod/lang/en_us.json:
{ "subtitles.examplemod.chime": "Chime rings"}Forge 1.19.3 to 1.20.1, NeoForge 1.20.1
Section titled “Forge 1.19.3 to 1.20.1, NeoForge 1.20.1”Uses:
SoundEvent.createVariableRangeEventDeferredRegister.createForgeRegistries.SOUND_EVENTSLevel.playSound
src/main/java/com/example/examplemod/registry/ModSounds.java
package com.example.examplemod.registry;
import com.example.examplemod.ExampleMod;import net.minecraft.resources.ResourceLocation;import net.minecraft.sounds.SoundEvent;import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;import net.minecraftforge.registries.DeferredRegister;import net.minecraftforge.registries.ForgeRegistries;import net.minecraftforge.registries.RegistryObject;
// The mod's sounds; assets/examplemod/sounds.json says which files each plays.public final class ModSounds { public static final DeferredRegister<SoundEvent> SOUND_EVENTS = DeferredRegister.create(ForgeRegistries.SOUND_EVENTS, ExampleMod.MOD_ID);
public static final RegistryObject<SoundEvent> CHIME = SOUND_EVENTS.register("chime", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation(ExampleMod.MOD_ID, "chime")));
private ModSounds() { }
// Called from the ExampleMod constructor: puts the sounds on the mod event bus. public static void register() { SOUND_EVENTS.register(FMLJavaModLoadingContext.get().getModEventBus()); }}In your main mod class, inside <init>:
ModSounds.register();In src/main/resources/assets/examplemod/sounds.json, add this entry to the top level:
"chime": { "subtitle": "subtitles.examplemod.chime", "sounds": [ "examplemod:chime" ]}In src/main/resources/assets/examplemod/lang/en_us.json:
{ "subtitles.examplemod.chime": "Chime rings"}Fabric 1.21.1, Fabric 1.21.2 to 26.3
Section titled “Fabric 1.21.1, Fabric 1.21.2 to 26.3”Uses:
SoundEvent.createVariableRangeEventBuiltInRegistries.SOUND_EVENTLevel.playSound
Put the sound at assets/examplemod/sounds/chime.ogg (Ogg Vorbis); Linen doesn’t make audio.
src/main/java/com/example/examplemod/registry/ModSounds.java
package com.example.examplemod.registry;
import com.example.examplemod.ExampleMod;import net.minecraft.core.Registry;import net.minecraft.core.registries.BuiltInRegistries;import net.minecraft.sounds.SoundEvent;
// The mod's sounds; assets/examplemod/sounds.json says which files each plays.public final class ModSounds { public static final SoundEvent CHIME = Registry.register(BuiltInRegistries.SOUND_EVENT, ExampleMod.id("chime"), SoundEvent.createVariableRangeEvent(ExampleMod.id("chime")));
private ModSounds() { }
// Called from ExampleMod#onInitialize; loading this class registers the sounds above. public static void register() { }}In your main mod class, inside onInitialize:
ModSounds.register();In src/main/resources/assets/examplemod/sounds.json, add this entry to the top level:
"chime": { "subtitle": "subtitles.examplemod.chime", "sounds": [ "examplemod:chime" ]}In src/main/resources/assets/examplemod/lang/en_us.json:
{ "subtitles.examplemod.chime": "Chime rings"}NeoForge 1.21 to 1.21.1, NeoForge 1.21.2 to 1.21.10
Section titled “NeoForge 1.21 to 1.21.1, NeoForge 1.21.2 to 1.21.10”Uses:
SoundEvent.createVariableRangeEventDeferredRegister.createRegistries.SOUND_EVENTLevel.playSound
Put the sound at assets/examplemod/sounds/chime.ogg (Ogg Vorbis); Linen doesn’t make audio.
src/main/java/com/example/examplemod/registry/ModSounds.java
package com.example.examplemod.registry;
import com.example.examplemod.ExampleMod;import net.minecraft.core.registries.Registries;import net.minecraft.resources.ResourceLocation;import net.minecraft.sounds.SoundEvent;import net.neoforged.neoforge.registries.DeferredHolder;import net.neoforged.neoforge.registries.DeferredRegister;
// The mod's sounds; assets/examplemod/sounds.json says which files each plays.public final class ModSounds { // Registered on the mod event bus in ExampleMod's constructor. public static final DeferredRegister<SoundEvent> SOUND_EVENTS = DeferredRegister.create(Registries.SOUND_EVENT, ExampleMod.MOD_ID);
public static final DeferredHolder<SoundEvent, SoundEvent> CHIME = SOUND_EVENTS.register("chime", () -> SoundEvent.createVariableRangeEvent(ResourceLocation.fromNamespaceAndPath(ExampleMod.MOD_ID, "chime")));
private ModSounds() { }}In your main mod class, inside <init>:
ModSounds.SOUND_EVENTS.register(modEventBus);In src/main/resources/assets/examplemod/sounds.json, add this entry to the top level:
"chime": { "subtitle": "subtitles.examplemod.chime", "sounds": [ "examplemod:chime" ]}In src/main/resources/assets/examplemod/lang/en_us.json:
{ "subtitles.examplemod.chime": "Chime rings"}NeoForge 1.20.2 to 1.20.6
Section titled “NeoForge 1.20.2 to 1.20.6”Uses:
SoundEvent.createVariableRangeEventDeferredRegister.createRegistries.SOUND_EVENTLevel.playSound
Put the sound at assets/examplemod/sounds/chime.ogg (Ogg Vorbis); Linen doesn’t make audio.
src/main/java/com/example/examplemod/registry/ModSounds.java
package com.example.examplemod.registry;
import com.example.examplemod.ExampleMod;import net.minecraft.core.registries.Registries;import net.minecraft.resources.ResourceLocation;import net.minecraft.sounds.SoundEvent;import net.neoforged.neoforge.registries.DeferredHolder;import net.neoforged.neoforge.registries.DeferredRegister;
// The mod's sounds; assets/examplemod/sounds.json says which files each plays.public final class ModSounds { // Registered on the mod event bus in ExampleMod's constructor. public static final DeferredRegister<SoundEvent> SOUND_EVENTS = DeferredRegister.create(Registries.SOUND_EVENT, ExampleMod.MOD_ID);
public static final DeferredHolder<SoundEvent, SoundEvent> CHIME = SOUND_EVENTS.register("chime", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation(ExampleMod.MOD_ID, "chime")));
private ModSounds() { }}In your main mod class, inside <init>:
ModSounds.SOUND_EVENTS.register(modEventBus);In src/main/resources/assets/examplemod/sounds.json, add this entry to the top level:
"chime": { "subtitle": "subtitles.examplemod.chime", "sounds": [ "examplemod:chime" ]}In src/main/resources/assets/examplemod/lang/en_us.json:
{ "subtitles.examplemod.chime": "Chime rings"}NeoForge 1.21.11 to 26.3
Section titled “NeoForge 1.21.11 to 26.3”Uses:
SoundEvent.createVariableRangeEventDeferredRegister.createRegistries.SOUND_EVENTLevel.playSound
Put the sound at assets/examplemod/sounds/chime.ogg (Ogg Vorbis); Linen doesn’t make audio.
src/main/java/com/example/examplemod/registry/ModSounds.java
package com.example.examplemod.registry;
import com.example.examplemod.ExampleMod;import net.minecraft.core.registries.Registries;import net.minecraft.resources.Identifier;import net.minecraft.sounds.SoundEvent;import net.neoforged.neoforge.registries.DeferredHolder;import net.neoforged.neoforge.registries.DeferredRegister;
// The mod's sounds; assets/examplemod/sounds.json says which files each plays.public final class ModSounds { // Registered on the mod event bus in ExampleMod's constructor. public static final DeferredRegister<SoundEvent> SOUND_EVENTS = DeferredRegister.create(Registries.SOUND_EVENT, ExampleMod.MOD_ID);
public static final DeferredHolder<SoundEvent, SoundEvent> CHIME = SOUND_EVENTS.register("chime", () -> SoundEvent.createVariableRangeEvent(Identifier.fromNamespaceAndPath(ExampleMod.MOD_ID, "chime")));
private ModSounds() { }}In your main mod class, inside <init>:
ModSounds.SOUND_EVENTS.register(modEventBus);In src/main/resources/assets/examplemod/sounds.json, add this entry to the top level:
"chime": { "subtitle": "subtitles.examplemod.chime", "sounds": [ "examplemod:chime" ]}In src/main/resources/assets/examplemod/lang/en_us.json:
{ "subtitles.examplemod.chime": "Chime rings"}Fabric 1.16.5 to 1.19.2
Section titled “Fabric 1.16.5 to 1.19.2”Uses:
SoundEvent.createVariableRangeEventRegistry.SOUND_EVENTLevel.playSound
src/main/java/com/example/examplemod/registry/ModSounds.java
package com.example.examplemod.registry;
import com.example.examplemod.ExampleMod;import net.minecraft.core.Registry;import net.minecraft.sounds.SoundEvent;
// The mod's sounds; assets/examplemod/sounds.json says which files each plays.public final class ModSounds { public static final SoundEvent CHIME = Registry.register(Registry.SOUND_EVENT, ExampleMod.id("chime"), new SoundEvent(ExampleMod.id("chime")));
private ModSounds() { }
// Called from ExampleMod#onInitialize; loading this class registers the sounds above. public static void register() { }}In your main mod class, inside onInitialize:
ModSounds.register();In src/main/resources/assets/examplemod/sounds.json, add this entry to the top level:
"chime": { "subtitle": "subtitles.examplemod.chime", "sounds": [ "examplemod:chime" ]}In src/main/resources/assets/examplemod/lang/en_us.json:
{ "subtitles.examplemod.chime": "Chime rings"}Forge 1.16.5
Section titled “Forge 1.16.5”Uses:
SoundEvent.<init>DeferredRegister.createForgeRegistries.SOUND_EVENTSWorld.playSound
src/main/java/com/example/examplemod/registry/ModSounds.java
package com.example.examplemod.registry;
import com.example.examplemod.ExampleMod;import net.minecraft.util.ResourceLocation;import net.minecraft.util.SoundEvent;import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;import net.minecraftforge.registries.DeferredRegister;import net.minecraftforge.registries.ForgeRegistries;import net.minecraftforge.fml.RegistryObject;
// The mod's sounds; assets/examplemod/sounds.json says which files each plays.public final class ModSounds { public static final DeferredRegister<SoundEvent> SOUND_EVENTS = DeferredRegister.create(ForgeRegistries.SOUND_EVENTS, ExampleMod.MOD_ID);
public static final RegistryObject<SoundEvent> CHIME = SOUND_EVENTS.register("chime", () -> new SoundEvent(new ResourceLocation(ExampleMod.MOD_ID, "chime")));
private ModSounds() { }
// Called from the ExampleMod constructor: puts the sounds on the mod event bus. public static void register() { SOUND_EVENTS.register(FMLJavaModLoadingContext.get().getModEventBus()); }}In your main mod class, inside <init>:
ModSounds.register();In src/main/resources/assets/examplemod/sounds.json, add this entry to the top level:
"chime": { "subtitle": "subtitles.examplemod.chime", "sounds": [ "examplemod:chime" ]}In src/main/resources/assets/examplemod/lang/en_us.json:
{ "subtitles.examplemod.chime": "Chime rings"}Forge 1.12.2
Section titled “Forge 1.12.2”Uses:
SoundEvent.<init>RegistryEvent.Register<SoundEvent>World.playSound
src/main/java/com/example/examplemod/registry/ModSounds.java
package com.example.examplemod.registry;
import com.example.examplemod.ExampleMod;import net.minecraft.util.ResourceLocation;import net.minecraft.util.SoundEvent;import net.minecraftforge.event.RegistryEvent;import net.minecraftforge.fml.common.Mod;import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
// The mod's sounds; assets/examplemod/sounds.json says which files each plays.@Mod.EventBusSubscriber(modid = ExampleMod.MOD_ID)public final class ModSounds { public static SoundEvent CHIME;
private ModSounds() { }
// Forge fires RegistryEvent.Register<SoundEvent> once; the sound event's name is the key in sounds.json. @SubscribeEvent public static void registerSounds(RegistryEvent.Register<SoundEvent> event) { ResourceLocation id = new ResourceLocation(ExampleMod.MOD_ID, "chime"); CHIME = new SoundEvent(id).setRegistryName(id); event.getRegistry().register(CHIME); }}In src/main/resources/assets/examplemod/sounds.json, add this entry to the top level:
"chime": { "subtitle": "subtitles.examplemod.chime", "sounds": [ "examplemod:chime" ]}In src/main/resources/assets/examplemod/lang/en_us.json:
{ "subtitles.examplemod.chime": "Chime rings"}Sources
Section titled “Sources”- https://docs.fabricmc.net/1.21.1/develop/sounds/custom
- https://docs.neoforged.net/docs/1.21.1/resources/client/sounds
Related how-tos
Section titled “Related how-tos”- A new block
- A new item
- A creative tab of your own
- A recipe type of your own
- Add drops to Minecraft’s loot
In Linen
Section titled “In Linen”Linen’s How-tos library has this page too, with the example for your own mod’s loader and Minecraft version. Hover a name in your code and Linen points to the how-tos that explain it. Both are free. Download Linen.