Jump to content

Recommended Posts

Posted

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!

Posted

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.

 

Posted

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

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.

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

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

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

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.