Jump to content
  • 0

How to get working directory of technic pack folder within a mod?


Question

Posted

I'm trying to make a mod, and I'm trying to create a text file as a log file to help me develop it, but if I set the .techniclauncher/technicssp folder to be not read-only, the launcher just makes it read-only again, so I'm not able to create the file.

How can I disable this behaviour?

EDIT: Seems the problem is actually that the working directory is set not to the technicssp folder but to the directory the launcher is in. I need to find a way to get the path to the minecraft folder so I can read multiple mods' config files there.

EDIT AGAIN: For the edification of future generations, here's some code that works. I don't like that this is rather a hack, but it may actually be the most portable and reliable way to do it cross-OS. (Thank you, StackExchange.)

import java.net.URLDecoder ;



public class mod_Whatever extends BaseMod

{

	public static String BaseWorkingPath ;



	@Override

	public void load ( )

	{

		try

		{

			BaseWorkingPath = net.minecraft.client.Minecraft . class . getProtectionDomain ( ) . getCodeSource ( ) . getLocation ( ) . getPath ( ) ;

			BaseWorkingPath = URLDecoder . decode ( BaseWorkingPath , "UTF-8" ) ;

			BaseWorkingPath = BaseWorkingPath . substring ( 0 , BaseWorkingPath . lastIndexOf ( '/' ) ) ;

			BaseWorkingPath = BaseWorkingPath . substring ( 0 , BaseWorkingPath . lastIndexOf ( '/' ) + 1 ) ;

		}

		catch ( UnsupportedEncodingException e )

		{

			e . printStackTrace ( ) ;

		}

	}

}

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  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.

×
×
  • Create New...