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

CraftFireball SetDirection applies wrong values to EntityFireball

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • None
    • None
    • None
    • Tested on both Windows 10 (64bit) and Ubuntu 16.04 (64bit)

    • CraftBukkit version git-Spigot-e7dc2f5-a8ec1d6 (MC: 1.15.2) (Implementing API version 1.15.2-R0.1-SNAPSHOT)
    • Yes

      When using setDirection(Vector) on a fireball, it will start to move at 10 times the intended velocity. 

      This can be tested by using the following code: (Also attached in Jar with source)

      @EventHandler 
      public void test(ProjectileLaunchEvent event){ 
          if(event.getEntity() instanceof Fireball){ 
              Fireball fireball = (Fireball) event.getEntity();
              fireball.setDirection(fireball.getDirection()); 
          } 
      }
      

      After some investigation it appears that the original EntityFireball in the Vanilla Server uses the following method to set the direction.

      public void setDirection(double d0, double d1, double d2) {
              d0 += this.random.nextGaussian() * 0.4D;
              d1 += this.random.nextGaussian() * 0.4D;
              d2 += this.random.nextGaussian() * 0.4D;
              double d3 = (double) MathHelper.sqrt(d0 * d0 + d1 * d1 + d2 * d2);
              this.dirX = d0 / d3 * 0.1D;
              this.dirY = d1 / d3 * 0.1D;
              this.dirZ = d2 / d3 * 0.1D;
      }
      

      While the CraftFireball seems to miss the last step after normalizing the vector (multiplying the direction values by 0.1D)

      @Override
      public void setDirection(Vector direction) {
              Validate.notNull(direction, "Direction can not be null");
              double x = direction.getX();
              double y = direction.getY();
              double z = direction.getZ();
              double magnitude = (double) MathHelper.sqrt(x * x + y * y + z * z);
              getHandle().dirX = x / magnitude;
              getHandle().dirY = y / magnitude;
              getHandle().dirZ = z / magnitude;
      }
      

      By adding the final step (* 0.1D) to the CraftBukkit class and compiling the server from the fixed source I was able to fix the bug. 

      I am however currently unable to submit a PR for this bug fix on Git.

            Unassigned Unassigned
            worthless_hobo Cory Caron
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: