# [1.7.10] Block[][][] to Block[] for new Chunk

## Recommended Posts

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!

##### Share on other sites

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.

##### Share on other sites

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.

##### Share on other sites

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.

##### Share on other sites

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...

##### Share on other sites

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.

##### Share on other sites

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...

## 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.

×   Pasted as rich text.   Restore formatting

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×

• ### Posts

• I have the same problem with the mac studio m1 max.   But I just have this problem with the mod when I use the multiMC launcher. If I use the Tlauncher the mod is working without a problem but in my test only with the 1.18.1, I dont test it jet with the new 1.19.2   I some one know how to solve this problem or how to recompile the mod is awesome.
• When the below code runs in game adding/removing a piece of bronze armor will change the players FOV, however the speed change only applies if you leave the game and rejoin. How is it possible to dynamically change the speed as the player adds/removes pieces of bronze armor?   @SubscribeEvent public void onPlayerTick(TickEvent.PlayerTickEvent event) { Player player = event.player; Iterable<ItemStack> slots = player.getArmorSlots(); final int[] bronzeArmourItemCount = {0}; slots.forEach(itemStack -> { if (itemStack.is(ModItems.BRONZE_BOOTS.get()) || itemStack.is(ModItems.BRONZE_LEGGINGS.get()) || itemStack.is(ModItems.BRONZE_CHESTPLATE.get()) || itemStack.is(ModItems.BRONZE_HELMET.get())) { bronzeArmourItemCount[0]++; } }); if (bronzeArmourItemCount[0] != lastBronzeArmourItemCount) { player.getAbilities().setWalkingSpeed((float) (0.1+bronzeArmourItemCount[0]*0.075)); lastBronzeArmourItemCount = bronzeArmourItemCount[0]; } }
• Hello There! Finally in part 3 of Project Run we go through some pretty intense coruses and we even end up in the BACKROOMS! Will we be able to escape the backrooms or will the rest of the video be in them?

• 0
• 3
• 0
• 0
• ### Who's Online (See full list)

×

• #### Activity

×
• Create New...