mojira.dev
MC-195727

The Block coordinates are incorrectly rounded to integers when negative,

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.  

 

 

Linked issues

Attachments

Comments 2

Thank you for your report!
However, we are already tracking this issue, and this report is a Duplicate of MC-36602, which has been marked as Works as Intended - this is an intentional game feature. If you have a different opinion, please visit the Feedback website.

Please use the search function in the future to prevent duplicate reports.

Quick Links:
📓 Issue Guidelines – 🛠 Community Support – 📧 Customer Support – ✍️ Feedback and Suggestions – 📖 Game Wiki
💬 Mojira Subreddit – 💬 Mojira Discord

@Galaxy_2Alex

Thank you for your prompt response.

Please note that in your linked bug report (which I also linked as a related bug), that the issue involved -0 and +0, not an off-by-1 error which is what this issue is reporting.

Also, please note in the section above the "Reason that I expected it".
As this this behavior is apparently intentional, it's my duty to point out that this is an unreasonable intention (i.e., it does not stand to reason).

Further, if this behavior is intentional, then positive integers should be affected as well and they are not (i.e., XYZ: 10.5 76 26.5 should translate to Block: 11 76 27 and it does not).

Pete Hopkins

(Unassigned)

Unconfirmed

1.16.1

Retrieved