Home > Back-end >  Algorithm to get an Id's components
Algorithm to get an Id's components

Time:09-28

I have a chunk which is just a 16 x 16 grouping (a chunk can be either positive or negative) and I used it to create a unique ID. The issue is I now need to take that chunkID and turn it back into its x and z component how would I do this?

long chunkID = (long) chunk.getX() & 0xffffffffL | ((long) chunk.getZ() & 0xffffffffL) << 32;

CodePudding user response:

You store the x value in the lower 32 bits of your chunkID, to get those just cast back to int:

int x = (int) chunkID;

The z value is in the upper 32 bits, so we need to shift down first:

int z = (int) (chunkID >> 32);
  • Related