diff --git a/MinecraftLaunch/Classes/Models/Game/GameEntry.cs b/MinecraftLaunch/Classes/Models/Game/GameEntry.cs index e6b2a1a..b7cdb71 100644 --- a/MinecraftLaunch/Classes/Models/Game/GameEntry.cs +++ b/MinecraftLaunch/Classes/Models/Game/GameEntry.cs @@ -8,6 +8,8 @@ public record GameEntry { public string Type { get; set; } + public int JavaVersion { get; set; } + public LoaderType MainLoaderType { get; set; } public bool IsVanilla { get; set; } diff --git a/MinecraftLaunch/Classes/Models/Game/GameJsonEntry.cs b/MinecraftLaunch/Classes/Models/Game/GameJsonEntry.cs index 5a764ed..2aacede 100644 --- a/MinecraftLaunch/Classes/Models/Game/GameJsonEntry.cs +++ b/MinecraftLaunch/Classes/Models/Game/GameJsonEntry.cs @@ -22,6 +22,9 @@ public record GameJsonEntry { [JsonPropertyName("assets")] public string Assets { get; set; } + [JsonPropertyName("javaVersion")] + public JsonNode JavaVersion { get; set; } + [JsonPropertyName("arguments")] public ArgumentsJsonEntry Arguments { get; set; } diff --git a/MinecraftLaunch/Components/Resolver/GameResolver.cs b/MinecraftLaunch/Components/Resolver/GameResolver.cs index 64feacf..6dcaf44 100644 --- a/MinecraftLaunch/Components/Resolver/GameResolver.cs +++ b/MinecraftLaunch/Components/Resolver/GameResolver.cs @@ -31,7 +31,8 @@ public GameEntry GetGameEntity(string id) { GameFolderPath = root, IsInheritedFrom = false, MainClass = entity.MainClass, - MainLoaderType = entity.GetGameLoaderType() + MainLoaderType = entity.GetGameLoaderType(), + JavaVersion = entity.JavaVersion.GetInt32("majorVersion"), }; var assetsIndexFile = Path.Combine(root, "assets", "indexes", $"{entity.AssetIndex?.Id}.json"); diff --git a/MinecraftLaunch/MinecraftLaunch.csproj b/MinecraftLaunch/MinecraftLaunch.csproj index 8de8574..e63339c 100644 --- a/MinecraftLaunch/MinecraftLaunch.csproj +++ b/MinecraftLaunch/MinecraftLaunch.csproj @@ -16,15 +16,14 @@ MinecraftLaunch disable - + - + + + - - True - - + diff --git a/MinecraftLaunch/Utilities/JavaUtil.cs b/MinecraftLaunch/Utilities/JavaUtil.cs index d784af8..107d52f 100644 --- a/MinecraftLaunch/Utilities/JavaUtil.cs +++ b/MinecraftLaunch/Utilities/JavaUtil.cs @@ -63,6 +63,18 @@ public static JavaEntry GetJavaInfo(string path) { } } + public static JavaEntry GetCurrentJava(IReadOnlyList javaEntries, GameEntry entry) { + var result = javaEntries.FirstOrDefault(x => x.Is64Bit && x.JavaSlugVersion == entry.JavaVersion) + ?? javaEntries.FirstOrDefault(x => x.JavaSlugVersion == entry.JavaVersion); + + if (result == null) { + throw new InvalidOperationException("No suitable Java found"); + } + + return result; + } + + [SupportedOSPlatform(nameof(OSPlatform.Windows))] private static bool GetIs64Bit(string path) { ushort architecture = 0;