#Saving json data to folders in resources or data directory

28 messages · Page 1 of 1 (latest)

patent pier
#

Is it possible to write to json files to these directories at runtime? Is there any relevant documentation?

quaint fog
#

wait i missed a little bit what you meant, sry. i believe it is possible, however i have never tried it before. it could be a little complicated because of writing and saving files so it probably should be thread safe. also minecraft doesn't reload its resources automaticaly, so if you want the game to access these files, you need to reload resources beforehand

patent pier
fresh burrow
#

why? they're embedded into your mods jar after compilation

patent pier
#

I have a world preset you can customise in a similar fashion to flat world customisation

#

There are some inbuilt presets, like super flat, that are stored as json and loaded as a resource thingy

#

Wanted to add functionality for users to save their own presets

gusty girder
#

In this case, you'd want to store a config file to hold your custom presets

gusty girder
#

nope. You are free to store/read the config file however you want

#

If you want to follow a doc, there are plenty of config mods to choose from

patent pier
#

Oh right, but where do I write them / read too is the main thing.

fresh burrow
#

fabric loader has a method for getting the config dir

#

you can just FabricLoader.getInstance().getConfigDir().resolve("mymod.json")

patent pier
#

Awesome I’ll check that out

fresh burrow
#

and the easiest way to serialize/deserialize it would be to just have a config class and using gson's serializer

patent pier
#

Could I put json files in the config directory and use the same codecs I’ve been using for the built in presets

fresh burrow
#

yes

patent pier
#

Thanks

patent pier
fresh burrow
#

it depends, resource loaders only allow people to add stuff using datapacks and using a config doesn't require using datapacks

patent pier
#

is there any advantages to these locations over a config

fallen anvil