Adding custom sounds involves three steps: registering a SoundEvent in the common module, providing the OGG audio file, and generating the sounds.json descriptor that maps the event to the file. The same event reference then works identically on Fabric and NeoForge.
RegistrationProvider for sound events.Sound Registry
Create a SoundRegistry class in your common registry package:
createVariableRangeEvent creates a sound whose audible range scales with the volume you pass when playing it, which is appropriate for most ambient and effect sounds. Use createFixedRangeEvent(location, range) instead for UI sounds that always need to be heard at a consistent distance regardless of volume.
Call SoundRegistry.init() from CommonClass.init():
Audio File
Minecraft requires audio in OGG Vorbis format, mono or stereo, at any standard sample rate. Place your file at:
You can convert audio to OGG using free tools such as Audacity (export as OGG Vorbis) or FFmpeg (ffmpeg -i input.mp3 output.ogg).
Datagen: Sound Definitions
Instead of writing sounds.json by hand, use a SoundDefinitionsProvider in your NeoForge datagen setup. Create ExampleSoundDefinitionsProvider in your NeoForge data package:
Register the provider in gatherData:
After running datagen, sounds.json is written to common/src/generated/resources/assets/examplemod/ and looks like this:
Add the subtitle translation key to en_us.json:
Playing Sounds
Sounds are played through the Level object. There are two variants to be aware of:
The four numeric arguments are: volume (1.0 is full, higher values increase range), pitch (1.0 is normal, 0.5 is an octave lower, 2.0 is an octave higher), and the position is the sound origin.
SoundSource category controls which volume slider in the audio settings affects this sound. Use BLOCKS for block interaction sounds, MOBS for entity sounds, and AMBIENT for environmental audio.Testing In-Game
Run datagen, then launch the client. Trigger the sound from a command block or a temporary event handler and confirm it plays. Check the subtitle overlay (enable it in Accessibility Settings) to verify that the subtitle text appears correctly.
If no sound plays, verify the OGG file exists at the correct path in your resources, that the name in sounds.json matches the file name exactly (without the .ogg extension), and that the sound event's registry name matches the key in sounds.json.
You can find the source for this tutorial here:
View Source on GitHubEvents and Listeners (MultiLoader 1.21+)
Keep game logic in common static handler methods and call them from loader-specific glue classes, using NeoForge @SubscribeEvent and Fabric API callbacks for player login and block break events.
Continue →