Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

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

Featured Replies

Posted

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

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.

  • Author

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

  • Author

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

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.