Jump to content

[1.4.2]Problem With Sounds[Solved]


LearnToSpel

Recommended Posts

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!

Link to comment
Share on other sites

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);
                        
                        
}

Link to comment
Share on other sites

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));
                        
	} 

Link to comment
Share on other sites

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;
}

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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