Custom Sounds and More in Minecraft

A lot of mods are now trying to add custom sounds and are having problems. Others will use AudioMod which is a good choice but not needed. Adding sounds is really easy and doesn’t require any mods or API’s. This tutorial isn’t made for a specific version of Minecraft and this method has been consistent among updates. This is a generic tutorial so it will work on ModLoader, Forge or no API at all.

As of 1.4.2, minecraft change the sound type “newsound” and “sound” to the name “sound3″.

Common Terms
File - java.io.File class
Sound Name - Refers to the name of sound, e.g., “mob.cow”. See Installing Scheme for more info.
SoundSystem - Paul’s 3D Sound System
SoundManager - Minecraft’s SoundManager.class that handles all sound.
SoundPool - Maps sound names and their corresponding files together in a HashMap. SoundPool.class holds this information and has methods like get random sound.

Sound Types
In Minecraft there are three types of sounds.

  • Sound - This is the main type of sound that is used for Mobs, hitting blocks, exp pickups, and many more. You will use this type more often than the rest.
  • Streaming - Streams the sound; meaning plays as it arrives. As of right now this type is only used for Music Disks.
  • Music - Same as Sound but for Background music instead. Note that Minecraft will randomly choose the music entry in a SoundPool.

Install Scheme
Minecraft has their own install method for all sounds. No this isn’t a special path on the hard drive; it’s the method that puts the sounds in a specific SoundPool.

net.minecraft.client.Minecraft.installResource(String soundName, File fileLocation) : void

This method takes two parameters; SoundName and File Location.
SoundName 

This defines the type of sound and the name. It has three parts.

“[type][name][file-extension]“

There are three different types as mentioned above. ”sound3″, ”music” or ”newmusic”, and ”streaming”.

After the type you can specify the name as anything. Like ”mob/cow” or”locknload/mod/tutorial/extremecow”. Note if you put a number at the end, Minecraft will remove it e.g., ”mob/cow1″, “mob/cow2″. Only if the SoundPool’s boolean getrandomsound is set. Read up on random sounds in the section Playing Sounds.

 

Lastly comes the file extension. Simple just put an extension like ”.ogg” The following codecs are allowed. ogg, mus, and wav files. To add more read the section about Audio Mod below.

Put it all together,

“sound3/mob/cow.ogg” or

“sound3/locknload/mod/tutorial/extremecow.ogg”

File Location

The file location is a path on the hard drive to the sound. This argument accepts Java’s File object.

new File(mc.mcDataDir, "resources/mod/tutorial/extremecow.ogg")

mc is the Minecraft instance which you will need to get. Make sure this is the correct path and import the File class as well.

import java.io.File;

Here is the method being used,

mc.installResource("sound3/locknload/mod/tutorial/extremecow.ogg", new File(
mc.mcDataDir, "resources/mod/tutorial/extremecow.ogg"));

Playing Sounds
To use or play the sound you need the name of it.
locknload/mod/tutorial/extremecow
Replace all the forward slashes (/) with dots (.) It will come out to this,
locknload.mod.tutorial.extremecow
Then you can use that modified name in methods that require it.

net.minecraft.src.World.playSound(double posX, double posY, double posZ, String soundName, float volume, float pitch) : void
net.minecraft.src.World.playSoundAtEntity(Entity entity, String soundName, float volume, float pitch) : void
net.minecraft.src.SoundManager.playSoundFX(String soundName, float volume, float pitch) : void
@Override
protected String getLivingSound() {
return "locknload.mod.tutorial.extremecow";
}

If you added custom music it will be played randomly with all the other music.

Random Sounds

When playing a sound, SoundManger has to find it inside the SoundPool. It will then return a List that contains all sounds with that name and use a random number to select it. That means there can be multiple sounds with the same name. So if you only have the one sound in the list it will only return that sound. Take a look at the cow’s sound.

cow1.ogg
cow2.ogg
cow3.ogg
cow4.ogg

When you have numbers at the end of the resource name, it will take them off and put them in the List. When Minecraft plays the sound it will randomly choose one from the List. There are 4 outcomes in this example. Note that the sound’s name is “mob.cow”, not “mob.cow2″ or “mob.cow3″ and so on.

Records
Records are fairly easy. First you need to use the Streaming sound type.
“streaming/[name][file-extension]“
Make sure to replace the slashes with dots too.
Then creating the record is like any other Item but the second parameter is the sound name.

new ItemRecord(id, "[name]")

What is Audio Mod
What is Audio Mod and should you use it? It recursively installs sounds in a special folder that is specified. It also allows IBXM codec files; xm, s3m, and mod files. So Audio Mod isn’t really needed for adding sounds as I explained in this tutorial, but it is possible to use the IBXM codecs as well. Go to Paul’s Sound System website and download the plugin called IBXM http://www.paulscode…x.php?topic=4.0 Unzip it and you will see a jar file called CodecIBXM.jar. Just copy the files in minecraft.jar like any other mod, make sure to delete the META-INF that comes with it too. If you are in eclipse you might want to add the jar to the project’s Referenced Libraries. After that you need to register the codec with in Minecraft.

import paulscode.sound.SoundSystemConfig;
import paulscode.sound.codecs.CodecIBXM;

Then when you start up your mod put this

SoundSystemConfig.setCodec("xm", CodecIBXM.class);
SoundSystemConfig.setCodec("s3m", CodecIBXM.class);
SoundSystemConfig.setCodec("mod", CodecIBXM.class);

That’s all you have to do.

View more

Was this discussion helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this discussion?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this discussion?

Thanks for your feedback.

 

Discussion Info


Last updated December 17, 2023 Views 245 Applies to: