This will inflict the hit entity (whatever you just clobbered with your sword) with the wither effect for 200 ticks (10 seconds). at level 1. You can play around with potion ID, duration and level as you have with your armour effects, it's the same construct.
The amusing thing with this method is that you can set what happens after "hitEntity." to loads of things:
hitEntity.motionY = 2.5D; Sends the hit entity about 30 blocks into the air (motionX & motionZ can be used for horizontal travel)
hitEntity.travelToDimension(-1); Sends the hit entity to Hell! (Dimension -1 is the nether)
hitEntity.setFire(5); Sets the entity on fire for 5 seconds.
Not strictly related, but you may also want to put this in the class:
public boolean hasEffect(ItemStack itemstack)
{
return true;
}
This gives your sword the shiny enchanted effect, making it look magical
Hope this helps, as usual message back if you don't understand or want to expand, and don't forget to press that green arrow if it helped!
Override Item#hitEntity to apply the potion effect, call super.hitEntity and return true. The first EntityLivingBase argument is the entity that was hit, the second is the entity that used the item to hit the first.
Rollback Post to RevisionRollBack
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Hello this is superdextor aka President Potato
I was wondering if any one knows how to add potion effects to swords.
Example: Hits a Creeper with the Sword and gives it Posion
If any one knows how to do this then please drop a comment below
Thanks
You mean like already on there once crafted?
https://limepot.xyz
i would like to change my username please for the love of god i ****ing hate this username
yeah sorta
when you hit a entity with the sword the entity gets a potion effect applied
Add the following method to your ModSword class:
public boolean hitEntity(ItemStack stack, EntityLivingBase hitEntity, EntityLivingBase attackingEntity)
{
hitEntity.addPotionEffect(new PotionEffect(Potion.wither.id, 200, 0));
return true;
}.
This will inflict the hit entity (whatever you just clobbered with your sword) with the wither effect for 200 ticks (10 seconds). at level 1. You can play around with potion ID, duration and level as you have with your armour effects, it's the same construct.
The amusing thing with this method is that you can set what happens after "hitEntity." to loads of things:
hitEntity.motionY = 2.5D; Sends the hit entity about 30 blocks into the air (motionX & motionZ can be used for horizontal travel)
hitEntity.travelToDimension(-1); Sends the hit entity to Hell! (Dimension -1 is the nether)
hitEntity.setFire(5); Sets the entity on fire for 5 seconds.
Not strictly related, but you may also want to put this in the class:
public boolean hasEffect(ItemStack itemstack)
{
return true;
}
This gives your sword the shiny enchanted effect, making it look magical
Hope this helps, as usual message back if you don't understand or want to expand, and don't forget to press that green arrow if it helped!
-Cookiehook
Check out my Youtube channel, where I build a theme park in vanilla Minecraft!
https://www.youtube.com/playlist?list=PLeCiIIOoWhe-mq3nYd_nXXrKw9MkjnUU7
Override Item#hitEntity to apply the potion effect, call super.hitEntity and return true. The first EntityLivingBase argument is the entity that was hit, the second is the entity that used the item to hit the first.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Thanks Guys again
Your the Best!
- Thread Locked