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

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.

Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.

×   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'm currently implementing an Oil Pump block. It's bigger than a regular block and is loaded with the wavefront (.obj) loader provied by Forge. I'm trying to add collision boxes to my block but some of my collision boxes are bigger than 16x16x16, and i can walk through them... Here's what I override to create my bounding boxes : @Override public VoxelShape getShape(BlockState state, BlockGetter world, BlockPos pos, CollisionContext context) { return switch (state.getValue(FACING)) { default -> Shapes.or(box(-5, 2, 17, 37, 53, 32), box(-5, 2, -13, 37, 53, 2), box(-12, 0, -20, 44, 4, 53), box(6, 1, 43, 26, 26, 62), box(9, 49, 2, 23, 53, 17)); case NORTH -> Shapes.or(box(-21, 2, -16, 21, 53, -1), box(-21, 2, 14, 21, 53, 29), box(-28, 0, -37, 28, 4, 36), box(-10, 1, -46, 10, 26, -27), box(-7, 49, -1, 7, 53, 14)); case EAST -> Shapes.or(box(17, 2, -21, 32, 53, 21), box(-13, 2, -21, 2, 53, 21), box(-20, 0, -28, 53, 4, 28), box(43, 1, -10, 62, 26, 10), box(2, 49, -7, 17, 53, 7)); case WEST -> Shapes.or(box(-16, 2, -5, -1, 53, 37), box(14, 2, -5, 29, 53, 37), box(-37, 0, -12, 36, 4, 44), box(-46, 1, 6, -27, 26, 26), box(-1, 49, 9, 14, 53, 23)); }; } My question is : Is there a way to bypass the collision box size limit on blocks ?
• Your drivers are in a broken state, follow the guide in the FAQ: https://forums.minecraftforge.net/topic/125488-rules-and-frequently-asked-questions-faq/#:~:text=How do I update my drivers%3F
• Delete the forge-client.toml file in your config folder and test it again
• I am new at modding and i am in forge My question was how do i modify an already existing block property, like for blocks that you create its easy: public static final RegistryObject<Block> BURNEDWOOD = registerBlock("burnedwood", () -> new Block(BlockBehaviour.Properties.of().blablablabla)); but what do I put in for just vanilla blocks(I want to change the oak log to take more time to cut down, but idk how to access the properties of said block)

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

×

• #### Activity

×
• Create New...