Lord_Lorden Posted December 24, 2018 Posted December 24, 2018 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. Quote
unassigned Posted December 24, 2018 Posted December 24, 2018 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. Quote Currently developing: https://github.com/unassignedxd/Dynamic-Quarries
Lord_Lorden Posted December 28, 2018 Author Posted December 28, 2018 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. Quote
Cadiboo Posted December 28, 2018 Posted December 28, 2018 Look at how structure blocks do it. IIRC those methods would be all that is required Quote About Me Spoiler My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.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)
Lord_Lorden Posted December 29, 2018 Author Posted December 29, 2018 Thank you! I have never used the structure block, so I didn't even think to look at it for an example. This had exactly what I needed. Quote
Lord_Lorden Posted December 29, 2018 Author Posted December 29, 2018 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? Quote
Recommended Posts
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.