Jump to content

[1.6.4]How to store data in a file


Recommended Posts

Have you searched?  this is well documented.  There is also good examples in the bukkit community that could be cross referenced.


After you have done all that, let us know what you had trouble with.

Long time Bukkit & Forge Programmer

Happy to try and help

Link to comment
Share on other sites

As always: It depends™.

Where does that variable belong to?

To a Block? Use a TileEntity or metadata (only 4 bits, most likely not enough if you say "variable").

To an Item? Use the NBTTagCompound attached to every ItemStack.

To an Entity? Use writeToNBT / readFromNBT or IExtendedEntityProperties in case it is not your entity.

To a specific world (=dimension)? Use WorldSavedData with World#perWorldStorage.

To a save file? Use WorldSavedData with World.mapStorage.

To the Mod in general? Use the Configuration class provided by forge, or just a normal file for more complex data (you can use the normal Java file writing mechanics here).


I want to do it on an food item.

Can you give an example on how can i do this.

Link to comment
Share on other sites

To get the data from the ItemStack you need to get the ItemStack first of course. Where do you want that to be? In the players inventory? Somewhere else?

Well as it is a food item so i wanna check if player has ever eaten this which i am storing in the nbt then on tickhandler i wanna check that if the player has ever eaten that and if true then the process carry on if false than break.


Actually i am trying to make an infinite potioneffect for the food. That can last even after the player die or close the game or drink milk. I will add a new item which will break this process.

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.