Mod development: Saving per-dimension data in user-editable format: how?

keybounce

New Member
Jul 29, 2019
1,925
0
0
I'm trying to improve rainfall in my flowing water fork. And I'm running into a real problem: determining sea level.

I can make a good guess -- 62 in the overworld, 49 in the end.

I can make good guesses for mystcraft/RfTools type dimensions -- "getAverageGroundLevel()", badly mis-named, returns 64, or 50, or 32, and turning that to 62, 49, and 31 is reasonable.

EDIT: 4 in flat worlds, and I don't know what in customized superflats.

But ... Twilight Forest actually needs 30 to avoid breaking swamps, other dimensions might actually have 63 for their overworld-like behavior, etc. And that's before oddball dimensions that are higher than normal. Before "sea-less" worlds that have no sea at all.

So, ultimately, I need to have a way for users to edit what I think is the answer. At first it was going into a config file, until I realized that in single-player, one config file drives multiple worlds. No good. And "WorldSavedData" makes NBT files that are not easy for users to edit. And relying on a server command to set data ... works but does not scale for worlds with lots of dimensions, plus the security issue (it would need to be op-only on servers, but accessible even without cheat codes in single player).

I'm thinking there has to be a better way. I cannot be the only one that has per-dimension / per-save data that needs to be editable by users and not stuck in an NBT file. What's a better way?
 
Last edited:

Robijnvogel

Well-Known Member
May 8, 2013
533
421
89
You are not the only one. I once suggested something like this at the MC Forge forums, but they didn't think there was enough demand to implement something like this.

For now, I hope there is some way to read arrays from config files. Otherwise you're going to have to invent your own format from scratch to dynamically read a file with "dimension id-water level pairs."
 

keybounce

New Member
Jul 29, 2019
1,925
0
0
Ha. Annoy Lex enough, and you get a perma-ban (with no appeal or any time limit, no warning), even if you are complaining about a serious world-destroying bug in forge that eventually gets fixed 2 years (or so) later.

There is a way to read an array from the config file, but it seems to be a really hard to use API, and it uses the config file -- not any per-world system. (Oh: the config API in general seems to be poorly thought out.)

I notice that a couple of mods save data on a per-world basis -- RTG/CC come to mind. I'll ask Zeno how he does it.

And yes, doing it myself is doable -- it's basic file I/O, and the java equivalent of fprintf/fscanf. And, figuring out how to determine the world's data directory, work in integrated server, dedicated server, and LAN, etc. Its doable, just a pain.

Hmm ... I just realized: Some mods make a directory and stuff files in there. That would be the easy solution -- one file per world. But I didn't see anything in the config API for that.
 

Robijnvogel

Well-Known Member
May 8, 2013
533
421
89
Ha. Annoy Lex enough, and you get a perma-ban (with no appeal or any time limit, no warning), even if you are complaining about a serious world-destroying bug in forge that eventually gets fixed 2 years (or so) later.

There is a way to read an array from the config file, but it seems to be a really hard to use API, and it uses the config file -- not any per-world system. (Oh: the config API in general seems to be poorly thought out.)

I notice that a couple of mods save data on a per-world basis -- RTG/CC come to mind. I'll ask Zeno how he does it.

And yes, doing it myself is doable -- it's basic file I/O, and the java equivalent of fprintf/fscanf. And, figuring out how to determine the world's data directory, work in integrated server, dedicated server, and LAN, etc. Its doable, just a pain.

Hmm ... I just realized: Some mods make a directory and stuff files in there. That would be the easy solution -- one file per world. But I didn't see anything in the config API for that.
Actually, search my name on the MC Forge forums.

I've asked something about the world save there and in the information they linked me, there was actually something about "per world saving".
I remember because it was something I desperately did not want to use.

I guess I misinterpreted your meaning. Forge does not have "per world configs", but per world saving should not be problematic.
 

keybounce

New Member
Jul 29, 2019
1,925
0
0
Forge may not have per-save config, but at least two mods have implemented such a thing. So at the least, the code I'd want is out there, somewhere.
 

lenscas

Over-Achiever
Jul 31, 2013
2,015
1,799
248
Why not store it in json? Sure it won't be the greatest thing to look at but assuming you can make it so it gets written nicely and not at 1 line it could at least be somewhat readable.
Failing that maybe xml? Again, not the greatest of things but it might be a good compromise between easy to load in and have users being able to edit it.
(This is assuming Java has an easy way to read those things, which I have no clue if that is the case)

Another thing that might work is to have a folder with a bunch of text files in each world where the name corresponds to the dimension id, however this is not a nice solution for the users but maybe it can work for the time being until someone comes with an better idea? If you implement it correctly you would only need to edit the function to read and write it.