I was thinking of creating a sword in my mod. That is simple, the catch is that I want to make it so it actually hurts the user and does as minimal as possible damage to what it whacks (but has huge knockback).
Any ideas how to accomplish this? I know it is weird but the entire point of my mod is to be as outrageous as possible and have some pretty funny/stupid/preposterously outrageous stuff in it.
EDIT: Ok, I found someone's code from like 2 years ago (2013). I am trying to update it to try with 1.7.10 but I am not sure what modloader was replaced by, do you have any idea?
onLeftClickEntity is not the place you want to do this, nor should you use setHealth directly - much better to use attackEntityFrom so standard damage procedures can take place.
onLeftClickEntity is called before processing an actual attack, and returning true cancels any further interaction, meaning the player is no longer even hitting the entity, just taking damage.
Use hitEntity, like we suggested, and read my post again if it is unclear who the player might be. Keep in mind that it is not necessarily always a player wielding your item.
Any ideas how to accomplish this? I know it is weird but the entire point of my mod is to be as outrageous as possible and have some pretty funny/stupid/preposterously outrageous stuff in it.
EDIT: Ok, I found someone's code from like 2 years ago (2013). I am trying to update it to try with 1.7.10 but I am not sure what modloader was replaced by, do you have any idea?
[quote]
Anyway, more descriptive names for the parameters should help you figure it out:
So the 3rd parameter is the entity that is doing the hitting (usually a player), and the 2nd one is the one being hit.
You want the attacker to take damage? => attacker.attackEntityFrom(DamageSource.generic, 100.0F);
@Vic_ @coolAlias thank you for all your help. I was able to solve this by doing
onLeftClickEntity is called before processing an actual attack, and returning true cancels any further interaction, meaning the player is no longer even hitting the entity, just taking damage.
Use hitEntity, like we suggested, and read my post again if it is unclear who the player might be. Keep in mind that it is not necessarily always a player wielding your item.