Ninlives / minecraft.nix

Command line Minecraft launcher managed by nix
42 stars 8 forks source link

Auto determine java version #27

Closed linyinfeng closed 2 months ago

linyinfeng commented 2 months ago

v1_21.vanilla is broken because Minecraft 1.21 requires Java 21.

$ nix run github:ninlives/minecraft.nix#v1_21.vanilla.client
Run launch script snippet 'parseArgs'
Run launch script snippet 'parseRunnerArgs'
Run launch script snippet 'auth'
Successfully authenticated.
Run launch script snippet 'enterWorkingDirectory'
Run launch script snippet 'linkFiles'
Run launch script snippet 'gameExecution'
Error: LinkageError occurred while loading main class net.minecraft.client.main.Main
        java.lang.UnsupportedClassVersionError: net/minecraft/client/main/Main has been compiled by a more recent version of the Java Runtime (class file version 65.0), this version of the Java Runtime only recognizes class file versions up to 61.0

Since the Minecraft JSON file provides javaVersion.majorVersion, we can set the Java path based on the file.

Result:

$ nix path-info .#v1_8_9.vanilla.client --recursive --derivation | grep openjdk
/nix/store/z88zslkdx3rcyl4rjylksqp6s98hmlgz-adoptopenjdk-hotspot-bin-8.0.372.drv
/nix/store/2rp7m6mpc5q6mz1wfjawd965rl2xdibp-openjdk-8u412-ga.drv
$ nix path-info .#v1_20.vanilla.client --recursive --derivation | grep openjdk
/nix/store/w560wzxxxgxvcrvlwvzl3802c058prs1-adoptopenjdk-hotspot-bin-17.0.7.drv
/nix/store/n2764w76s5crfqpkdqd1qsmvf1gha9kr-openjdk-17.0.11+9.drv
$ nix path-info .#v1_21.vanilla.client --recursive --derivation | grep openjdk
/nix/store/s6ymvqbskp57a2zdy4ygnk2kfvj3jn3s-openjdk-21+35.drv
$ nix path-info .#v13w36a.vanilla.client --recursive --derivation | grep openjdk
trace: warning: Java version is not specified by the Minecraft json file, or
the specified version of OpenJDK is not supported by the Nixpkgs.
Fallback to '/nix/store/bk3x3ia7gxqic1jgr3dz05gwi8zw671y-openjdk-21+35'.

/nix/store/s6ymvqbskp57a2zdy4ygnk2kfvj3jn3s-openjdk-21+35.drv
Ninlives commented 2 months ago

So the older versions will default to the default openjdk in nixpkgs now, will it break anything?

linyinfeng commented 2 months ago

So the older versions will default to the default openjdk in nixpkgs now, will it break anything?

I did some tests and it seems that it breaks nothing.

Only these versions in minecraft.json trigger fallback.

$ cd vanilla/versions
$ versions=$( for f in *; do if [ "$(jq '.javaVersion.majorVersion' "$f")" = "null" ]; then echo "$f"; fi; done )
$ echo "${versions[@]}"
20116297638f7c70cd046e25a6ac90fee4cae61a.json
2f33c613a4bb81ef5f56be03a8f578208ada382a.json
4a538e23057a596fc8c7e04d8a7738d866467f51.json
65c0e5fff89b477ac6f8ddb336f0e718d525d311.json
6f426be1993b140ab5d10459c91eb1f542d58c82.json
74666ab85cc5539f08aec638eabd63a552ed4125.json
7fd8e0c76f62813eb0465e31bb74b160c01472d6.json
8b7870ddd0d0b38779479ad782d65ad80e688cf7.json
903d6ba1bc87c301d88fa418f8b33446201c7d4e.json
934788bc580ef0a19725ee5bd31f02a0b866e0bf.json
a9e87e0699f19fea280878f5deb744c5d5d3ccb1.json
b349702aef5e3adaebec30c79338300423943930.json
b71bae449192fbbe1582ff32fb3765edf0b9b0a8.json
b8d28154ee056af6af3c8c37815418fe0e9f34f8.json
bc915c4dc167dfba92fcc0ae3aa051ae0f9f089b.json
c0729761bf65dc58138ce508645dba1442fa78b8.json
e1294b52803771cfb06767c4c40dced70475cb25.json
e6dc1d9f9c8efeec67af438d5bf61be082f6e8a4.json
$ for f in ${versions[@]}; do jq '.id' "$f" --raw-output; done | sort
13w24a
13w24b
13w25a
13w25b
13w25c
13w26a
13w36a
13w36b
13w37a
13w37b
13w38a
13w38b
13w38c
1.6
1.6.1
1.6.2
1.6.3
1.6.4

It surprised me that both 1.6 and 13w24a started successfully with OpenJDK 21...

image