Posted July 14, 201213 yr EDIT: Wow, sorry about that. This should probably be in Support & Bug Reports.. I have absolutely no idea what I'm doing. I've been trying to get my mob to play sound files for several hours now, and it's getting pretty annoying. I got it to work with ModLoader fine. I could always just do the same thing I did to get it to work for ModLoader, but I wanted to learn how to do it with Forge too. This is the tutorial I'm trying to follow: http://minecraftforge.net/wiki/Adding_Custom_Sounds_to_Minecraft! And here's my code (I'm sure there's a lot of stuff wrong with it): mod_Scoaleton package net.minecraft.src; import java.util.Map; import net.minecraft.src.forge.*; import java.io.File; import cpw.mods.fml.common.FMLCommonHandler; import net.minecraft.client.Minecraft; import java.util.*; import net.minecraft.src.SoundManager; import net.minecraft.src.forge.MinecraftForgeClient; import net.minecraft.src.forge.*; public class mod_Scoaleton extends BaseMod{ public mod_Scoaleton() { } static Configuration configuration = new Configuration(new File(Minecraft.getMinecraftDir(), "/config/Scoaleton.cfg")); public static int DoesScoaletonExplodeAtDay; public static int DoesScoaletonAttackVillagers; static int ScoaletonProperties = configurationProperties(); public static int ScoaletonHealth; public static int ScoaletonStrength; public static int ScoaletonEXP; public static int ScoaletonSpawnRate; public static int ScoaletonMinimumGroupSize; public static int ScoaletonMaximumGroupSize; public void load() { ModLoader.addSpawn(EntityScoaleton.class, ScoaletonSpawnRate, ScoaletonMinimumGroupSize, ScoaletonMaximumGroupSize, EnumCreatureType.monster); ModLoader.registerEntityID(EntityScoaleton.class, "Scoaleton", 85, 1447446, 3158064); } public static int configurationProperties() { configuration.load(); DoesScoaletonAttackVillagers = Integer.parseInt(configuration.getOrCreateIntProperty("DoesScoaletonAttackVillagers", Configuration.CATEGORY_GENERAL, 0).value); DoesScoaletonExplodeAtDay = Integer.parseInt(configuration.getOrCreateIntProperty("DoesScoaletonExplodeAtDay", Configuration.CATEGORY_GENERAL, 0).value); ScoaletonHealth = Integer.parseInt(configuration.getOrCreateIntProperty("ScoaletonHealth", Configuration.CATEGORY_GENERAL, 70).value); ScoaletonStrength = Integer.parseInt(configuration.getOrCreateIntProperty("ScoaletonStrength", Configuration.CATEGORY_GENERAL, .value); ScoaletonEXP = Integer.parseInt(configuration.getOrCreateIntProperty("ScoaletonEXP", Configuration.CATEGORY_GENERAL, 30).value); ScoaletonSpawnRate = Integer.parseInt(configuration.getOrCreateIntProperty("ScoaletonSpawnRate", Configuration.CATEGORY_GENERAL, 1).value); ScoaletonMinimumGroupSize = Integer.parseInt(configuration.getOrCreateIntProperty("ScoaletonMinimumGroupSize", Configuration.CATEGORY_GENERAL, 1).value); ScoaletonMaximumGroupSize = Integer.parseInt(configuration.getOrCreateIntProperty("ScoaletonMaximumGroupSize", Configuration.CATEGORY_GENERAL, 1).value); configuration.save(); return ScoaletonProperties; } public void addRenderer(Map map) { FMLCommonHandler.instance().addStringLocalization("entity.Scoaleton.name", "en_US", "Scoaleton"); map.put(EntityScoaleton.class, new RenderBiped(new ModelBiped(), 0.5F)); map.put(net.minecraft.src.EntityScoaleton.class, new RenderScoaleton(new ModelScoaleton(), 0.4F)); } public String getVersion() { return "1.2.5"; } } SoundHandler package net.minecraft.src; import java.io.File; import java.lang.reflect.Method; import java.net.URL; import java.net.URLClassLoader; import net.minecraft.src.ModLoader; import net.minecraft.src.SoundManager; import net.minecraft.src.SoundPoolEntry; import net.minecraft.src.mod_Scoaleton; import net.minecraft.src.forge.*; public abstract class SoundHandler implements ISoundHandler { @Override public void onSetupAudio(SoundManager soundManager) { } @Override // Initialises our entries into the Sound Pool public void onLoadSoundSettings(SoundManager soundManager) { String [] soundFiles = { "metalhurt.ogg", "metalliving.ogg", "metaldeath.ogg"}; for (int i = 0; i < soundFiles.length; i++){ soundManager.getSoundsPool().addSound(soundFiles, this.getClass().getResource("/ocomosounds/sound/" + soundFiles)); } } @Override public SoundPoolEntry onPlayBackgroundMusic(SoundManager soundManager, SoundPoolEntry entry) { return entry; } @Override public SoundPoolEntry onPlayStreaming(SoundManager soundManager, SoundPoolEntry entry, String soundName, float x, float y, float z) { return entry; } @Override public SoundPoolEntry onPlaySound(SoundManager soundManager, SoundPoolEntry entry, String soundName, float x, float y, float z, float volume, float pitch) { return entry; } @Override public SoundPoolEntry onPlaySoundEffect(SoundManager soundManager, SoundPoolEntry entry, String soundName, float volume, float pitch) { return entry; } }
July 14, 201213 yr Try naming your sound files with a XXX/ before it. So for example in the tutorial "horse.whinny" is acceptable but when you added your sound files you don't have a prefix before the sound file. That might be the problem. Also, I wrote that tutorial, so I guess it wasn't a good enough tutorial to get people to understand it... http://calclavia.com/uploads/banner.png[/img]
July 14, 201213 yr Author I tried that and it didn't work, here's my code now: public void onLoadSoundSettings(SoundManager soundManager) { String [] soundFiles = { "test/metalhurt.ogg", "test/metalliving.ogg", "test/metaldeath.ogg"}; for (int i = 0; i < soundFiles.length; i++){ soundManager.getSoundsPool().addSound(soundFiles[i], this.getClass().getResource("/ocomosounds/sound" + soundFiles[i])); } } Also, I put the files in 'resources\mod\ocomosounds\test'. Here are the sounds in my Entity file: public String getHurtSound() { return "test.metalhurt"; } public String getLivingSound() { return "test.metalliving"; } public String getDeathSound() { return "test.metaldeath"; } And also, I'm not using the MinecraftForgeClient.registerSoundHandler(mod_Scoaleton, ISoundManager); function (which is most likely the problem), because I kept this error on that line: Multiple markers at this line - Syntax error on token ")", delete this token - Syntax error on token "(", delete this token Your tutorial is fine, I'm just stupid I wasn't really sure where to put that function, so I just put it after public abstract class SoundHandler implements ISoundHandler {
July 15, 201213 yr Actually Calclavia, your sound system tut is working for me either. You've got the register call wrong and even when I fixed that, it still doesn't work.
July 15, 201213 yr I dont understand the MinecraftForgeClient.registerSoundHandler(new SoundHandlerClass()); thing, I try this but it doesnt work: MinecraftForgeClient.registerSoundHandler(new ThorMod_SoundHandler()); Eclipse gives me the error: Cannot instantiate the type ThorMod_SoundHandler ThorMod_SoundHandler: package net.minecraft.src; import java.io.File; import java.lang.reflect.Method; import java.net.URL; import java.net.URLClassLoader; import net.minecraft.src.ModLoader; import net.minecraft.src.SoundManager; import net.minecraft.src.SoundPoolEntry; import net.minecraft.src.mod_TheThorMod; import net.minecraft.src.forge.*; public abstract class ThorMod_SoundHandler implements ISoundHandler { @Override public void onSetupAudio(SoundManager soundManager) { } @Override public void onLoadSoundSettings(SoundManager soundManager) { String [] soundFiles = { "monkey/cry1.ogg", "monkey/cry2.ogg", "monkey/cry3.ogg",}; for (int i = 0; i < soundFiles.length; i++){ soundManager.getSoundsPool().addSound(soundFiles[i], this.getClass().getResource("/Thormod/Audio/" + soundFiles[i])); } } @Override public SoundPoolEntry onPlayBackgroundMusic(SoundManager soundManager, SoundPoolEntry entry) { return entry; } @Override public SoundPoolEntry onPlayStreaming(SoundManager soundManager, SoundPoolEntry entry, String soundName, float x, float y, float z) { return entry; } @Override public SoundPoolEntry onPlaySound(SoundManager soundManager, SoundPoolEntry entry, String soundName, float x, float y, float z, float volume, float pitch) { return entry; } @Override public SoundPoolEntry onPlaySoundEffect(SoundManager soundManager, SoundPoolEntry entry, String soundName, float volume, float pitch) { return entry; } } Pls help I need this http://i.imgur.com/Hppni.png[/img]
July 16, 201213 yr I folllowed that tutorial and it worked for me. *NOTE* if you don't use a prefix for your sound files it assumes you have your sound in a "Sounds/" folder in the jar file. Thats built in to the codec thingy.
July 16, 201213 yr I folllowed that tutorial and it worked for me. *NOTE* if you don't use a prefix for your sound files it assumes you have your sound in a "Sounds/" folder in the jar file. Thats built in to the codec thingy. Would be nice if you could send us what you did so we know what we've done wrong, thank you very much http://i.imgur.com/Hppni.png[/img]
July 16, 201213 yr Author What did you do with the MinecraftForgeClient.registerSoundHandler thing? EDIT: Didn't see that someone else posted, sorry.
July 16, 201213 yr What did you do with the MinecraftForgeClient.registerSoundHandler thing? EDIT: Didn't see that someone else posted, sorry. Who posted? I still dont see any answers to this problem. Nothing works with the registerSoundHandler thing no matter what I put in there it always says cannot instantiate <The Thing You Put In The Brackets>. Also, what do I put in the getLivingSound thing on mobs when I want to use the sound? http://i.imgur.com/Hppni.png[/img]
July 16, 201213 yr Author I was basically just saying that you said the same thing before me, not that someone already told me how.
July 17, 201213 yr So you guys can't get it to work following the tutorial? I had some trouble initially too, I think my code is basically the same as the tutorial except I didn't put a prefix on my sound files, this means I have to put my sound files in a Sounds/ folder as it assumes this for some reason. Make a class that extends SoundHandlerAdaptor. Most important method in there is onLoadSoundSettings, in general My onLoadSoundSettings : @Override public void onLoadSoundSettings(SoundManager soundManager) { String[] soundFiles = { "aSound.wav", "abeep.wav", "aSuperBeep.wav" }; for (int i = 0; i < soundFiles.length; i++){ soundManager.getSoundsPool().addSound(soundFiles[i], this.getClass().getClassLoader().getResource("/" + soundFiles[i])); } } In your mod_**** class, I simply created an instance of this soundHandler class, and then loaded it with MinecraftForge. //With my declarations public static awesomeSoundHandler soundHandler = new awesomeSoundHandler(); // Loading with MinecraftForge public void load() { MinecraftForgeClient.registerSoundHandler(soundHandler); } Then when testing in MCP, I put my custom sounds in the minecraft.jar Sounds/aSounds.wav for example. And playing a sound: world.playSoundEffect(xPos,yPos,zPos, "aSound", world.rand.nextFloat()*0.2f + 0.8f, world.rand.nextFloat() * 0.2F + 0.8F); Those parameters are reasonably self-explanatory bar the last 2. Note the lack of ".wav" in my sound name string. The last two paramaters are volume and pitch respectively. If you wish, a simple 1f will suffice. I think thats everything you need to do...?
July 17, 201213 yr So you guys can't get it to work following the tutorial? I had some trouble initially too, I think my code is basically the same as the tutorial except I didn't put a prefix on my sound files, this means I have to put my sound files in a Sounds/ folder as it assumes this for some reason. Make a class that extends SoundHandlerAdaptor. Most important method in there is onLoadSoundSettings, in general My onLoadSoundSettings : @Override public void onLoadSoundSettings(SoundManager soundManager) { String[] soundFiles = { "aSound.wav", "abeep.wav", "aSuperBeep.wav" }; for (int i = 0; i < soundFiles.length; i++){ soundManager.getSoundsPool().addSound(soundFiles[i], this.getClass().getClassLoader().getResource("/" + soundFiles[i])); } } In your mod_**** class, I simply created an instance of this soundHandler class, and then loaded it with MinecraftForge. //With my declarations public static awesomeSoundHandler soundHandler = new awesomeSoundHandler(); // Loading with MinecraftForge public void load() { MinecraftForgeClient.registerSoundHandler(soundHandler); } Then when testing in MCP, I put my custom sounds in the minecraft.jar Sounds/aSounds.wav for example. And playing a sound: world.playSoundEffect(xPos,yPos,zPos, "aSound", world.rand.nextFloat()*0.2f + 0.8f, world.rand.nextFloat() * 0.2F + 0.8F); Those parameters are reasonably self-explanatory bar the last 2. Note the lack of ".wav" in my sound name string. The last two paramaters are volume and pitch respectively. If you wish, a simple 1f will suffice. I think thats everything you need to do...? I found the problem and everything is working smoothly now, what I did wrong: 1. My class was implementing ISoundHandler 2. I didnt have onPlaySoundAtEntity() in my class 3. I was using .ogg files not wav files Thank you! http://i.imgur.com/Hppni.png[/img]
July 18, 201213 yr I found the problem and everything is working smoothly now, what I did wrong: 1. My class was implementing ISoundHandler 2. I didnt have onPlaySoundAtEntity() in my class 3. I was using .ogg files not wav files Thank you! The fact that you were implementing ISoundHandler wasn't necessarily a problem - by extending the SoundHandlerAdaptor (or whatever it was called) you are extending a class which has implemented ISoundHandler. Its just a nice simple way to do it as the SoundHandlerAdaptor has default implementations you can override. Anyway, as long as you got it working its all good
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.