Jump to content

[1.7.10] Global Variable Storage


Recommended Posts

Storing information in tile entities and get it back when the server loads (or chunk in their case) is relatively trivial.


My question is, what if I want to have global variables? Like if one did some form of gate system to store the adresses which are then reloaded everytime the server is booted up again?

Link to comment
Share on other sites

Never crossed my mind, which are possible? And if both how are both done?

The first one will use world saved data (google it).

The second one is more complicated and requires new class holding your variables which saves and loads to file using either save and load or server start and stop events.

In both cases server to clients variables synchronisation is required...

Link to comment
Share on other sites

There is perworld (dimension) and permap (per instance) versions that do this.  Do a search and you will find an explanation by diesieben07 on it.


you don't need to do the 'complicated' route.



Below is the pertinent part he stated.



Each WorldSavedData has a unique identifier (for maps this is map_0, map_1 and so on).

That is the parameter the constructor takes.

Also think about if you want actual per World (=per dimension) storage or just a per map (= per save) storage.

For per world use world.perWorldStorage and for per map use world.mapStorage.

Then to create a new data use

Code: [select]

YourAwesomeData data = new YourAwesomeData("IDENTIFIER");

world.perWorldStorage.setData("IDENTIFIER", data); // or world.mapStorage

To get that data back any time use

Code: [select]

YourAwesomeData data = (YourAwesomeData)world.perWorldStorage.loadData("IDENTIFIER");

loadData will return null if the data has not been created yet.

Thats it. Just be sure to always call markDirty() on your data when you change a value, otherwise MC will not save it.

If you want an example look at the link Mew posted.

Long time Bukkit & Forge Programmer

Happy to try and help

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.