Skip to content

Commit f1b006b

Browse files
authored
Implement support for NeoForge 20.2+ (ZekerZhayard#16)
Signed-off-by: Sefa Eyeoglu <contact@scrumplex.net>
1 parent d779606 commit f1b006b

3 files changed

Lines changed: 33 additions & 20 deletions

File tree

src/main/java/io/github/zekerzhayard/forgewrapper/installer/Main.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,31 @@
1515

1616
public class Main {
1717
public static void main(String[] args) throws Throwable {
18+
// --fml.neoForgeVersion 20.2.20-beta --fml.fmlVersion 1.0.2 --fml.mcVersion 1.20.2 --fml.neoFormVersion 20231019.002635 --launchTarget forgeclient
19+
1820
List<String> argsList = Stream.of(args).collect(Collectors.toList());
21+
// NOTE: this is only true for NeoForge versions past 20.2.x
22+
// early versions of NeoForge (for 1.20.1) are not supposed to be covered here
23+
boolean isNeoForge = argsList.contains("--fml.neoForgeVersion");
24+
1925
String mcVersion = argsList.get(argsList.indexOf("--fml.mcVersion") + 1);
2026
String forgeGroup = argsList.contains("--fml.forgeGroup") ? argsList.get(argsList.indexOf("--fml.forgeGroup") + 1) : "net.neoforged";
21-
String forgeVersion = argsList.get(argsList.indexOf("--fml.forgeVersion") + 1);
22-
String forgeFullVersion = mcVersion + "-" + forgeVersion;
27+
String forgeArtifact = isNeoForge ? "neoforge" : "forge";
28+
String forgeVersionKey = isNeoForge ? "--fml.neoForgeVersion" : "--fml.forgeVersion";
29+
String forgeVersion = argsList.get(argsList.indexOf(forgeVersionKey) + 1);
30+
String forgeFullVersion = isNeoForge ? forgeVersion : mcVersion + "-" + forgeVersion;
2331

2432
IFileDetector detector = DetectorLoader.loadDetector();
2533
try {
26-
Bootstrap.bootstrap(detector.getJvmArgs(forgeGroup, forgeFullVersion), detector.getMinecraftJar(mcVersion).getFileName().toString(), detector.getLibraryDir().toAbsolutePath().toString());
34+
Bootstrap.bootstrap(detector.getJvmArgs(forgeGroup, forgeArtifact, forgeFullVersion), detector.getMinecraftJar(mcVersion).getFileName().toString(), detector.getLibraryDir().toAbsolutePath().toString());
2735
} catch (Throwable ignored) {
2836
// Avoid this bunch of hacks that nuke the whole wrapper.
2937
}
30-
if (!detector.checkExtraFiles(forgeGroup, forgeFullVersion)) {
38+
if (!detector.checkExtraFiles(forgeGroup, forgeArtifact, forgeFullVersion)) {
3139
System.out.println("Some extra libraries are missing! Running the installer to generate them now.");
3240

3341
// Check installer jar.
34-
Path installerJar = detector.getInstallerJar(forgeGroup, forgeFullVersion);
42+
Path installerJar = detector.getInstallerJar(forgeGroup, forgeArtifact, forgeFullVersion);
3543
if (!IFileDetector.isFile(installerJar)) {
3644
throw new RuntimeException("Unable to detect the forge installer!");
3745
}
@@ -54,7 +62,7 @@ public static void main(String[] args) throws Throwable {
5462
}
5563
}
5664

57-
Class<?> mainClass = ModuleUtil.setupBootstrapLauncher(Class.forName(detector.getMainClass(forgeGroup, forgeFullVersion)));
65+
Class<?> mainClass = ModuleUtil.setupBootstrapLauncher(Class.forName(detector.getMainClass(forgeGroup, forgeArtifact, forgeFullVersion)));
5866
mainClass.getMethod("main", String[].class).invoke(null, new Object[] { args });
5967
}
6068
}

src/main/java/io/github/zekerzhayard/forgewrapper/installer/detector/IFileDetector.java

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,11 @@ default Path getLibraryDir() {
6262

6363
/**
6464
* @param forgeGroup Forge package group (e.g. net.minecraftforge).
65+
* @param forgeArtifact Forge package artifact (e.g. forge).
6566
* @param forgeFullVersion Forge full version (e.g. 1.14.4-28.2.0).
6667
* @return The forge installer jar path. It can also be defined by JVM argument "-Dforgewrapper.installer=&lt;installer-path&gt;".
6768
*/
68-
default Path getInstallerJar(String forgeGroup, String forgeFullVersion) {
69+
default Path getInstallerJar(String forgeGroup, String forgeArtifact, String forgeFullVersion) {
6970
String installer = System.getProperty("forgewrapper.installer");
7071
if (installer != null) {
7172
return Paths.get(installer).toAbsolutePath();
@@ -87,11 +88,12 @@ default Path getMinecraftJar(String mcVersion) {
8788

8889
/**
8990
* @param forgeGroup Forge package group (e.g. net.minecraftforge).
91+
* @param forgeArtifact Forge package artifact (e.g. forge).
9092
* @param forgeFullVersion Forge full version (e.g. 1.14.4-28.2.0).
9193
* @return The list of jvm args.
9294
*/
93-
default List<String> getJvmArgs(String forgeGroup, String forgeFullVersion) {
94-
return this.getDataFromInstaller(forgeGroup, forgeFullVersion, "version.json", e -> {
95+
default List<String> getJvmArgs(String forgeGroup, String forgeArtifact, String forgeFullVersion) {
96+
return this.getDataFromInstaller(forgeGroup, forgeArtifact, forgeFullVersion, "version.json", e -> {
9597
JsonElement element = getElement(e.getAsJsonObject().getAsJsonObject("arguments"), "jvm");
9698
List<String> args = new ArrayList<>();
9799
if (!element.equals(JsonNull.INSTANCE)) {
@@ -103,25 +105,27 @@ default List<String> getJvmArgs(String forgeGroup, String forgeFullVersion) {
103105

104106
/**
105107
* @param forgeGroup Forge package group (e.g. net.minecraftforge).
108+
* @param forgeArtifact Forge package artifact (e.g. forge).
106109
* @param forgeFullVersion Forge full version (e.g. 1.14.4-28.2.0).
107110
* @return The main class.
108111
*/
109-
default String getMainClass(String forgeGroup, String forgeFullVersion) {
110-
return this.getDataFromInstaller(forgeGroup, forgeFullVersion, "version.json", e -> e.getAsJsonObject().getAsJsonPrimitive("mainClass").getAsString());
112+
default String getMainClass(String forgeGroup, String forgeArtifact, String forgeFullVersion) {
113+
return this.getDataFromInstaller(forgeGroup, forgeArtifact, forgeFullVersion, "version.json", e -> e.getAsJsonObject().getAsJsonPrimitive("mainClass").getAsString());
111114
}
112115

113116
/**
114117
* @param forgeGroup Forge package group (e.g. net.minecraftforge).
118+
* @param forgeArtifact Forge package artifact (e.g. forge).
115119
* @param forgeFullVersion Forge full version (e.g. 1.14.4-28.2.0).
116120
* @return The json object in the-installer-jar-->install_profile.json-->data-->xxx-->client.
117121
*/
118-
default JsonObject getInstallProfileExtraData(String forgeGroup, String forgeFullVersion) {
119-
return this.getDataFromInstaller(forgeGroup, forgeFullVersion, "install_profile.json", e -> e.getAsJsonObject().getAsJsonObject("data"));
122+
default JsonObject getInstallProfileExtraData(String forgeGroup, String forgeArtifact, String forgeFullVersion) {
123+
return this.getDataFromInstaller(forgeGroup, forgeArtifact, forgeFullVersion, "install_profile.json", e -> e.getAsJsonObject().getAsJsonObject("data"));
120124
}
121125

122126
@SuppressWarnings("deprecation")
123-
default <R> R getDataFromInstaller(String forgeGroup, String forgeFullVersion, String entry, Function<JsonElement, R> function) {
124-
Path installer = this.getInstallerJar(forgeGroup, forgeFullVersion);
127+
default <R> R getDataFromInstaller(String forgeGroup, String forgeArtifact, String forgeFullVersion, String entry, Function<JsonElement, R> function) {
128+
Path installer = this.getInstallerJar(forgeGroup, forgeArtifact, forgeFullVersion);
125129
if (isFile(installer)) {
126130
try (ZipFile zf = new ZipFile(installer.toFile())) {
127131
ZipEntry ze = zf.getEntry(entry);
@@ -145,11 +149,12 @@ default <R> R getDataFromInstaller(String forgeGroup, String forgeFullVersion, S
145149
/**
146150
* Check all cached files.
147151
* @param forgeGroup Forge package group (e.g. net.minecraftforge).
152+
* @param forgeArtifact Forge package artifact (e.g. forge).
148153
* @param forgeFullVersion Forge full version (e.g. 1.14.4-28.2.0).
149154
* @return True represents all files are ready.
150155
*/
151-
default boolean checkExtraFiles(String forgeGroup, String forgeFullVersion) {
152-
JsonObject jo = this.getInstallProfileExtraData(forgeGroup, forgeFullVersion);
156+
default boolean checkExtraFiles(String forgeGroup, String forgeArtifact, String forgeFullVersion) {
157+
JsonObject jo = this.getInstallProfileExtraData(forgeGroup, forgeArtifact, forgeFullVersion);
153158
if (jo != null) {
154159
Map<String, Path> libsMap = new HashMap<>();
155160
Map<String, String> hashMap = new HashMap<>();

src/main/java/io/github/zekerzhayard/forgewrapper/installer/detector/MultiMCFileDetector.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ public Path getLibraryDir() {
2727
}
2828

2929
@Override
30-
public Path getInstallerJar(String forgeGroup, String forgeFullVersion) {
31-
Path path = IFileDetector.super.getInstallerJar(forgeGroup, forgeFullVersion);
30+
public Path getInstallerJar(String forgeGroup, String forgeArtifact, String forgeFullVersion) {
31+
Path path = IFileDetector.super.getInstallerJar(forgeGroup, forgeArtifact, forgeFullVersion);
3232
if (path == null) {
3333
if (this.installerJar == null) {
3434
Path installerBase = this.getLibraryDir();
3535
for (String dir : forgeGroup.split("\\."))
3636
installerBase = installerBase.resolve(dir);
37-
this.installerJar = installerBase.resolve("forge").resolve(forgeFullVersion).resolve("forge-" + forgeFullVersion + "-installer.jar").toAbsolutePath();
37+
this.installerJar = installerBase.resolve(forgeArtifact).resolve(forgeFullVersion).resolve(forgeArtifact + "-" + forgeFullVersion + "-installer.jar").toAbsolutePath();
3838
}
3939
return this.installerJar;
4040
}

0 commit comments

Comments
 (0)