Posted April 21, 201411 yr Hello all, I need to get the direct location of a mods assets folder on the user's computer. I know that Minecraft.getMinecraft().mcDataDir will get where minecraft is located, however i'm not sure to get the assets of mod as well. Any help would be appreciated, thanks. Here is my method that needs it, in case you where wondering. It is supposed to return all the textures in a folder. /** * Returns all of the textures with the material prefix and the type in an array. used for metadata material blocks * @param matPrefix * @param type * @return */ public static String[] getMaterialStringArray(String id, String matPrefix, String type) { List<String> textures = new ArrayList<>(); try { String path = new ResourceLocation("extradecor:/textures/blocks/stoneCutter/").getResourcePath(); File textureDir = new File(path); for(int i = 0; i < textureDir.list().length; i++) { if(textureDir.list()[i].startsWith(matPrefix + "_" + type)) { textures.add(id + ":/stoneCutter/" + textureDir.list()[i].replaceAll(".png", "")); } } } catch(Exception e) { } //convert the list to an array String[] result = new String[textures.size()]; for(int i = 0; i < textures.size(); i++) { result[i] = textures.get(i); } return result; }
April 21, 201411 yr I don't have any source code to look in since my external hard drive is gone right now, but I think there's a method in ResourceLocation to get the file directory of the current resource. Kain
April 21, 201411 yr Author I don't have any source code to look in since my external hard drive is gone right now, but I think there's a method in ResourceLocation to get the file directory of the current resource. Nope, that only returns the end part of it View my post above, as i edited it.
April 21, 201411 yr Hi This link should help http://www.minecraftforge.net/forum/index.php/topic,11963.0.html -TGG
April 21, 201411 yr Author Hi This link should help http://www.minecraftforge.net/forum/index.php/topic,11963.0.html -TGG I'm a bit confused, I'm not sure how this applies to my code. Also, It might work in the eclipse environment, but come build time and run it in your minecraft and it won't work.
April 21, 201411 yr Hi Sorry, I should have been a bit clearer; what I meant was that you can use that as a starting point to figure out where the directory is coming from. To be honest I don't know exactly the answer to your question. The following is based on 1.6.4 but I imagine it's similar for 1.7.2 The base path is stored in the FolderResourcePack or the FileResourcePack depending on whether your assets are in a directory or in a zip. So you need to find the file that is passed to their constructor. If you put a breakpoint in the constructor, you should be able to trace back to the caller and hopefully figure out where the base path is coming from, or alternatively a way for you to access it. (It looks to me like they are contained in ResourcePackRepository, which gives you access to getDirResourcepacks and getResourcePackFiles() from Minecraft.getMinecraft().getResourcePackRepository, but I'm not sure exactly how forge inserts your mod packs into that.) -TGG
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.