Fix duplicate EntityKnockbackEvent for sprint attacks and add ENTITY_SPRINT_ATTACK cause - #14156
Fix duplicate EntityKnockbackEvent for sprint attacks and add ENTITY_SPRINT_ATTACK cause#14156Yager400 wants to merge 3 commits into
Conversation
…SPRINT_ATTACK cause
| - knockbackAmount, Mth.sin(this.getYRot() * Mth.DEG_TO_RAD), -Mth.cos(this.getYRot() * Mth.DEG_TO_RAD), damageSource, damage, comesFromEffect | ||
| + knockbackAmount, Mth.sin(this.getYRot() * Mth.DEG_TO_RAD), -Mth.cos(this.getYRot() * Mth.DEG_TO_RAD), damageSource, damage, comesFromEffect, this, io.papermc.paper.event.entity.EntityKnockbackEvent.Cause.ENTITY_ATTACK // Paper - knockback events | ||
| ); | ||
| - ); |
There was a problem hiding this comment.
if the only difference here is the cause then that should just be deduced as a oneliner and passed in, no need for an entire code block to be added (which doesn't follow the commenting guidelines anyways)
| + // Paper end - Check distance in entity interactions | ||
| + | ||
| + this.knockback(0.4F, xd, zd, source, damage, source.getDirectEntity(), source.getDirectEntity() == null ? io.papermc.paper.event.entity.EntityKnockbackEvent.Cause.DAMAGE : io.papermc.paper.event.entity.EntityKnockbackEvent.Cause.ENTITY_ATTACK); // CraftBukkit // Paper - knockback events | ||
| + io.papermc.paper.event.entity.EntityKnockbackEvent.Cause cause; |
There was a problem hiding this comment.
See the contrib guide; it needs start/end comments. You can't just add a block of code and then only comment a singular line in there
| - knockback, Mth.sin(this.getYRot() * Mth.DEG_TO_RAD), -Mth.cos(this.getYRot() * Mth.DEG_TO_RAD), damageSource, damage, comesFromEffect | ||
| + knockback, Mth.sin(this.getYRot() * Mth.DEG_TO_RAD), -Mth.cos(this.getYRot() * Mth.DEG_TO_RAD), damageSource, damage, comesFromEffect, this, io.papermc.paper.event.entity.EntityKnockbackEvent.Cause.ENTITY_ATTACK // Paper - knockback events | ||
| ); | ||
| - ); |
| + if (event.isCancelled()) { | ||
| + return; | ||
| + } | ||
| + if (!comesFromEffect) { |
There was a problem hiding this comment.
Tis boolean looks somewhat concerning, what does this signify? This looks like double firing is actually intended as in many cases this is additional knockback over the entity?
There was a problem hiding this comment.
That boolean distinguishes the base attack knockback from the extra knockback added by attributes/enchantments. The double movement application (base + extra) is vanilla behavior, but firing the Paper event twice for a single hit isn't desirable — that's what caused #11622 (event firing twice on sprint attacks). This boolean lets the event fire only once (on the base call), while both movement increments still get applied.
Fixes EntityKnockbackEvent beign fired twice when a player attacks an entity while sprinting. This was reported here: #11622 .
Adde the enum "ENTITY_SPRINT_ATTACK" cause in the Bukkit and Paper api so plugin can distinguish spring knockback and normal knockback.