Minecraft – Finding the current installation of minecraft

minecraft-java-edition

Am trying to figure out where to look for finding out the current version of minecraft installed my pc. I can see the current version, if I open up the Minecraft.exe launcher.

enter image description here

I tried to search in Windows Registry to see if there is any entry regarding the current version. But didn't found any when I searched for the term minecraft. And I can see that, this folder C:\Users\USERNAME\AppData\Roaming\.minecraft\versions contains the sub-folder 1.7.4 which is the current version!

So, is that the only place we can check to find out the current version?

I am trying to fetch the version via code (creating VB.Net app). I can do a scan for the sub-folders in the ..\.minecraft\versions folder and could find out the version number. But what if that versions folder contains another folder say 1.8.2 with a JAR and JSON file? My idea of fetching the current version would fail then! Because the versions folder contains two folders 1.7.4 (which is the current version) and the 1.8.2 (which is a duplicate of the contents of the folder 1.7.4, I created for testing). In my code, it would find out the current version as 1.8.2, which would be wrong! Because when the MC launcher is opened, it still shows the 1.7.4 as the current version!

So, what would be the effective way/place to look for finding the currently installed version? Any hints would be highly appreciated.

Thank you

Best Answer

I just checked the launcher and this is how it does it:

It loads .minecraft\launcher_profiles.json and looks at "selectedProfile":

  {
    "profiles": {
      "1.6.4": {
        "name": "1.6.4",
        "lastVersionId": "1.6.4",
        "playerUUID": "---"
      },
      "default": {
        "name": "default",
        "playerUUID": "---",
        "launcherVisibilityOnGameClose": "close launcher when game starts"
      }
    },
    "selectedProfile": "default",
    "clientToken": "---",
  }

Then it looks at the selected profile's lastVersionId and uses that version (e.g. 1.6.4). If there is no such attribute (as in the above example), it lists all versions from the versions folder, reads the json files and chooses the one with latest "releaseTime" attribute. It also filters the versions by "type" == "release" attribute (this filtering actually depends on the profile settings, but by default only "release" versions are considered).