Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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 :'(

  • Author

BTW:If I delete the [soundPoolEntry snd = ] the console won't show any error,but the sound still isn't loaded xDD

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.