PaperMC / PaperMC/Paper

Cancelling ProjectileHitEvent for entity collisions allows arrows to phase through blocks

Open
#11,478 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

  • #10804 by @notTamion — closed without merging
status: accepted type: bug version: 1.21.1
Dominant language
Java
Stars
12.7k
Forks
3.5k
Avg merge
3d 13h
Merged PRs (30d)
11

Description

Expected behavior

Cancelling ProjectileHitEvent for entity collisions should not prevent block collisions.

Observed/Actual behavior

Cancelling a ProjectileHitEvent fired for hitting an entity can cause arrows to phase through blocks.

Steps/models to reproduce

Shoot an arrow at an entity on the edge of its bounding box, towards the ground. If positioned correctly, the arrow will phase into a block. If the ground is thin enough, it will continue travelling after phasing into the block. Otherwise, it will be lodged within the ground.
Example image of lining up a shot:
Image

Plugin and Datapack List

Only a test plugin, with the following listener to cancel ProjectileHitEvent:

public class TestListener implements Listener {

    @EventHandler
    public void onHit(ProjectileHitEvent event) {
        if (event.getHitEntity() != null) event.setCancelled(true);
    }

}
Paper version

This server is running Paper version 1.21.1-119-master@7cd4f2c (2024-10-03T15:19:34Z) (Implementing API version 1.21.1-R0.1-SNAPSHOT)
You are running the latest version
Previous version: 1.21.1-85-c5a1066 (MC: 1.21.1)

Other

This seems to be a result of the logic in AbstractArrow#tick and Projectile#preHitTargetOrDeflectSelf. Arrows first ray trace to determine any block collisions, and then does another ray trace to find hit entities. If an entity that can be hit is found, the hit result is passed to Projectile#preHitTargetOrDeflectSelf. As such, the block collision is never considered, including when the ProjectileHitEvent is cancelled.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with AbstractArrow#tick and Projectile#preHitTargetOrDeflectSelf, following the block and entity ray-trace results described in the report. Reproduce with the provided listener by shooting an arrow at an entity near the ground; done means cancelling the entity hit still allows the arrow to collide with the block rather than phase through it.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
game-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.