Uploaded image for project: 'Spigot'
  1. Spigot
  2. SPIGOT-7255

Infinite loop and crash caused by Projectile#setShooter entity lambda setup

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Invalid
    • Icon: Minor Minor
    • None
    • None
    • None
    • 1.19.2-R0.1
    • Yes

      Setting the shooter of a spawned arrow via the lambda setup causes a ProjectileShootEvent to fire. If you do logic on the ProjectileShootEvent that causes extra projectiles to fire, and you spawn an arrow in (seemingly only an arrow, but unsure?) using the lambda entity setup, it causes an infinite loop and crash.

      Example:

      Arrow arrow = shooter.getWorld().spawn(shooter.getEyeLocation().clone(), Arrow.class, e -> {
          e.setShooter(shooter); // Here
          e.setVelocity(velocity);
      });
      arrow.setShooter(shooter); // Not here

      Simply not using the lambda setup to set shooter isn't really the best option, because without it there's the visual bug for 1-2 frames where the arrows doesn't know if it should collide with you, instead of smoothly spawning in and animating in the direction provided.
       
      If this is an unreasonable request, for mitigation purposes I currently just cache a reference to the entity and ignore projectile shoot events that use it, but that's some overhead that may not be needed, and I don't know how expected it is that setting shooter in the lambda is firing projectile shoot events. At least my expectation was that spawning it in manually rather than using the .lanuchProjectile() entity function would not fire the event, and that's true, unless set in the lambda.

            Unassigned Unassigned
            kattreinkyle@gmail.com FACEGUY
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: