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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...