Jump to content

Recommended method of storing Entities and TileEntities


Lord_Lorden

Recommended Posts

I am working on a mod which requires objects (Blocks, Entities, TileEntities) to be stored in a persistable location.  The stored data would then be used to restore the objects in another location.  Is there any recommended (low overhead, non-hacky) way to store Entities and TileEntities and then restore them at a later time?  This would ideally work for Entities and TileEntities from other mods.

Link to comment
Share on other sites

You could have a capability that is saved to the player (or item) that stores the blocks/tiles position and IBlockState (as in a map). For tiles, you'd also have to save its NBT to make sure that everything within it is saved. For entities, you'd have to also have to store what type of entity it is as well as its position. So when the player does x (say destroy a block), get the capability off the player, add the block to the map, and if needed, the NBT, and store it for later. Then, say the player right-clicks a block with some item - grab the capability off the player, access the map, and then iterate through all positions/states (this is also where you'd offset the positions of the blocks relative to the players) and apply needed NBT.

 

Hope this somewhat helps.

Link to comment
Share on other sites

I guess I misworded the question.  I am just looking for a way to save and then restore the state of TileEntities and Entities.  Is it sufficient to just save the Entity/TileEntity to a NBTTagCompound using writeToNBT(), and restore the Entity/TileEntity by creating a new one of the same class and calling readFromNBT() using the NBTTagCompound extracted from the original?  To be more clear, the mod will be saving the Blocks, Entities, and TileEntities in an area to a 'Pattern' object, and then use the saved data to restore the Blocks/Entities/TileEntities in a different location.

Link to comment
Share on other sites

Look at how structure blocks do it. IIRC those methods would be all that is required

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

Is there any limit to the amount of data I can store in the NBT of an Item/TileEntity?  I could not find a conclusive answer other than nested tags may not extend past a depth of 512.  While nesting should not be a problem, there is the potential for these patterns to hold quite a bit of data.  If there is some kind of limit that is easily exceeded, would it be possible to store the data within a subfolder of the current world?

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.