Jump to content

Recommended Posts

Posted

So im trying to make my custom lightsaber item play a sound when hitting an entity. I got it to work with the method onItemRightClick, but i cant get it to work with hitEntity. Im rather new to modding and id like to get help.

Here is the working code

 

public class ItemModLightsaber extends ItemSword {

    public ItemModLightsaber(ToolMaterial Kyber, String unlocalizedName) {
        super(Kyber);
        this.setUnlocalizedName(unlocalizedName);
        this.setCreativeTab(IRCrTab.tabIRItems);
        this.setTextureName("mod:" + unlocalizedName);
    }

    @Override
    public boolean hitEntity(ItemStack stack, EntityLivingBase hitEntity, EntityLivingBase attackingEntity) {
        hitEntity.setFire(4);
        return true;

    }
    public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player)
    {
            world.playSoundAtEntity(player, "mod:lightsaberswing", 1.0F, 1.0F);
            return itemStack;                
}
}

Posted

this doesnt work either, and i have no idea why

    
    public ItemStack hitEntity(ItemStack itemStack, World world, EntityPlayer player)
    {
            world.playSoundAtEntity(player, "mod:lightsaberswing", 1.0F, 1.0F);
            return itemStack;
            
    
}

Posted
Spoiler

 

Like i said, im a complete beginner and only know the really basic stuff, im learning it as i go i suppose. Do you know a good source where i can learn the basic java needed for modding(or just writing java in general), so i dont have to bother anyone like this ?

 

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.