Started by
GSantos
on
Topic category: Help with Minecraft modding (Java Edition)
Hello everyone, Im trying to make the player take damage when see a entity hurt, not when he hurts the mob, but yes when The entity take damage for some thing. I don't find it, can someone help me?
...This would be tricky, but not impossible. There is a global trigger for 'when entity hurt.' You would need to make a procedure with this trigger, and then target either every player in the world, or every nearby player, (in, say, a 64 block radius), as an entity iterator. (An entity iterator is a special type of bracket that runs code on every entity in its radius.)
Then comes the tricky part. Essentially, you need to check if the entity iterator is a player, and if their look angle vectors intersect with the hitbox of the entity being hurt. (Or are in the general vicinity.) So you need to use trig to caclulate a vector between the entity's position and the player's position, and then check if their look angle vector is near enough to the first vector to determine whether or not they should take damage.
This is, uh, kind of advanced even for me, but again, not totally impossible. There isn't a built in trigger for it though.
Ok thanks you, Im probably saying some thing about it after
Yeah, I really don't know how make the make the second part. I only do the iterator is a player the part of vectors I dont know
If you know a way to player take damage when he attack with a sword its usefull too, less then take damage when see a entity hurt but also usefull
Forget the thing about sword cause damage, because I already do it
An easier method might be to just try to detect if the player is facing in the direction of the entity that got hurt. (You would subtract the x/y/z positions of the entity and the player to determine if it's to the north, south, east, or west; and then check if the player is facing that direction.) Of course, this doesn't take into account any solid blocks in between them, or the elevation of the entity.