EmperorZelos Posted August 19, 2015 Posted August 19, 2015 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? Quote
Elix_x Posted August 19, 2015 Posted August 19, 2015 The question is: do you want this variables be global per dimension or be global per mc instance? Quote Check out my mods: BTAM Armor sets Avoid Exploding Creepers Tools compressor Anti Id Conflict Key bindings overhaul Colourfull blocks Invisi Zones
EmperorZelos Posted August 19, 2015 Author Posted August 19, 2015 Never crossed my mind, which are possible? And if both how are both done? Quote
Elix_x Posted August 19, 2015 Posted August 19, 2015 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... Quote Check out my mods: BTAM Armor sets Avoid Exploding Creepers Tools compressor Anti Id Conflict Key bindings overhaul Colourfull blocks Invisi Zones
delpi Posted August 19, 2015 Posted August 19, 2015 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. Quote Long time Bukkit & Forge Programmer Happy to try and help
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.