Jump to content

[1.7.2] How to add Potion effect to a weapon


CodeLined

Recommended Posts

Hey,

 

I started picking up minecraft modding recently and I wanted to get a weapon to apply a potion effect when it hits an entity, I looked around in ItemSword and found "hitEntity" So I tried the following (here is the whole class)

 

public class ItemStoneSpear extends ItemSword{

public ItemStoneSpear(ToolMaterial p_i45356_1_) {
	super(p_i45356_1_);
	// TODO Auto-generated constructor stub
}

@Override
public boolean hitEntity(ItemStack par1ItemStack, EntityLivingBase par2EntityLivingBase, EntityLivingBase par3EntityLivingBase){
	par1ItemStack.damageItem(1, par3EntityLivingBase);
	par2EntityLivingBase.addPotionEffect(new PotionEffect(Potion.poison.getId(),100 , 1));
	return true;
}



}

 

But it doesn't work no matter what I try. So if someone could help me out i'd love it a ton :D

Link to comment
Share on other sites

Hey,

 

I started picking up minecraft modding recently and I wanted to get a weapon to apply a potion effect when it hits an entity, I looked around in ItemSword and found "hitEntity" So I tried the following (here is the whole class)

 

public class ItemStoneSpear extends ItemSword{

public ItemStoneSpear(ToolMaterial p_i45356_1_) {
	super(p_i45356_1_);
	// TODO Auto-generated constructor stub
}

@Override
public boolean hitEntity(ItemStack par1ItemStack, EntityLivingBase par2EntityLivingBase, EntityLivingBase par3EntityLivingBase){
	par1ItemStack.damageItem(1, par3EntityLivingBase);
	par2EntityLivingBase.addPotionEffect(new PotionEffect(Potion.poison.getId(),100 , 1));
	return true;
}



}

 

But it doesn't work no matter what I try. So if someone could help me out i'd love it a ton :D

 

Didn't know that there is an hitEntity function(would have used an onLivingUpdateEvent).

Please put some test output into the hit function and test if it is called when you hit something.

Here could be your advertisement!

Link to comment
Share on other sites

Didn't know that there is an hitEntity function(would have used an onLivingUpdateEvent).

Please put some test output into the hit function and test if it is called when you hit something.

 

Yeah, the hitEntity function doesn't seem to be getting called;

how would I go about using onLivingUpdateEvent?

Link to comment
Share on other sites

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.