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

BoundingBox#rayTrace returns incorrect null

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • None
    • None
    • None
    • Windows 7 Professional
      java version 1.8.0_251

    • This server is running CraftBukkit version git-Spigot-0509002-7c03d25 (MC: 1.16.1) (Implementing API version 1.16.1-R0.1-SNAPSHOT)
    • Yes

      API bug happens on Spigot & CraftBukkit 1.13.2, 1.14.4, 1.15.2, 1.16.1
      source code of provided plugin https://github.com/MrCrackerplays/boundingboxbug
      time spent figuring out this bug: about 12 hours, (yes it probably could've been figured out in a shorter time period but I went into the wrong direction at first)

      Raytracing entities (World#rayTraceEntities) will in specific situations return a null when in reality it does go through an entity, which is caused by BoundingBox#rayTrace (being used in CraftWorld on row 1161) returning a null when one of the values (x, y, z) of the Vector direction is -0 (not sure why it's negative but that's what happens).

      The null being returned is due to those values (direction's x, y, and z) being used to divide 1.0D and that division by -0 results in -Infinity which will in turn lead to one of the if statements returning null (from my testing it's always the first one, at BoundingBox row 891, but I imagine the other if statements would also result in the same).

      A direction's value will contain a zero when taking the direction an entity is facing is [0.0,0.0], [0.0,any_number], or [any_number,0.0].

      Steps to reproduce this bug with the provided plugin:

      1. Summon an entity (for ease of use I recommend an armor stand)
        /summon ArmorStand
      1. Teleport yourself so that yaw/pitch (either/both) are 0 using this command:
        /teleport @p ~ ~ ~ 0 0

        and move yourself, without changing where you're looking, such that you are looking at the entity's hitbox (press F3 + B to view the hitbox)

      1. Use the plugin's command
        /ray

        which will tell you whether the raytrace resulted in an entity being hit or not within 25 blocks

      While this bug almost certainly will never be a problem when taking the direction a player is looking (since most of the time a player's facing won't be at exactly 0 but at some decimal number), it is however a very common problem when taking the direction a mob is looking at, since those are (in my experience) most of the time looking straight ahead ([any_number,0.0]) rather than up/down somewhere.

            Unassigned Unassigned
            MrCrackerplays Patrick
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: