Jump to content

[1.9] What is the best way to have data attached to a world?


WorldsEnder

Recommended Posts

I am porting a mod from 1.7.10 to 1.9. Previously I used a self-written WorldChunkManager that used the perWorldStorage to have some data associated with the world it is used for. But now (thank god) chunk manager are a thing of the past, and it's solved via WorldProviders, ISaveHandlers and IChunkGenerators.

 

What I did previously to access the data, was

(CustomChunkManagerClass) server.getWorldChunkManager()

and then work with the custom instance.

 

The question I have is, what is the simplest method to attach data to the world (must only be done on the server, I allocate some "building slots" and keep track of them on the server, that the client doesn't need to know of) that fulfills the following:

 

1) I can reliably save and load the data when the world gets loaded/unloaded

2) I can access the data when I have WorldServer instance

 

Is there some sort of Capability system as there is for Entities, Items, etc...?

 

 

Link to comment
Share on other sites

Okay, got it, so I write a static method inside the SaveData

 

public static ExampleWorldSavedData retrieveFor(World world){
  ExampleWorldSavedData instance = (ExampleWorldSavedData) world.getPerWorldStorage().loadData(ExampleWorldSavedData.class, DATA_NAME);

  if (instance == null) {
    instance = new ExampleWorldSavedData();
    storage.setData(DATA_NAME, instance);
  }
}

 

for now and use Capabilities in 1.10.2

Link to comment
Share on other sites

Okay, got it, so I write a static method inside the SaveData

 

public static ExampleWorldSavedData retrieveFor(World world){
  ExampleWorldSavedData instance = (ExampleWorldSavedData) world.getPerWorldStorage().loadData(ExampleWorldSavedData.class, DATA_NAME);

  if (instance == null) {
    instance = new ExampleWorldSavedData();
    storage.setData(DATA_NAME, instance);
  }
}

 

for now and use Capabilities in 1.10.2

 

That's correct.

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

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.



×
×
  • Create New...

Important Information

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