Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

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/

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.

  • Author

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/

  • Author

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/

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 :) !

  • Author

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.