Jump to content

TileEntity vs. WorldSavedData

Recommended Posts

I need to store a single number with a specific Block type. The number should be modifiable by the user, which I already have a method for, and persist between games. Each Block in the world should have the number independent from the other ones. I should be able to easily retrieve the number frequently. Lastly, I need to be able to iterate over all instances of the Block in the world. That part doesn't need to be included with the numbers, but it would be convenient.


With that information, would it preferable to create an entire TileEntity for this Block type just for this single number, or would it be better to use the WorldSavedData system to store and retrieve it? I want to also consider compatibility with other mods that allow for copying of Blocks, like WorldEdit and MCEdit, as in the copied Blocks should have a number associated with them and should be part of the data structure that I can iterate over.


Thank you.

Link to comment
Share on other sites

That depends on what the valid range of numbers is.

If the numbers you are trying to store are heavily restricted (eg 100 different possible values) then use blockstates (more efficient).  You can cache the block instances in a custom data structure that you don't need to save (since you can easily regenerate it by iterating through all blocks when (eg) loading a chunk.)


Otherwise, use a TileEntity.  The list of all (loaded) tileentities is maintained by vanilla automatically, you just need to filter it.


7 hours ago, Caffeinated Pinkie said:

would it be better to use the WorldSavedData system to store and retrieve it?

Down that road lies nothing but pain and suffering....  Chunks loading in and out, other mods manipulating your blocks, multithreaded access, loss of synchronisation...





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.

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.