Posted July 3, 201510 yr Hello, my question is: How can i convert my 3 dimensional Block array into 1 dimensional that will be used in chunk for filling. Basically i create a Block[][][] blocks3d = new Block[15][255][15] Then i fill it with needed blocks. And now i want to convert it to Block[] blocks1d = new Block[16*16*256] which will be used in new Chunk(worldObj, blocks1d, chunkX, chunkY) After looking at vanilla code i'm thinking about: for(int xx = 0; xx < 15; xx++){ for(int zz = 0; zz < 15; zz++){ for(int yy = 0; yy < 255; yy++){ blocks1d[xx << 11 | zz << 7 | yy / 256] = blocks3d[xx][yy][zz]; } } } Would that work? Do i have to test it to see (i can't test this part of mod yet)? Thanks for help! If you have any questions - just ask! Check out my mods: BTAM Armor sets Avoid Exploding Creepers Tools compressor Anti Id Conflict Key bindings overhaul Colourfull blocks Invisi Zones
July 3, 201510 yr Author That should be fine. But I recommend you keep it as a 1d array in the first place, then you don't have to do the copying step. All i wanted is logic of converting 3d in 1d. Of course i'll rewrite it to write in 1d array directly. But for now i was searching for correct logic. Check out my mods: BTAM Armor sets Avoid Exploding Creepers Tools compressor Anti Id Conflict Key bindings overhaul Colourfull blocks Invisi Zones
July 3, 201510 yr Shouldn't you be using 16 instead of 15? Chunks are 16x16, using index 0 to 15, so it seems you are excluding a line of blocks on two sides of the chunk. Similarly, the y axis should use 256 instead of 255. http://i.imgur.com/NdrFdld.png[/img]
July 3, 201510 yr Author Shouldn't you be using 16 instead of 15? Chunks are 16x16, using index 0 to 15, so it seems you are excluding a line of blocks on two sides of the chunk. Similarly, the y axis should use 256 instead of 255. I wasn't sure about this either. Because chunks are 16*16 and they start count from 0, wouldn't 16 make 17 blocks? Anyways, i'll change it to 16... Check out my mods: BTAM Armor sets Avoid Exploding Creepers Tools compressor Anti Id Conflict Key bindings overhaul Colourfull blocks Invisi Zones
July 3, 201510 yr No, arrays are zero-indexed, and go up to but not including the size: int[] array = new int[16] has 16 elements, from 0 to 15. array[16] will give you an out of bounds exception. http://i.imgur.com/NdrFdld.png[/img]
July 3, 201510 yr Author No, arrays are zero-indexed, and go up to but not including the size: int[] array = new int[16] has 16 elements, from 0 to 15. array[16] will give you an out of bounds exception. Completely forgot that... Oops... Check out my mods: BTAM Armor sets Avoid Exploding Creepers Tools compressor Anti Id Conflict Key bindings overhaul Colourfull blocks Invisi Zones
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.