I have followed ever tutorial I can and still can not get this to work.
I have a mob that is mostly just a copy/paste of Skeleton code, just using a custom projectile. I am attempting to replace the sound that plays when it uses a ranged attack, but it won't play no matter what I try.
This is my code to add the sounds.
package mymod
;
import java.io.PrintStream;
import net.minecraft.client.audio.SoundManager;
import net.minecraft.client.audio.SoundPool;
import net.minecraftforge.client.event.sound.SoundLoadEvent;
import net.minecraftforge.event.ForgeSubscribe;
public class GriffinIEventSounds {
@ForgeSubscribe
public void onSound(SoundLoadEvent event)
{
try
{
// Put 'addStreaming' instead of 'addSound' for a record! (Got this tip from another forum entry.)
event.manager.addSound("griffinimod:shot.ogg");
}
catch (Exception e)
{
System.err.println("There was a problem loading the sound. Please report on the forums.");
}
}
}
This is my code in the main method to register it.
public static void registerSound() {
MinecraftForge.EVENT_BUS.register(new GriffinIEventSounds());
}
And this is the part of my code where the mob shoots and plays the sound. The commented sections are everything I've tried that runs without crashing the game. playSound crashes just the sound engine, and the other two result in no sound.
public void attackEntityWithRangedAttack(EntityLivingBase par1EntityLivingBase, float par2)
{
GriffinIProjectile entityarrow = new GriffinIProjectile(this.worldObj, this, par1EntityLivingBase, 1.6F, (float)(14 - this.worldObj.difficultySetting * 4));
int i = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, this.getHeldItem());
int j = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, this.getHeldItem());
entityarrow.setDamage((double)(par2 * 5.0F) + this.rand.nextGaussian() * 0.5D + (double)((float)this.worldObj.difficultySetting * 0.15F));
if (i > 0)
{
entityarrow.setDamage(entityarrow.getDamage() + (double)i * 0.5D + 0.5D);
}
if (j > 0)
{
entityarrow.setKnockbackStrength(j);
}
if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, this.getHeldItem()) > 0 || this.getSkeletonType() == 1)
{
entityarrow.setFire(100);
}
//this.playSoundEffect("griffinimod:shot", 1.0F, 1.0F);
//this.playSound("griffinimod:shot", 1.0F, 1.0F);
//worldObj.playSoundAtEntity(this, "griffinimod:shot", 1.0F, 1.0F);
this.worldObj.spawnEntityInWorld(entityarrow);
}