From 3ea69265b89aa069a9ee6567f46a04fe9178e317 Mon Sep 17 00:00:00 2001 From: Ryan Dowling Date: Sun, 13 Aug 2023 22:39:10 +1000 Subject: [PATCH] feat: support NeoForge loader for Modrinth and MultiMC import --- CHANGELOG.md | 6 +-- .../java/com/atlauncher/data/Instance.java | 24 +++++++-- .../data/minecraft/loaders/LoaderVersion.java | 4 ++ .../gui/dialogs/InstanceInstallerDialog.java | 4 +- .../atlauncher/workers/InstanceInstaller.java | 52 ++++++++++++++++++- src/main/resources/version | 2 +- 6 files changed, 83 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 19a77302..195e936a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,11 +6,11 @@ This changelog only contains the changes that are unreleased. For changes for in ## 3.4.31.3 ### New Features - - Servers will now be started using kitty, allacritty or gnome-terminal, if x-terminal-emulator or exo-open aren't present -- Rename "Vanilla Packs" to "Create Pack" +- Support NeoForge loader for Modrinth and MultiMC import ### Fixes ### Misc -- Organize ViewModels \ No newline at end of file +- Organize ViewModels +- Rename "Vanilla Packs" to "Create Pack" \ No newline at end of file diff --git a/src/main/java/com/atlauncher/data/Instance.java b/src/main/java/com/atlauncher/data/Instance.java index 90dbc5d0..c7c17055 100644 --- a/src/main/java/com/atlauncher/data/Instance.java +++ b/src/main/java/com/atlauncher/data/Instance.java @@ -1798,7 +1798,7 @@ public class Instance extends MinecraftVersion { manifest.components.add(minecraftComponent); // fabric loader - if (launcher.loaderVersion.type.equals("Fabric") || launcher.loaderVersion.type.equals("LegacyFabric")) { + if (launcher.loaderVersion.isFabric() || launcher.loaderVersion.isLegacyFabric()) { // mappings MultiMCComponent fabricMappingsComponent = new MultiMCComponent(); fabricMappingsComponent.cachedName = "Intermediary Mappings"; @@ -1832,7 +1832,25 @@ public class Instance extends MinecraftVersion { } // forge loader - if (launcher.loaderVersion.type.equals("Forge")) { + if (launcher.loaderVersion.isNeoForge()) { + // loader + MultiMCComponent forgeMappingsComponent = new MultiMCComponent(); + forgeMappingsComponent.cachedName = "Forge"; + + forgeMappingsComponent.cachedRequires = new ArrayList<>(); + MultiMCRequire minecraftRequire = new MultiMCRequire(); + minecraftRequire.equals = id; + minecraftRequire.uid = "net.minecraft"; + forgeMappingsComponent.cachedRequires.add(minecraftRequire); + + forgeMappingsComponent.cachedVersion = launcher.loaderVersion.version; + forgeMappingsComponent.uid = "net.neoforged"; + forgeMappingsComponent.version = launcher.loaderVersion.version; + manifest.components.add(forgeMappingsComponent); + } + + // forge loader + if (launcher.loaderVersion.isForge()) { // loader MultiMCComponent forgeMappingsComponent = new MultiMCComponent(); forgeMappingsComponent.cachedName = "Forge"; @@ -1850,7 +1868,7 @@ public class Instance extends MinecraftVersion { } // quilt loader - if (launcher.loaderVersion.type.equals("Quilt")) { + if (launcher.loaderVersion.isQuilt()) { String hashedName = "org.quiltmc.hashed"; String cachedName = "Hashed Mappings"; if (ConfigManager.getConfigItem("loaders.quilt.switchHashedForIntermediary", true) == false) { diff --git a/src/main/java/com/atlauncher/data/minecraft/loaders/LoaderVersion.java b/src/main/java/com/atlauncher/data/minecraft/loaders/LoaderVersion.java index 15dcf0c4..5d692a3c 100644 --- a/src/main/java/com/atlauncher/data/minecraft/loaders/LoaderVersion.java +++ b/src/main/java/com/atlauncher/data/minecraft/loaders/LoaderVersion.java @@ -128,6 +128,10 @@ public class LoaderVersion { return "quilt-loader"; } + if (this.isNeoForge()) { + return "neoforge"; + } + return "forge"; } diff --git a/src/main/java/com/atlauncher/gui/dialogs/InstanceInstallerDialog.java b/src/main/java/com/atlauncher/gui/dialogs/InstanceInstallerDialog.java index ffbc03da..c7e57073 100644 --- a/src/main/java/com/atlauncher/gui/dialogs/InstanceInstallerDialog.java +++ b/src/main/java/com/atlauncher/gui/dialogs/InstanceInstallerDialog.java @@ -776,6 +776,7 @@ public class InstanceInstallerDialog extends JDialog { packVersion.hasLoader = modrinthManifest.dependencies.containsKey("fabric-loader") || modrinthManifest.dependencies.containsKey("quilt-loader") + || modrinthManifest.dependencies.containsKey("neoforge") || modrinthManifest.dependencies.containsKey("forge"); pack.versions = Collections.singletonList(packVersion); @@ -812,7 +813,8 @@ public class InstanceInstallerDialog extends JDialog { } packVersion.hasLoader = multiMCManifest.components.stream() - .anyMatch(c -> c.uid.equalsIgnoreCase("net.minecraftforge") + .anyMatch(c -> c.uid.equalsIgnoreCase("net.neoforged") + || c.uid.equalsIgnoreCase("net.minecraftforge") || c.uid.equalsIgnoreCase("net.fabricmc.hashed")); pack.versions = Collections.singletonList(packVersion); diff --git a/src/main/java/com/atlauncher/workers/InstanceInstaller.java b/src/main/java/com/atlauncher/workers/InstanceInstaller.java index 3d7d28a5..724bbb7d 100644 --- a/src/main/java/com/atlauncher/workers/InstanceInstaller.java +++ b/src/main/java/com/atlauncher/workers/InstanceInstaller.java @@ -117,6 +117,7 @@ import com.atlauncher.data.technic.TechnicModpackAsset; import com.atlauncher.data.technic.TechnicSolderModpackManifest; import com.atlauncher.exceptions.LocalException; import com.atlauncher.graphql.GetForgeLoaderVersionQuery; +import com.atlauncher.graphql.GetNeoForgeLoaderVersionQuery; import com.atlauncher.gui.dialogs.BrowserDownloadDialog; import com.atlauncher.interfaces.NetworkProgressable; import com.atlauncher.managers.ConfigManager; @@ -1620,6 +1621,7 @@ public class InstanceInstaller extends SwingWorker implements Net if (modrinthManifest.dependencies.containsKey("fabric-loader") || modrinthManifest.dependencies.containsKey("quilt-loader") + || modrinthManifest.dependencies.containsKey("neoforge") || modrinthManifest.dependencies.containsKey("forge")) { packVersion.loader = new com.atlauncher.data.json.Loader(); @@ -1641,6 +1643,29 @@ public class InstanceInstaller extends SwingWorker implements Net loaderMeta.put("loader", modrinthManifest.dependencies.get("quilt-loader")); packVersion.loader.metadata = loaderMeta; packVersion.loader.className = "com.atlauncher.data.minecraft.loaders.quilt.QuiltLoader"; + } else if (modrinthManifest.dependencies.containsKey("neoforge")) { + String neoForgeVersionString = modrinthManifest.dependencies.get("neoforge"); + + if (ConfigManager.getConfigItem("useGraphql.loaderVersions", false) == false) { + throw new Exception( + "Failed to find loader version for " + neoForgeVersionString + " as GraphQL is disabled"); + } + + GetNeoForgeLoaderVersionQuery.Data response = GraphqlClient + .callAndWait(new GetNeoForgeLoaderVersionQuery(neoForgeVersionString)); + + if (response == null || response.neoForgeVersion() == null) { + throw new Exception("Failed to find loader version for " + neoForgeVersionString); + } + + Map loaderMeta = new HashMap<>(); + loaderMeta.put("minecraft", packVersion.minecraft); + + loaderMeta.put("version", response.neoForgeVersion().version()); + loaderMeta.put("rawVersion", response.neoForgeVersion().rawVersion()); + + packVersion.loader.metadata = loaderMeta; + packVersion.loader.className = "com.atlauncher.data.minecraft.loaders.neoforge.NeoForgeLoader"; } else if (modrinthManifest.dependencies.containsKey("forge")) { String forgeVersionString = modrinthManifest.dependencies.get("forge"); @@ -1756,6 +1781,8 @@ public class InstanceInstaller extends SwingWorker implements Net packVersion.loader = new com.atlauncher.data.json.Loader(); + MultiMCComponent neoForgedComponent = multiMCManifest.components.stream() + .filter(c -> c.uid.equalsIgnoreCase("net.neoforged")).findFirst().orElse(null); MultiMCComponent forgeComponent = multiMCManifest.components.stream() .filter(c -> c.uid.equalsIgnoreCase("net.minecraftforge")).findFirst().orElse(null); MultiMCComponent fabricLoaderComponent = multiMCManifest.components.stream() @@ -1763,7 +1790,30 @@ public class InstanceInstaller extends SwingWorker implements Net MultiMCComponent quiltLoaderComponent = multiMCManifest.components.stream() .filter(c -> c.uid.equalsIgnoreCase("org.quiltmc.quilt-loader")).findFirst().orElse(null); - if (forgeComponent != null) { + if (neoForgedComponent != null) { + String neoForgeVersionString = neoForgedComponent.version; + + if (ConfigManager.getConfigItem("useGraphql.loaderVersions", false) == false) { + throw new Exception( + "Failed to find loader version for " + neoForgeVersionString + " as GraphQL is disabled"); + } + + GetNeoForgeLoaderVersionQuery.Data response = GraphqlClient + .callAndWait(new GetNeoForgeLoaderVersionQuery(neoForgeVersionString)); + + if (response == null || response.neoForgeVersion() == null) { + throw new Exception("Failed to find loader version for " + neoForgeVersionString); + } + + Map loaderMeta = new HashMap<>(); + loaderMeta.put("minecraft", minecraftVersion); + + loaderMeta.put("version", response.neoForgeVersion().version()); + loaderMeta.put("rawVersion", response.neoForgeVersion().rawVersion()); + + packVersion.loader.metadata = loaderMeta; + packVersion.loader.className = "com.atlauncher.data.minecraft.loaders.neoforge.NeoForgeLoader"; + } else if (forgeComponent != null) { String forgeVersionString = forgeComponent.version; if (ConfigManager.getConfigItem("useGraphql.loaderVersions", false) == true) { diff --git a/src/main/resources/version b/src/main/resources/version index b852430c..ac18a41f 100644 --- a/src/main/resources/version +++ b/src/main/resources/version @@ -1 +1 @@ -3.4.31.3.Beta +3.4.32.0.Beta