I am trying to add a custom sound to my mod. Each time I launch my mod Minecraft crashes (goes to a black screen for a second and then sends me back to Eclipse). Eclipse is not creating an error log when this happens so I can't see what the problem is. I have included my code below. Could someone take a look at my code and tell me what I am doing wrong?
1) I added this line of code to the perInit section of my Main:
3) I downloaded my ogg file and placed it under assets.mymod.sounds.testsounds and called it 'Star Wars Theme Song.ogg'.
I am not sure what other information I can provide to help determine the problem so please let me know if there is something else I can add. I appreciate any help.
Can you upload the FML log (ForgeModLoader-client-0.log) and the crash report (if there is one) to Gist and link them here? There's probably some indication of the error in one of these files.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Your sound files probably should not have spaces in the file name, and should probably be lower case, e.g. 'star_wars_theme_song.ogg' would be a good filename.
Also, you need to include '.ogg' in the file name when adding the sound during SoundLoadEvent, and SoundLoadEvent should only be handled on the client - in other words, register the event handler in your ClientProxy, not in your Main mod class, otherwise you will crash the game on a server.
Show the code where you play the sound. Also, are you making a music disc, or just a sound file? Because the registration code to play it are different.
never mind I got it all sorted out and I can play my custom sounds now. It turns out the path i was referencing to the sounds was incorrect. thanks for all your help.
Hello,
I am trying to add a custom sound to my mod. Each time I launch my mod Minecraft crashes (goes to a black screen for a second and then sends me back to Eclipse). Eclipse is not creating an error log when this happens so I can't see what the problem is. I have included my code below. Could someone take a look at my code and tell me what I am doing wrong?
1) I added this line of code to the perInit section of my Main:
MinecraftForge.EVENT_BUS.register(new RegisterSounds());
2) I created a class called RegisterSounds:
package mymod.entity.mysounds;
import net.minecraftforge.client.event.sound.SoundLoadEvent;
import net.minecraftforge.event.ForgeSubscribe;
public class RegisterSounds {
@ForgeSubscribe
public void onSound(SoundLoadEvent event){
event.manager.addSound("mymod:testsound/Star Wars Theme Song");
}
}
3) I downloaded my ogg file and placed it under assets.mymod.sounds.testsounds and called it 'Star Wars Theme Song.ogg'.
I am not sure what other information I can provide to help determine the problem so please let me know if there is something else I can add. I appreciate any help.
Can you upload the FML log (ForgeModLoader-client-0.log) and the crash report (if there is one) to Gist and link them here? There's probably some indication of the error in one of these files.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Your sound files probably should not have spaces in the file name, and should probably be lower case, e.g. 'star_wars_theme_song.ogg' would be a good filename.
Also, you need to include '.ogg' in the file name when adding the sound during SoundLoadEvent, and SoundLoadEvent should only be handled on the client - in other words, register the event handler in your ClientProxy, not in your Main mod class, otherwise you will crash the game on a server.
I have done what you have told me. The game has stopped crashing, but now when I run the game and play the sound minecraft gets muted.
Show the code where you play the sound. Also, are you making a music disc, or just a sound file? Because the registration code to play it are different.
i am making a sound file and the code is below
package mymod.items;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.monster.EntityMob;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class MyForce extends Item {
private String texturePath = "mymod:";
public MyForce(int ItemID, String textureName)
{
super(ItemID);
this.setUnlocalizedName(textureName);
this.setCreativeTab(CreativeTabs.tabMaterials);
texturePath += textureName;
}
@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IconRegister iconRegister)
{
this.itemIcon = iconRegister.registerIcon(texturePath);
}
/** This entire area is responsible for the Magnetic effect*/
public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer)
{
//This number sets the size of pull area of the magnet.
double radius = 10;
java.util.List<EntityMob> items = world.getEntitiesWithinAABB(
EntityMob.class,
entityplayer.boundingBox.expand(radius, radius, radius));
for (EntityMob entitymob : items) {
double distX = entityplayer.posX + entitymob.posX;
double distZ = entityplayer.posZ + entitymob.posZ;
double distY = entitymob.posY - 5.5D - entityplayer.posY;
double dir = Math.atan2(distZ, distX);
//This number sets the speed it comes to you.
double speed = 6F / entitymob.getDistanceToEntity(entityplayer) * 0.5;
if (distY < 0) {
entitymob.motionY += speed;
}
entitymob.motionX = Math.cos(dir) * speed;
entitymob.motionZ = Math.sin(dir) * speed;
}
world.playSoundAtEntity(entityplayer, "mymod:testsounds.star_wars_theme_song.ogg", 0.3F, 0.1F);
return itemstack;
}
}
never mind I got it all sorted out and I can play my custom sounds now. It turns out the path i was referencing to the sounds was incorrect. thanks for all your help.