Automatically detect the MC version for an instance
By looking at the minecraft.jar or server.jar we should be able to determine the MC version that is in use, hopefully... That way, the user doesn't have to explicitly set the MC version for each instance.
not sure how you plan on doing this but just wanted to give some input. It seems like minecraft launchers handle the naming of the minecraft.jar differently. the official launcher names it X.XX.X.jar, multimc uses minecraft-X.XX.X-client.jar and I bet the other launchers also do it differently. on top of that these files are located in different places as well
packed inside both these .jar files is a version.json which should have enough info
{
"id": "1.17.1",
"name": "1.17.1",
"release_target": "1.17.1",
"world_version": 2730,
"protocol_version": 756,
"pack_version": {
"resource": 7,
"data": 7
},
"build_time": "2021-07-06T11:59:45+00:00",
"java_component": "java-runtime-alpha",
"java_version": 16,
"stable": true
}
Thanks @theofficialgman 🙂
I had a hunch there might be some information inside the .jar, but I wasn't sure. So thanks for confirming 😃
I have to look into snapshots and server versions as well to see which one of id, name, or release_target should be used. It's also nice that there seems to be a stable flag, not sure if there will be any use of this, but maybe in the future.
I should also note that multimc dumps all the minecraft-X.XX.X-client.jar files into its own folder structure libraries/com/mojang/minecraft/22w18a/minecraft-22w18a-client.jar separate from the .minecraft folder. so you can't really read from that since you don't know where it is.
a launcher specific way for multimc is just reading the mmc-pack.json where you can get the minecraft version and fabric/forge version if they are installed.
mc_version=$(jq -M -r '.components[] | "\(.uid)/\(.version)"' mmc-pack.json | sed -n -e 's/^.*net.minecraft\///p')
fabric_version=$(jq -M -r '.components[] | "\(.uid)/\(.version)"' mmc-pack.json | sed -n -e 's/^.*net.fabricmc.fabric-loader\///p')
forge_version=$(jq -M -r '.components[] | "\(.uid)/\(.version)"' mmc-pack.json | sed -n -e 's/^.*net.minecraftforge\///p')