Jump to content

Recommended Posts

Posted

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?

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

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.

Posted

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).

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

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?

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

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!

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.