jabelar Posted April 24, 2014 Posted April 24, 2014 Okay, I want do do some file manipulation in my mod. I generally understand file operations, but have a question specific to Minecraft modding -- what is best way to specify the file path such that I can use it in dev environment but it will also be available in my published mod? ResourceLocations obviously seem like the right thing, since it provides a mod-specific relative path to various non-code file assets. However, I wasn't sure how to use the ResourceLocation to create a Java File object. Or more specifically, maybe if I new how relative paths in File object map into the assets folder path. I'd love to be able to do something like File myFile = new File(ResourceLocation) but I think I need some method to transform ResourceLocationinto a relative path string for File constructor. Any tips? Quote Check out my tutorials here: http://jabelarminecraft.blogspot.com/
beaucoralk Posted April 24, 2014 Posted April 24, 2014 Hello jabelar, Maybe u can use the class Configuration into the package net.minecraftforge.common.config to create a configuration ressource file for your mod. It's a realy great idea for do what u want. Quote
jabelar Posted April 24, 2014 Author Posted April 24, 2014 Hello jabelar, Maybe u can use the class Configuration into the package net.minecraftforge.common.config to create a configuration ressource file for your mod. It's a realy great idea for do what u want. Thanks. That is actually what I want to do -- but my problem is when you create a Configuration you need to pass it a file. Most examples for Configuration pass a file using suggestedConfigFile for the path and then they create the file from within the executing code with a config.save() method. However, I want to be able to place a pre-made file in some assets directory where edit it externally and only load it (not save it). So I need to know how to create a File instance that points to the path of my file so I can pass it to the Configuration. I suspect I can use the path variables within the ResourceLocation, but I'm not entirely confident I'm not sure they are proper relative paths (i.e. can I use them as is) or whether I need to prepend or trim something from the path string. I'll probably play around with it more when I'm at a computer with my development environment, but was hoping that someone might have experience on the simple question -- how can I create a File with a reference the relative path to my assets folder (and is ResourceLocation a good way to do it). Quote Check out my tutorials here: http://jabelarminecraft.blogspot.com/
jabelar Posted April 24, 2014 Author Posted April 24, 2014 Actually I guess I really just want an answer to a simple question: what is proper relative path to my assets folder? If I had a file called my_file.txt in /assets/configurations/ then what would I put in my new File path argument: File myFile = new File("/configurations/my_file.txt"); or File myFile = new File("/assets/configurations/my_file.txt"); Or what? Quote Check out my tutorials here: http://jabelarminecraft.blogspot.com/
beaucoralk Posted April 24, 2014 Posted April 24, 2014 U will love me !! I found ! U need to use the ResourceManager of minecraft, to get a InputStream of your file who is into your assets folder. See this code (He get the file "txt/test.cfg" into my mod assets folder) and print it into out console : https://gist.github.com/beaucoralk/11269058 Now... u can use this InputStream to parse all file ! Quote
jabelar Posted April 24, 2014 Author Posted April 24, 2014 U will love me !! I found ! U need to use the ResourceManager of minecraft, to get a InputStream of your file who is into your assets folder. See this code (He get the file "txt/test.cfg" into my mod assets folder) and print it into out console : https://gist.github.com/beaucoralk/11269058 Now... u can use this InputStream to parse all file ! Thanks. I do love you! The IResource class is what I was missing, that will do what I want. Thanks! Quote Check out my tutorials here: http://jabelarminecraft.blogspot.com/
Recommended Posts
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.