Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

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!

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

 

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

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.