Hello guys,
I’d like to know when an entity is damaged wether or not the hit is a critical hit. For that I’m listening to the DamageEntityEvent.
First I thought of using DamageModifierTypes but I didn’t see any critical related modifier type. Then I saw there’s this CriticalHitData interface but I don’t understand how it works (what would be its associated data holder ?).
Any ideas ?
TL;DR How to know if a DamageEntityEvent is a critical hit or not ?
You’d want to query from the DamageSource if it is an EntityDamageSource and if the entity is an Arrow entity, you can query for the arrow.get(Keys.CRITICAL_HIT) since it will return a boolean.
I see… thanks !
So how could I get a critical hit a player did with a sword ? (It’s possible with a sword isn’t it ?)
If the damager is above the damagee and in the air, the hit is critical.
Not necessarily, according to the minecraft wiki:
In melee, a critical hit occurs when a player attacks a mob while falling
(Emphasis not mine)
See here
That’s a bit tricky but if it works, why not…
But aren’t there any DamageModifier for critical hits ?
There’s a new way to find out if a player critically attacked an entity with the new AttackEntityEvent, as it will include a DamageModifier with a DamageModifierTypes.CRITICAL_HIT if the player in fact critically hit the target entity.
Note that the flow of events is as follows: InteractEntityEvent.Primary -> AttackEntityEvent -> DamageEntityEvent. The reasoning for the separation is that attacking only evaluates the outgoing damage to the target entity, whereas damaging is evaluating the incoming damage.
1 Like
Interesting ! Thank you for the info !