Skip to content

Fix duplicate EntityKnockbackEvent for sprint attacks and add ENTITY_SPRINT_ATTACK cause - #14156

Open
Yager400 wants to merge 3 commits into
PaperMC:mainfrom
Yager400:fix/sprint-attack-knockback-cause
Open

Fix duplicate EntityKnockbackEvent for sprint attacks and add ENTITY_SPRINT_ATTACK cause#14156
Yager400 wants to merge 3 commits into
PaperMC:mainfrom
Yager400:fix/sprint-attack-knockback-cause

Conversation

@Yager400

@Yager400 Yager400 commented Aug 7, 2026

Copy link
Copy Markdown

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.

@Yager400
Yager400 requested a review from a team as a code owner August 7, 2026 13:31
@github-project-automation github-project-automation Bot moved this to Awaiting review in Paper PR Queue Aug 7, 2026
- 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
);
- );

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
);
- );

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

+ if (event.isCancelled()) {
+ return;
+ }
+ if (!comesFromEffect) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@github-project-automation github-project-automation Bot moved this from Awaiting review to Changes required in Paper PR Queue Aug 7, 2026
@Yager400
Yager400 requested a review from electronicboy August 8, 2026 18:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Changes required

Development

Successfully merging this pull request may close these issues.

2 participants