How to install mods for the new Minecraft launcher

I've recently changed to the new Minecraft launcher, and I have noticed a change in the .minecraft folder layout. I can no longer install mods just by copying it over into the versions/1.6.1 jar file, as this file refreshes every time it is launched.

For those who don't know what I am talking about, here is the new layout:

New minecraft folder layout.

I am specifically trying to install Optifine, which does work with 1.6.1. Where do I drag in the mod files now? I can't seem to find a jar file that is suited to it, except in the version folder, but as I stated above, this refreshes every time.

After copying a recent version and renaming it in the version folder, I get this error in the development console:

Unexpected exception refreshing version list
java.lang.IllegalArgumentException: Version '1.6.1' is already tracked
    at net.minecraft.launcher.updater.VersionList.addVersion(VersionList.java:91)
    at net.minecraft.launcher.updater.LocalVersionList.refreshVersions(LocalVersionList.java:44)
    at net.minecraft.launcher.updater.VersionManager.refreshVersions(VersionManager.java:47)
    at net.minecraft.launcher.Launcher$2.run(Launcher.java:164)
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
    at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

Solution 1:

There doesn't seem to be any official way. Then again, modding the game by splaying open and modifying the internals of the .jar file was never really officially supported, either. The new launcher is, ultimately, part of a rather large series of changes to Minecraft, including making mods actually something the game supports via the new Resource Pack stuff, but until that time, modding is a bit more awkward.

However, there's still a way to do it. Go into the versions folder inside .minecraft, and copy the version you want to mod. Rename the copied folder, and both the files inside, to some new name, say "modded 1.blah". Lastly, open the .json file in a text editor, and change the line that will read something like "id": "1.6.1", so that the ID matches the new name. The new launcher should now show a version "modded 1.blah" in the list, but since that version doesn't exist on the Minecraft servers, it won't get overwritten. Splay open and tinker with the .jar file in there the same way you always would with the old launcher.

Note:
If you are using the new launcher with an older version of Minecraft, then the mods you are using may attempt to access files in the bin folder directly. If this is the case, you can simply create a folder named 'bin' in the .minecraft folder where they are looking for it, and add the files the mod needs in there. The mod should find the files, and carry on as it used to, not knowing the difference.

Solution 2:

If you're willing to download MagicLauncher in addition to your regular launcher, it supports the original <1.6 way of installing mods. Just copy the mod files into the .jar, and MagicLauncher won't overwrite it. You now only need the official launcher to get new releases.

Solution 3:

Seeing as none of the answers so far have covered this, it is now possible to do it. For a long while now, APIs such as Forge have transitioned to the new layout for quite some time now, and Forge especially has its own installer that you can use to automatically drop a modified .jar archive already prepared to be used.

The universal-OS installer (used since 1.6 Forge) looks something like this.

Mod system installer: options to set installation directory and to install client or server API or to simply extract it are also included.