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

Hello everyone. I am new to modding with Forge (used to use ModLoader), and I have encountered a problem when trying to play my sounds for my mod. I follow the tutorial, and this is the code that I put(I only included the parts that play the sound):

 

ModMagicItems_EventSounds:

 


package magicItems.common;

import net.minecraftforge.client.event.sound.SoundLoadEvent;
import net.minecraftforge.event.ForgeSubscribe;

public class MagicItems_EventSounds
{

@ForgeSubscribe
    public void onSound(SoundLoadEvent event)
    {
        try 
        {
            event.manager.soundPoolSounds.addSound("/folder/mirrorsound.wav", ModMagicItems.class.getResource("/spelssounds/sounds/folder/mirrorsound.wav"));            
        
        } 
        catch (Exception e)
        {
            System.err.println("Failed to register one or more sounds.");
        }
    }

}

 

 

My BaseMod File:

 


@Init
    public void load(FMLInitializationEvent initEvent){

        
        //Sounds
        
        MinecraftForge.EVENT_BUS.register(new MagicItems_EventSounds());
}

 

ItemMirror:

 


public ItemStack onItemRightClick(ItemStack item, World world, EntityPlayer player) 
{


		world.playSoundAtEntity(player, "spelssounds.mirror", 1.0F, 1.0F);
                        
                        
}

 

I'm pretty sure that I named the folders correctly and everything. I even tried exporting the mod, and putting it in my real minecraft.jar and playing it, but the sound just simply would not play. Does anybody know what I am doing wrong? Thanks!

Change your code to:

 

ModMagicItems_EventSounds:

 


package magicItems.common;

import net.minecraftforge.client.event.sound.SoundLoadEvent;
import net.minecraftforge.event.ForgeSubscribe;

public class MagicItems_EventSounds
{

@ForgeSubscribe
    public void onSound(SoundLoadEvent event)
    {
        try 
        {
            event.manager.soundPoolSounds.addSound("/magicItems/mirrorsound.wav", "magicItems/spelssounds/sounds/folder/mirrorsound.wav");            
        // So you should have mirrorsound.wav in your "src/common/magicItems/spelssounds/sounds/folder" folder and after compiling you should put it into "magicItems.zip/common/spelssounds/sounds/folder"
        } 
        catch (Exception e)
        {
            System.err.println("Failed to register one or more sounds.");
        }
    }

}

 

 

BaseMod File:

 


@PreInit
    public void load(FMLInitializationEvent initEvent){

        
        //Sounds
        
        MinecraftForge.EVENT_BUS.register(new MagicItems_EventSounds());
}

 

ItemMirror:

 


public ItemStack onItemRightClick(ItemStack item, World world, EntityPlayer player) 
{


		world.playSoundAtEntity(player, "magicItems.mirrorsound", 1.0F, 1.0F);
                        
                        
}

  • Author

I tried what you told me and it still didn't work, even when I exported it. I put the folders in everywhere you told me to put it, but it wasn't working :(

 

MagicItems_EventSounds:

 


@ForgeSubscribe
    public void onSound(SoundLoadEvent event)
    {
        try 
        {
            event.manager.soundPoolSounds.addSound("/magicItems/mirrorsound.ogg", ModMagicItems.class.getResource("magicItems/spelssounds/sounds/folder/mirrorsound.ogg"));            
        
        } 
        catch (Exception e)
        {
            System.err.println("Failed to register one or more sounds.");
        }

 

ModBase:

 


@PreInit
    public void load(FMLInitializationEvent initEvent)
{

	//Declare names


        
        //Recipes
        
        
        //Sounds
        
        MinecraftForge.EVENT_BUS.register(new MagicItems_EventSounds());
}

 

ItemMirror:

 


public ItemStack onItemRightClick(ItemStack item, World world, EntityPlayer player) 
{

	if (world.isRemote) 
	{
		return item;
	}


		player.addChatMessage("Commencing teleportation to bed.");
		world.playSoundAtEntity(player, "magicItems.mirrorsound", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 0.8F));
                        
	} 

  • Author

I changed the file extension of the sound to .ogg if that matters. It still doesn't work, any help?

  • Author

Ok, so I modified them a bit, and this is my new code:

 

MagicItems_EventSounds:

 


package magicItems.common;

import net.minecraftforge.client.event.sound.SoundLoadEvent;
import net.minecraftforge.event.ForgeSubscribe;

public class MagicItems_EventSounds
{

@ForgeSubscribe
    public void onSound(SoundLoadEvent event)
    {
        try 
        {
        	event.manager.soundPoolSounds.addSound("/folder/mirrorsound.ogg", ModMagicItems.class.getResource("/spelssounds/sounds/folder/mirrorsound.ogg"));
        
        } 
        catch (Exception e)
        {
            System.err.println("Failed to register one or more sounds.@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
        }
    }

}

 

ModBase:

 


@PreInit
public void preInit(FMLPreInitializationEvent event) 
{

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

}

 

 

ItemMirror:

 


public ItemStack onItemRightClick(ItemStack item, World world, EntityPlayer player) 
{
	world.playSoundAtEntity(player, "folder.mirrorsound", 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
	System.out.println("SOUND PLAYED@@@@@@@@@");
	return item;
}

event.manager.soundPoolSounds.addSound("/folder/mirrorsound.ogg", ModMagicItems.class.getResource("/spelssounds/sounds/folder/mirrorsound.ogg"));

The first path is wrong. You shouldn't have a slash at the beginning. It should be like:

"folder/mirrorsound.ogg"

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

  • Author

event.manager.soundPoolSounds.addSound("/folder/mirrorsound.ogg", ModMagicItems.class.getResource("/spelssounds/sounds/folder/mirrorsound.ogg"));

The first path is wrong. You shouldn't have a slash at the beginning. It should be like:

"folder/mirrorsound.ogg"

 

I tried that and got an error in the console:

 

2012-10-31 15:05:43 [iNFO] [sTDOUT] SOUND PLAYED@@@@@@@@@
2012-10-31 15:05:43 [iNFO] [sTDOUT] SOUND PLAYED@@@@@@@@@
2012-10-31 15:05:43 [iNFO] [sTDOUT] Error in class 'LibraryLWJGLOpenAL'
2012-10-31 15:05:43 [iNFO] [sTDOUT]     Unable to open file 'folder/mirrorsound.wav' in method 'loadSound'
2012-10-31 15:05:43 [iNFO] [sTDOUT] Error in class 'LibraryLWJGLOpenAL'
2012-10-31 15:05:43 [iNFO] [sTDOUT]     Source 'sound_3' was not created because an error occurred while loading folder/mirrorsound.wav

 

The path to my sound is MCP>src>common>magicItems>spelssounds>sound>folder>mirrorsound.wav

 

Guest
This topic is now closed to further replies.

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.