Chunk+Block pos <=> Global pos: no round trip?

  • @red51: Something strange seems to happen when converting between Chunk+Block coordinates and Global coordinates when Global is negative.


    (Chunk -1, block 0) converts into global position -16 (using ChunkUtils.getGlobalPosition())


    BUT


    Global position -16 converts into (Chunk -2, block 15) (using ChunkUtils.getChunkAndBlockPosition()) which is 1 block off.


    This also happens when creating Areas with the Area(Vector3f globalStartPosition, Vector3f globalEndPosition) constructor: the chunk and block start/end positions of the resulting Area are off by one block if any global position is negative.


    This is a small plug-in which tests these methods.


  • Hmm... yeah that's indeed a problem. It has technical reasons, more precisely it's caused by the way how negative numbers are handled and the "rounding issues" when chunk/block positions are converted into a global position (the resulting position points to the lower right corner of a block instead to the center of a block). But of course it's very inconvenient (and it might be confusing in certain situations)... nevertheless, this issue will be sorted out with the next update :)

Participate now!

Don’t have an account yet? Create a new account now and be part of our community!