mojira.dev
MC-267937

Shooting a breeze with a piercing crossbow makes the game crash

If you try shooting a breeze from a distance with a crossbow enchanted with piercing IV the game will crash!!!

I think it happens because of the last change that was made in 24w03a: "Breeze is now deflecting all projectiles". Apparently Mojang totally forgot to adjust the behavior when shooting a breeze with a piercing crossbow, so the game doesn't know what to do, so it crashes!

Attachments

Comments 2

Can reproduce in Minecraft snapshot 24w03b. The game freezes rather than crashing.

Code analysis (Yarn mappings)

A piercing arrow will continuously check for entities to pierce through in a loop within the same tick. To prevent the same entity from being collided with twice, pierced entities are stored in the PersistentProjectileEntity#piercedEntities set and ignored by collision detection.

Projectile deflection prevents the code that mutates the pierced entities set from executing:

// PersistentProjectileEntity class
// This method is called until no entity in the piercedEntities set collides with the arrow
protected void onCollision(HitResult hit) {
    HitResult.Type type = hit.getType();

    if (type == HitResult.Type.ENTITY) {
        EntityHitResult entityHit = (EntityHitResult) hitResult;
        ProjectileDeflector deflector = entityHit.getEntity().getProjectileDeflector(this);

        if (deflector != ProjectileDeflector.NONE) {
            deflector.deflect(this, entityHit.getEntity(), this.random);
            return;
        }

        // This method updates the piercedEntities set
        this.onEntityHit(entityHit);
    } /* ... */

Therefore, the arrow will continuously attempt to collide with the same entity over and over and get deflected; an infinite loop occurs.

A fix would be to move the deflection behavior either past the pierced entities update code or to stop checking for further collisions after deflection occurs. The core way to prevent the infinite loop is to exit the while loop in some way.

DvirMC

(Unassigned)

1168649

Confirmed

Expansion B

Very Important

Crash

24w03a, 24w03b

24w04a

Retrieved