I have a 3D array that contains integer values for each different block in my game; int[x][y][z] = blockid;
I need to flatten the array into a one dimensional array; int[VALUE] = blockid;
I have looked through the site for an answer most of the answers that I saw were incorrect and gave really bad results, For example my world is 2048x2048x128 blocks, That is 536870912 blocks. I need a mathematical equation that would give me 536870912 different results for 536870912 different values.
This is an example ( that doesn't work ) that I found on the site: value = x+y * maxX+z * maxZ * maxY The world is a square, The height is a fixed 128 though. Thanks.
EDIT: setter code:
world.blocks[x+y*world.maxSize+z*world.maxSize*world.maxSizeY] = Block.DARK_STONE.getId();
it used to be
world.blocks[x][y][z] = Block.DARK_STONE.getId();
getter code:
World.blocks[x+y*world.maxSize+z*world.maxSize*world.maxSizeY];
instead of
World.blocks[x][y][z];
the blocks[]
blocks = new int[2048*2048*128];
the maxSize and maxSizeY
maxSize = 2048;
maxSizeY = 128;