#Walk the resource fs

9 messages · Page 1 of 1 (latest)

pale gate
#

I'm not entirely sure how to ask this but what I want to accomplish is I want to be able to read all the files from a specific folder in the resources folder.
And the goal is so that other resource packs and other mod's resource packs can be taken into account even without registering with each other in code.
Are there any examples of this I can be pointed towards?

Thanks for your time in advance.

frozen ridge
#

i think Files.list() works with Path obtained from ModContainer but idk i haven't tested this yet. you can get the path to mod resources by using ModContainer#findPath() and you can get ModContainer by using FabricLoader.getInstance().getModContainer()

pale gate
#

I'm checking out MinecraftClient.getInstance().resourceManager.findResources(path, predicate) if that doesn't pan out check that one, thanks!

frozen ridge
#

oh wait you also said resource packs and i didn't see that. i thought you just want to read content of resources folder of your mod

#

i think findResources is enough

pale gate
#

I still haven't figured out how to test it but yes it seems that way

pale gate
#

The findResources doesn't seem to work as well as I expected it to work. Unless I'm doing this wrong, which is very possible.
I mostly want other mod's to be able to place a json file in the same path as I am looking for it and have that file automatically loaded, creating mod compatibility without the need for code dependency.
And if other mods still don't add such a thing, it would be great if I just by having those json files in the correct path of resource packs I could still access them. Again creating the possibility of adding mod compatibly without any code or API or what have it.

If anyone has any suggestions what would be greatly appreciated!

frozen ridge
#

you might have a better chance at reading files with given path from all namespaces, something like findAllResources() with the predicate being id -> id.getPath().equals("my_mod/a.json") which will returns all files from assets/<namespace>/my_mod/a.json

#

though please note that assets is meant for client-side resources pack. if you want server-side resources (a.k.a datapack), you need to find a way to get ResourceManager for server. if you don't want to access files in assets or data then you might have to use ModContainer#findPath()