Jump to content

[1.7.10] Do I have to save and read my TileEntities fields from NBTTags?


kauan99

Recommended Posts

Hello I have this doubt. If I have a TileEntity with a bunch of fields, and invoke markDirty() every time those fields are changed, do I still have to save those fields as NBTTags or is that data saved in some other way that doesn't need my code to explicitly do it?

WIP mods: easyautomation, easyenergy, easyelectronics, easymoney, easytrasportation, easysecurity, easymultiverse, easyfactions, easymagick, easyalchemy, easyseasons

Link to comment
Share on other sites

For a TileEntity's data to persist through reloads, it needs to be written to and then read back from NBT in the writeToNBT and readFromNBT methods. If you don't do this, the data won't be saved.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

I see, thank you. I thought this was automated somehow, but that wouldn't work very well, unless there was an annotation you could add to each field and it would probably be more complicated.

 

Oh I have an idea, maybe TileEntity could be declared as abstract and have 2 abstract methods named maybe "readUserNBT" and "writeUserNBT" or whatever. and then both readFromNBT and writeToNBT base implementations would invoke their respective abstract peers?

 

Or, if that would break some part of Forge's code, then maybe instead of extending TileEntity we modders would have to extend AbstractTileEntity, and that one would be just like TileEntity (in fact, a subclass of TileEntity), but the implementations of readFromNBT and writeToNBT overriden to the way I mentioned before and with the 2 abstract methods I also mentioned being declared in it.

 

Thus, preventing us begginers from forgetting to implement the necessary persistence methods.

WIP mods: easyautomation, easyenergy, easyelectronics, easymoney, easytrasportation, easysecurity, easymultiverse, easyfactions, easymagick, easyalchemy, easyseasons

Link to comment
Share on other sites

Hi

 

Forge is full of pitfalls like that unfortunately.

 

Like - if your client needs a copy of the field, you also need to implement packets for your TileEntity as well.

 

eg see here

http://greyminecraftcoder.blogspot.com.au/2015/01/tileentity.html

 

-TGG

 

So how do I know if my client needs those packets? My tile entity has 2 slots for Item Stacks, one for input and one for output; it has a fluid tank (not implemented yet, because I still don't know how) and an RF buffer (also still no idea how to do this). Do I have to implement those packet methods? My block is basically some sort of anvil-machine.

WIP mods: easyautomation, easyenergy, easyelectronics, easymoney, easytrasportation, easysecurity, easymultiverse, easyfactions, easymagick, easyalchemy, easyseasons

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.

Announcements



×
×
  • Create New...

Important Information

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