Minecraft – Change game directory of Minecraft instance with Forge

minecraft-forgeminecraft-java-editionmods

I would like to make a Minecraft modpack using Minecraft Forge, most likely in Minecraft versions 1.5.2 and older, without using the new Minecraft launcher, since I will be making my own (not cracked, of course). I need it to run the modded Minecraft out of an entirely separate directory from normal Minecraft (Like Tekkit, which runs in %APPDATA%\.technic\ instead of %APPDATA%\.minecraft\). Unfortunately, the only way I know of to do this would be to change the %APPDATA% variable on the modpack startup and then restore it to its original value after exiting. This would mean that I cannot have multiple instances of the modpack or Minecraft running at the same time without causing problems with file access and saving. I have also looked at the source code for some modpack launchers, but most of them seem to use some sort of obscure launch method that is inherent in Java or Forge, or so it seems.

Is there a way in Java, Batch scripting, Forge config, or otherwise, that I can launch my modded Minecraft in a certain directory without changing my %APPDATA% environment variable globally?

Best Answer

You actually can use a batch file to change %AppData%. In a batch file, changing %AppData% is not global; it only applies to the commands in that batch file. (It would be a massive security hole otherwise!) So if you want to go that route and use a batch file, you seem to already know how to do that and you don't have to let worries about global environment changes stop you. For multiple instances simultaneously, use multiple batch files with different %AppData% settings.

I use this method to keep my and my kid's Minecraft installs completely separate, so that our profiles, worlds, and even jar versions are inaccessible from the other's launcher.


Alternatively, if using the new launcher is an option, this is easily done within the profile settings. I detail the method in this answer on a question about keeping different game versions' worlds separate. That's exactly the method I use myself for keeping multiple different Forge-based modpacks separate.

The two methods can be combined for even finer control over world separation, if that is relevant to your use-case.