Jump to content

Problems while adding Sounds


WeAthFolD

Recommended Posts

I read the tuotrial in the forge wiki(though it's outdated and only compatitable with 1.3.2) and try exactly as it said

first I created a class called SoundEvents

public class CBCSoundEvents {

@ForgeSubscribe
public void onSound(SoundLoadEvent event)
{

	System.out.println("but a simple try");
	File file=new File("/mod/sounds/pin.wav");
	if(file==null){
			System.err.println("Fail to load the damn file.>)");
			return;
	} 
	System.out.println(file.getPath());
	try{
		SoundPoolEntry snd = event.manager.soundPoolSounds.addSound("abc", file);
		System.out.println(snd.soundName);
	}catch(Exception e){

		System.out.println("Sound registering failed.");

	}
}
}

 

at @PreInit method of my mod I added this:

MinecraftForge.EVENT_BUS.register(new CBCSoundEvents());

 

and at my Item's onItemRightClick method I added this:

par2World.playSoundAtEntity(par3EntityPlayer, "abc", 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));

 

Clearly it doesn't work.

The debug console shows "but a simple try" ,which indicates the function has been registered successfully,

also File loading and path printing works fine

but when it try to add sound there's an error.

2013-02-20 19:15:42 [iNFO] [sTDERR] java.lang.StringIndexOutOfBoundsException: String index out of range: -1
2013-02-20 19:15:42 [iNFO] [sTDERR] 	at java.lang.String.substring(String.java:1911)
2013-02-20 19:15:42 [iNFO] [sTDERR] 	at net.minecraft.client.audio.SoundPool.addSound(SoundPool.java:63)
2013-02-20 19:15:42 [iNFO] [sTDERR] 	at net.minecraft.client.audio.SoundPool.addSound(SoundPool.java:42)
2013-02-20 19:15:42 [iNFO] [sTDERR] 	at cbproject.misc.CBCSoundEvents.onSound(CBCSoundEvents.java:29)
2013-02-20 19:15:42 [iNFO] [sTDERR] 	at net.minecraftforge.event.ASMEventHandler_4_CBCSoundEvents_onSound_SoundLoadEvent.invoke(.dynamic)
2013-02-20 19:15:42 [iNFO] [sTDERR] 	at net.minecraftforge.event.ASMEventHandler.invoke(ASMEventHandler.java:35)
2013-02-20 19:15:42 [iNFO] [sTDERR] 	at net.minecraftforge.event.EventBus.post(EventBus.java:103)
2013-02-20 19:15:42 [iNFO] [sTDERR] 	at net.minecraft.client.audio.SoundManager.loadSoundSettings(SoundManager.java:80)
2013-02-20 19:15:42 [iNFO] [sTDERR] 	at net.minecraft.client.Minecraft.startGame(Minecraft.java:442)
2013-02-20 19:15:42 [iNFO] [sTDERR] 	at net.minecraft.client.MinecraftAppletImpl.startGame(MinecraftAppletImpl.java:44)
2013-02-20 19:15:42 [iNFO] [sTDERR] 	at net.minecraft.client.Minecraft.run(Minecraft.java:744)
2013-02-20 19:15:42 [iNFO] [sTDERR] 	at java.lang.Thread.run(Thread.java:722)
2013-02-20 19:15:42 [iNFO] [sTDOUT] Sound registering failed.

It says "String out of index" so I think the problem is exactly at here.

Am I using the wrong methods or doing anything wrong with the EventBus?

Using event.manager.addSound("abc",ModClass.class.getResource("path")) also won't work

Help me plz , I really don't know what to do now :'(

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.