Creating on-hit effects on tools!

Started by c3d7 on Wed, 01/02/2019 - 01:00

Topic category: User side tutorials

Last seen on 08:38, 4. Jan 2019
Joined Jan 2019
User points:

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
Creating on-hit effects on tools!
Wed, 01/02/2019 - 01:04 (edited)

Creating on-hit effects
Hello and welcome to my tutorial on how to create on-hit effects on your tools! This tutorial will teach you on how to add potion effects to mobs when you hit them with a tool.

Step 1:
Since there is no on-hit procedure in tools we will be coding in it ourselves, so go on ahead and create your tool.

Step 2:
Select your tool and click on the "Edit the code of the selected mod element" the button should look like this "</>".

Step 3:
Override the public boolean "hitEntity", here's the code if you don't know how to:

@Override
public boolean hitEntity(ItemStack stack, EntityLivingBase target, EntityLivingBase attacker) 
{
	return true;
}

Make sure it is placed inside the class that extends the tool, not the mod element.

Step 4:
Currently, the code itself isn't going to do anything, so, insert this next bit of code on top of return true:

target.addPotionEffect(new PotionEffect(MobEffects.WITHER, 100, 2, false, false));

This is the code that gives out the effect, the important part here is the "new PotionEffect()" part, I'll be explaining it now.

  • The first argument is the effect that it's gonna give, there are a lot more effects, test them out.

  • The second argument determines how long the potion lasts in ticks, 20 ticks is a second. I've set mine to 100 ticks so that the wither effect would last for 5 seconds.

  • The third argument, determines the strength of a potion, I've set it to 2 so that it gives out a Wither III effect.

  • The fourth argument makes the particles less visible.

  • The fifth argument determines if the particles are visible or not.

 

That is the end of my tutorial, if you need some help, leave a comment. Also, tell me if there's something wrong, I have never tested this in a mod element due to me being unable to create mod elements for some reason.

Edited by c3d7 on Wed, 01/02/2019 - 01:04
Last seen on 18:00, 30. Jul 2019
Joined Dec 2018
User points:

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
¿Can you put the full code…
Thu, 02/21/2019 - 14:26

¿Can you put the full code of the sword to see if it's okay? 

 

Last seen on 20:10, 4. Aug 2019
Joined Feb 2019
User points:

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
  Can you put the complete…
Sun, 02/24/2019 - 21:28

 

Can you put the complete code of the sword to see because I do not know where I should put your code @c3d7