1818package org .jackhuang .hmcl .mod .multimc ;
1919
2020import com .google .gson .annotations .SerializedName ;
21- import org .jackhuang .hmcl .game .Library ;
21+ import org .jackhuang .hmcl .game .* ;
2222import org .jackhuang .hmcl .util .Immutable ;
2323import org .jackhuang .hmcl .util .Lang ;
2424import org .jetbrains .annotations .Nullable ;
2525
26+ import java .util .ArrayList ;
27+ import java .util .Arrays ;
2628import java .util .Collections ;
2729import java .util .List ;
2830
@@ -35,6 +37,7 @@ public final class MultiMCInstancePatch {
3537 private final String name ;
3638 private final String version ;
3739 private final int order ;
40+ private final AssetIndexInfo assetIndex ;
3841
3942 private final String minecraftArguments ;
4043
@@ -63,10 +66,11 @@ public final class MultiMCInstancePatch {
6366 @ Nullable
6467 private final List <Library > jarMods ;
6568
66- public MultiMCInstancePatch (String name , String version , int order , String minecraftArguments , String gameVersion , String mainClass , int [] javaMajors , @ Nullable List <String > tweakers , @ Nullable List <String > jvmArgs , @ Nullable List <Library > _libraries , @ Nullable List <Library > libraries , @ Nullable List <Library > jarMods ) {
69+ public MultiMCInstancePatch (String name , String version , int order , AssetIndexInfo assetIndex , String minecraftArguments , String gameVersion , String mainClass , int [] javaMajors , @ Nullable List <String > tweakers , @ Nullable List <String > jvmArgs , @ Nullable List <Library > _libraries , @ Nullable List <Library > libraries , @ Nullable List <Library > jarMods ) {
6770 this .name = name ;
6871 this .version = version ;
6972 this .order = order ;
73+ this .assetIndex = assetIndex ;
7074 this .minecraftArguments = minecraftArguments ;
7175 this .gameVersion = gameVersion ;
7276 this .mainClass = mainClass ;
@@ -86,6 +90,10 @@ public String getVersion() {
8690 return version ;
8791 }
8892
93+ public AssetIndexInfo getAssetIndex () {
94+ return assetIndex ;
95+ }
96+
8997 public String getMinecraftArguments () {
9098 return minecraftArguments ;
9199 }
@@ -121,4 +129,38 @@ public List<Library> getLibraries() {
121129 public List <Library > getJarMods () {
122130 return jarMods != null ? Collections .unmodifiableList (jarMods ) : Collections .emptyList ();
123131 }
132+
133+ public Version asVersion (String patchID ) {
134+ List <String > arguments = new ArrayList <>();
135+ for (String arg : getTweakers ()) {
136+ arguments .add ("--tweakClass" );
137+ arguments .add (arg );
138+ }
139+
140+ Version version = new Version (patchID )
141+ .setVersion (getVersion ())
142+ .setArguments (new Arguments ().addGameArguments (arguments ).addJVMArguments (getJvmArgs ()))
143+ .setMainClass (getMainClass ())
144+ .setMinecraftArguments (getMinecraftArguments ())
145+ .setLibraries (getLibraries ())
146+ .setAssetIndex (getAssetIndex ());
147+
148+ /* TODO: Official Version Json can only store one GameJavaVersion, not a array of all suitable java versions.
149+ For compatibility with official launcher and any other launchers, a transform is made between int[] and GameJavaVersion. */
150+ int [] majors = getJavaMajors ();
151+ if (majors != null ) {
152+ majors = majors .clone ();
153+ Arrays .sort (majors );
154+
155+ for (int i = majors .length - 1 ; i >= 0 ; i --) {
156+ GameJavaVersion jv = GameJavaVersion .get (majors [i ]);
157+ if (jv != null ) {
158+ version = version .setJavaVersion (jv );
159+ break ;
160+ }
161+ }
162+ }
163+
164+ return version ;
165+ }
124166}
0 commit comments