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.

[1.7.10] NBT Serialization or Reconstruction, which is better or prefere?

Featured Replies

Posted

Hey, hope everyone is well!

 

Anyway, I have the following data structure

 

/**
* This structure represents a category of TileEntity locations which are used to store metadata about certain TileEntities in
* the world.
* </p>
* A key can contain an array of TileEntity locations and a Location Set (X, Y, Z) can contain an array of metadata
*
* @param key   The key that defines a category
* @param x     The TileEntity X Coordinate
* @param y     The TileEntity Y Coordinate
* @param z     The TileEntity Z Coordinate
* @param metas The generic metadata that belongs to the coordinates (x, y, z).
*/
(String) key => [{ 
(int) x => 0, 
(int) y => 0, 
(int) z => 0, 
(bool[]) metas => {
	0: "Hello World!",
	1: 42.0F,
	2: false,
	3: int[] {1, 2, 3, 4, 5, 6}
}
}]

 

This data will be written to a TileEntity NBT on one Block and is synced with the client to allow changes in users rendering (I called it "BlockController").

 

Now I am at the point of saving this data but I am unsure in which direction to go, here are some options:

 

  • Serialize the data to a byteArray and save the bytes to NBT, deserialize on the client side for reading
  • Read all the entries and save them in NBT Compound tags by traversing all the arrays of data and constructing the NBT equivalent using NBTCompountTags, the client side will get an update with the NBT packet and deconstructs it into the original structure.

 

The client will never alter this data directly, and the transfer of this data will only happen Once when a player logs on.

 

What do ya'll think?

I require Java, both the coffee and the code :)

  • Author

The point of NBT is to represent your data accurately and "understandable", as opposed to just a stream of bytes (yes, NBT will eventually boil down to a stream of bytes, but that's besides the point).

So yeah, go for the 2nd approach, otherwise there is no point in using NBT.

 

Thanks, was actually leaning towards that approach but wasn't sure.

I require Java, both the coffee and the code :)

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.