Jump to content

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


Belpois

Recommended Posts

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 :)

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

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.



×
×
  • Create New...

Important Information

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