#Saving json data to folders in resources or data directory
28 messages · Page 1 of 1 (latest)
it is completly possible, tho there isn't much documentation about it. this article is from fabric's wiki: https://wiki.fabricmc.net/tutorial:custom_resources, but i would recommend checking other mods' source code and look at how the ydo this thing
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
do you know how i can programmatically get the folder path for the assets folder
why? they're embedded into your mods jar after compilation
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
This
In this case, you'd want to store a config file to hold your custom presets
Are there docs for this?
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
Oh right, but where do I write them / read too is the main thing.
fabric loader has a method for getting the config dir
you can just FabricLoader.getInstance().getConfigDir().resolve("mymod.json")
Awesome I’ll check that out
and the easiest way to serialize/deserialize it would be to just have a config class and using gson's serializer
Could I put json files in the config directory and use the same codecs I’ve been using for the built in presets
yes
https://github.com/Raik176/undertale-death-screen/blob/master/src/main/java/org/rhm/undertale_death_screen/Config.java for an example of a config using codecs
Thanks
Do you think i stick with resource loaders of for the built in presets or configs like this instead
it depends, resource loaders only allow people to add stuff using datapacks and using a config doesn't require using datapacks
I've got it working through a config, but now it hits me. Why do I need to do any of these presets through a custom resorucelistener (looking into assets/data folders)
is there any advantages to these locations over a config
Depends on the use case