Jump to content

Recommended Posts

Posted

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

Posted

worldObj.playSoundAtEntity(this, "griffinimod:shot", 1.0F, 1.0F);

This should work, assuming you have sound at:

mcp/src/minecraft/assets/griffinimod/sound/shot.ogg

 

 

Is the folder name supposed to be "sound". I had the file in that location, but the folder name is "sounds".

Posted

Yes, only "sound" will work in your case.

 

That is the simplest solution that I would have never noticed. Once I'm back at my computer, I'll try it then mark this issue as solved.

Posted

Yes, only "sound" will work in your case.

 

I changed the folder name to "sound" and it still doesn't play the sound in game. I am using all the same code as I was before.

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

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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