Uploaded image for project: 'Minecraft: Java Edition'
  1. Minecraft: Java Edition
  2. MC-195727

The Block coordinates are incorrectly rounded to integers when negative,

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • None
    • 1.16.1
    • None
    • OS: Windows 8.1
      Java Version 1.8.0_51 (64-bit)
    • Unconfirmed

      When viewing the F3 Debug Information to view my current coordinates, The double listed for the XYZ is incorrectly off by 1 when compared to the Block information.  

      This is consistent for any negative coordinate.  

      Positive coordinates are correct.  

      This appears to be a problem with using "Math.floor" with negative numbers, which always rounds down (towards 0 when positive, away from 0 when negative), instead of casting the double into an int which would correctly truncate the fractional portion instead.

       

      What I expected to happen was...:
      When viewing the debug information for my current position, the screen showed:

      XYZ: -152.477 -0.07309 -3.334

      I expected to see:  

      Block: -152 0 -3

       

      What actually happened was...:

      I saw this instead:

      Block: -153 -1 -4

       

      Reason that I expected it:
      When I am between blocks (i.e., within a fractional coordinate) I expect to see the Block coordinate to be the same as the XYZ coordinate without the fraction (i.e., just the integer portion of the coordinate).
      This is because when I am between A and B, I am within A and moving to B.
      Example:
      10.7 65 256.9 means I have not yet crossed any of the the lines that divide 10 65 256 from:

      • 10 65 257
      • 10 65 255
      • 11 65 256
      • 9 65 256

       

      Steps to Reproduce:
      1. Start any existing world, or create a new one in v1.16.1.  
      2. Once spawned in, press F3 to bring up the debug screen.  
      3. Move to any location with a negative X, Y, or Z coordinate.  
      4. Notice as you move within your chosen negative axis that the XYZ, showing the fractional portion of the coordinate, is always one less than the Block coordinate for where you are standing. This affects all negative coordinates and only negative coordinates. If you are at a positive X and a negative Z, you will see the off-by-1 on the Z only. Likewise, if you are at a negative X and a positive Z, you will see the off-by-1 on the X only. If both are negative, both will be affected. If neither are negative, then neither will be affected. This also occurs for negative values of Y (see attached screenshot).

       

      Similar bug reports:
      MC-4794
      MC-36602
      MC-47763
      MC-51286
      MC-113466
      MC-135638

      All of the above have been marked as resolved.
      Whether this bug has never been successfully patched, or whether this is a regression of some kind, I'm not sure.
      What I am sure about is that, for those reports above which were marked as "Works as Intended", this was clearly a mistake as this behavior cannot be what the developers intended.

      If I am standing on top of the center of a block at -10 76 -25, then my XYZ coordinates should be be -10.5 76 -25.5 and my Block should be -10 76 -25..
      When I move exactly 1 block to the west (further along the negative X axis), my XYZ coordinates should then be -11.5 76 -25.5 and my Block should be -11 76 -25.
      Yet, the debug screen tells me that I am at -11 75 -26 when I am standing on -10 76 -25.

      Again, positive coordinates are displayed correctly.
      This only affects negative coordinates.

       

      Suggestions for correction:

      The "official Minecraft wiki" states about Block (emphasis mine):

      The coordinates of the block the player's feet are in, in xyz format. Similar to XYZ as above, floored to the whole number.

      The quote above made me suspect that the Block information is being obtained using "Math.floor" and empirical testing confirms behavior consistent with this suspicion.  

      Simply casting to an int (i.e., "(int) coordinate") would suffice as that truncates fractions, rather than rounding them in a particular direction.  

      You could also do "Math.floor(Math.abs(coordinate))" to strip any negative signs prior to "floor"ing the number, which would also give you correct behavior.  

       

       

            Unassigned Unassigned
            uncle_pete Pete Hopkins
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: