Skip to content

Commit 3aeeada

Browse files
committedJul 22, 2021
Fix crash on launch with forge-1.16.5-36.1.66.
Add GitHub Actions.
1 parent 29f6029 commit 3aeeada

File tree

19 files changed

+375
-76
lines changed

19 files changed

+375
-76
lines changed
 

‎.github/workflows/build.yml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Gradle Build
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
jobs:
10+
build:
11+
runs-on: windows-latest
12+
13+
steps:
14+
- uses: actions/checkout@v2
15+
- name: Set up JDK
16+
uses: actions/setup-java@v1
17+
with:
18+
java-version: '8.0.302'
19+
architecture: x64
20+
- name: Build with Gradle
21+
run: ./gradlew.bat build -iS
22+
- uses: actions/upload-artifact@v2
23+
with:
24+
name: Package
25+
path: build/libs

‎.github/workflows/maven.bat

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
@ECHO OFF
2+
3+
git clone -b maven https://github.com/ZekerZhayard/ForgeWrapper.git .\maven
4+
5+
xcopy ".\build\maven\" ".\maven\" /S /Y
6+
cd ".\maven\"
7+
8+
git config --local user.name "GitHub Actions"
9+
git config --local user.email "actions@github.com"
10+
11+
git add .
12+
git commit -m "%GITHUB_SHA%"
13+
git push https://${GITHUB_TOKEN}@github.com/ZekerZhayard/ForgeWrapper.git maven

‎.github/workflows/publication.yml

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Publication
2+
3+
on:
4+
push:
5+
tags:
6+
- '*'
7+
8+
jobs:
9+
build:
10+
runs-on: windows-latest
11+
12+
steps:
13+
- uses: actions/checkout@v2
14+
- name: Set up JDK
15+
uses: actions/setup-java@v1
16+
with:
17+
java-version: '8.0.302'
18+
architecture: x64
19+
- name: Build with Gradle
20+
env:
21+
IS_PUBLICATION: true
22+
run: ./gradlew.bat publish -iS
23+
- uses: actions/upload-artifact@v2
24+
with:
25+
name: Package
26+
path: build/libs
27+
- name: Get tag version
28+
id: get_version
29+
uses: olegtarasov/get-tag@v2.1
30+
- uses: actions/upload-artifact@v2
31+
with:
32+
name: Package
33+
path: build/libs
34+
- name: Create Release
35+
id: create_release
36+
uses: actions/create-release@v1
37+
env:
38+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
39+
with:
40+
tag_name: ${{ steps.get_version.outputs.tag }}
41+
release_name: ${{ steps.get_version.outputs.tag }}
42+
body: ''
43+
draft: false
44+
prerelease: false
45+
- name: Upload release binaries
46+
uses: alexellis/upload-assets@0.2.2
47+
env:
48+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
49+
with:
50+
asset_paths: '["./build/libs/*"]'
51+
- name: Upload to Maven
52+
env:
53+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
54+
run: ./.github/workflows/maven.bat

‎build.gradle

+84-12
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,111 @@
1-
apply plugin: "base"
2-
apply plugin: "java"
3-
apply plugin: "eclipse"
4-
apply plugin: "idea"
1+
2+
plugins {
3+
id "java"
4+
id "eclipse"
5+
id "maven-publish"
6+
}
57

68
sourceCompatibility = targetCompatibility = 1.8
79

8-
version = "1.4.2"
10+
version = "${fw_version}${-> getVersionSuffix()}"
911
group = "io.github.zekerzhayard"
1012
archivesBaseName = rootProject.name
1113

14+
configurations {
15+
provided {
16+
compileOnly.extendsFrom provided
17+
}
18+
}
19+
1220
repositories {
21+
mavenCentral()
1322
maven {
1423
name = "forge"
15-
url = "https://files.minecraftforge.net/maven/"
24+
url = "https://maven.minecraftforge.net/"
1625
}
1726
}
1827

1928
dependencies {
20-
compile "cpw.mods:modlauncher:4.1.0"
21-
compile "net.minecraftforge:forge:1.14.4-28.2.0:installer"
29+
compileOnly "com.google.code.gson:gson:2.8.7"
30+
compileOnly "cpw.mods:modlauncher:8.0.9"
31+
compileOnly "net.minecraftforge:installer:2.1.4"
32+
compileOnly "net.sf.jopt-simple:jopt-simple:5.0.4"
33+
34+
provided project(":legacy")
35+
}
36+
37+
java {
38+
withSourcesJar()
2239
}
2340

2441
jar {
25-
manifest.attributes(
26-
"Main-Class": "io.github.zekerzhayard.forgewrapper.converter.Main"
27-
)
42+
manifest.attributes([
43+
"Specification-Title": "${project.name}",
44+
"Specification-Vendor": "ZekerZhayard",
45+
"Specification-Version": "${project.version}".split("-")[0],
46+
"Implementation-Title": "${project.name}",
47+
"Implementation-Version": "${project.version}",
48+
"Implementation-Vendor" :"ZekerZhayard",
49+
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"),
50+
"Automatic-Module-Name": "${project.group}.${project.archivesBaseName}".toString().toLowerCase(),
51+
"Main-Class": "io.github.zekerzhayard.forgewrapper.converter.Main",
52+
"GitCommit": String.valueOf(System.getenv("GITHUB_SHA"))
53+
])
54+
55+
from configurations.provided.files.collect {
56+
zipTree(it)
57+
}
58+
}
59+
60+
/*task sourcesJar(type: Jar) {
61+
manifest {
62+
attributes(jar.manifest.attributes)
63+
}
64+
from sourceSets.main.allSource
65+
archiveFileName = "${archivesBaseName}-${archiveVersion.get()}-sources.${archiveExtension.get()}"
2866
}
2967
68+
artifacts {
69+
archives sourcesJar
70+
}*/
71+
3072
processResources {
3173
inputs.property "version", project.version
3274
from(sourceSets.main.resources.srcDirs) {
75+
duplicatesStrategy = DuplicatesStrategy.INCLUDE
3376
include "patches/net.minecraftforge.json"
3477
expand "version": project.version
3578
}
3679
from(sourceSets.main.resources.srcDirs) {
80+
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
3781
exclude "patches/net.minecraftforge.json"
3882
}
39-
}
83+
}
84+
85+
publishing {
86+
publications {
87+
maven(MavenPublication) {
88+
groupId "${project.group}"
89+
artifactId "${project.archivesBaseName}"
90+
version "${project.version}"
91+
92+
from components.java
93+
}
94+
}
95+
repositories {
96+
maven {
97+
url = layout.buildDirectory.dir("maven")
98+
}
99+
}
100+
101+
}
102+
tasks.publish.dependsOn build
103+
104+
static String getVersionSuffix() {
105+
if (System.getenv("IS_PUBLICATION") != null) {
106+
return ""
107+
} else if (System.getenv("GITHUB_RUN_NUMBER") != null && System.getenv("GITHUB_SHA") != null) {
108+
return "-s." + System.getenv("GITHUB_RUN_NUMBER") + "-" + System.getenv("GITHUB_SHA").substring(0, 7)
109+
}
110+
return "-LOCAL"
111+
}

‎gradle.properties

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
org.gradle.daemon = false
3+
4+
fw_version = 1.5

‎gradle/wrapper/gradle-wrapper.jar

3.28 KB
Binary file not shown.
+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
#Thu Mar 12 20:06:29 CST 2020
21
distributionBase=GRADLE_USER_HOME
32
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-all.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-all.zip

‎gradlew

+34-21
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
#!/usr/bin/env sh
22

3+
#
4+
# Copyright 2015 the original author or authors.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# https://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
319
##############################################################################
420
##
521
## Gradle start up script for UN*X
@@ -28,7 +44,7 @@ APP_NAME="Gradle"
2844
APP_BASE_NAME=`basename "$0"`
2945

3046
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31-
DEFAULT_JVM_OPTS=""
47+
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
3248

3349
# Use the maximum available, or set MAX_FD != -1 to use that value.
3450
MAX_FD="maximum"
@@ -56,7 +72,7 @@ case "`uname`" in
5672
Darwin* )
5773
darwin=true
5874
;;
59-
MINGW* )
75+
MSYS* | MINGW* )
6076
msys=true
6177
;;
6278
NONSTOP* )
@@ -66,6 +82,7 @@ esac
6682

6783
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
6884

85+
6986
# Determine the Java command to use to start the JVM.
7087
if [ -n "$JAVA_HOME" ] ; then
7188
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
@@ -109,10 +126,11 @@ if $darwin; then
109126
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110127
fi
111128

112-
# For Cygwin, switch paths to Windows format before running java
113-
if $cygwin ; then
129+
# For Cygwin or MSYS, switch paths to Windows format before running java
130+
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
114131
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115132
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
133+
116134
JAVACMD=`cygpath --unix "$JAVACMD"`
117135

118136
# We build the pattern for arguments to be converted via cygpath
@@ -138,19 +156,19 @@ if $cygwin ; then
138156
else
139157
eval `echo args$i`="\"$arg\""
140158
fi
141-
i=$((i+1))
159+
i=`expr $i + 1`
142160
done
143161
case $i in
144-
(0) set -- ;;
145-
(1) set -- "$args0" ;;
146-
(2) set -- "$args0" "$args1" ;;
147-
(3) set -- "$args0" "$args1" "$args2" ;;
148-
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149-
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150-
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151-
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152-
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153-
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
162+
0) set -- ;;
163+
1) set -- "$args0" ;;
164+
2) set -- "$args0" "$args1" ;;
165+
3) set -- "$args0" "$args1" "$args2" ;;
166+
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
167+
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
168+
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
169+
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
170+
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
171+
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154172
esac
155173
fi
156174

@@ -159,14 +177,9 @@ save () {
159177
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160178
echo " "
161179
}
162-
APP_ARGS=$(save "$@")
180+
APP_ARGS=`save "$@"`
163181

164182
# Collect all arguments for the java command, following the shell quoting and substitution rules
165183
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166184

167-
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168-
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169-
cd "$(dirname "$0")"
170-
fi
171-
172185
exec "$JAVACMD" "$@"

‎gradlew.bat

+24-19
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
@rem
2+
@rem Copyright 2015 the original author or authors.
3+
@rem
4+
@rem Licensed under the Apache License, Version 2.0 (the "License");
5+
@rem you may not use this file except in compliance with the License.
6+
@rem You may obtain a copy of the License at
7+
@rem
8+
@rem https://www.apache.org/licenses/LICENSE-2.0
9+
@rem
10+
@rem Unless required by applicable law or agreed to in writing, software
11+
@rem distributed under the License is distributed on an "AS IS" BASIS,
12+
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
@rem See the License for the specific language governing permissions and
14+
@rem limitations under the License.
15+
@rem
16+
117
@if "%DEBUG%" == "" @echo off
218
@rem ##########################################################################
319
@rem
@@ -13,15 +29,18 @@ if "%DIRNAME%" == "" set DIRNAME=.
1329
set APP_BASE_NAME=%~n0
1430
set APP_HOME=%DIRNAME%
1531

32+
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
33+
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
34+
1635
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17-
set DEFAULT_JVM_OPTS=
36+
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
1837

1938
@rem Find java.exe
2039
if defined JAVA_HOME goto findJavaFromJavaHome
2140

2241
set JAVA_EXE=java.exe
2342
%JAVA_EXE% -version >NUL 2>&1
24-
if "%ERRORLEVEL%" == "0" goto init
43+
if "%ERRORLEVEL%" == "0" goto execute
2544

2645
echo.
2746
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
@@ -35,7 +54,7 @@ goto fail
3554
set JAVA_HOME=%JAVA_HOME:"=%
3655
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
3756

38-
if exist "%JAVA_EXE%" goto init
57+
if exist "%JAVA_EXE%" goto execute
3958

4059
echo.
4160
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
@@ -45,28 +64,14 @@ echo location of your Java installation.
4564

4665
goto fail
4766

48-
:init
49-
@rem Get command-line arguments, handling Windows variants
50-
51-
if not "%OS%" == "Windows_NT" goto win9xME_args
52-
53-
:win9xME_args
54-
@rem Slurp the command line arguments.
55-
set CMD_LINE_ARGS=
56-
set _SKIP=2
57-
58-
:win9xME_args_slurp
59-
if "x%~1" == "x" goto execute
60-
61-
set CMD_LINE_ARGS=%*
62-
6367
:execute
6468
@rem Setup the command line
6569

6670
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
6771

72+
6873
@rem Execute Gradle
69-
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
74+
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
7075

7176
:end
7277
@rem End local scope for the variables with windows NT shell

‎legacy/build.gradle

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
plugins {
3+
id "java"
4+
id "eclipse"
5+
}
6+
7+
repositories {
8+
mavenCentral()
9+
maven {
10+
name = "forge"
11+
url = "https://maven.minecraftforge.net/"
12+
}
13+
}
14+
15+
dependencies {
16+
compileOnly "net.minecraftforge:installer:2.0.24"
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package io.github.zekerzhayard.forgewrapper.installer;
2+
3+
import java.io.File;
4+
import java.util.function.Predicate;
5+
6+
import net.minecraftforge.installer.actions.ClientInstall;
7+
import net.minecraftforge.installer.actions.ProgressCallback;
8+
import net.minecraftforge.installer.json.Install;
9+
10+
public class LegacyClientInstall4MultiMC extends ClientInstall {
11+
protected File libraryDir;
12+
protected File minecraftJar;
13+
14+
public LegacyClientInstall4MultiMC(Install profile, ProgressCallback monitor, File libraryDir, File minecraftJar) {
15+
super(profile, monitor);
16+
this.libraryDir = libraryDir;
17+
this.minecraftJar = minecraftJar;
18+
}
19+
20+
@Override
21+
public boolean run(File target, Predicate<String> optionals) {
22+
return this.processors.process(this.libraryDir, this.minecraftJar);
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package io.github.zekerzhayard.forgewrapper.installer.util;
2+
3+
import net.minecraftforge.installer.json.Install;
4+
import net.minecraftforge.installer.json.Util;
5+
6+
// to compatible with forge [1.13.2-25.0.9,1.16.5-36.1.65]
7+
public class LegacyInstallerUtil {
8+
public static Install loadInstallProfile() {
9+
return Util.loadInstallProfile();
10+
}
11+
}

‎settings.gradle

+2-9
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
/*
2-
* This file was generated by the Gradle 'init' task.
3-
*
4-
* The settings file is used to specify which projects to include in your build.
5-
*
6-
* Detailed information about configuring a multi-project build in Gradle can be found
7-
* in the user guide at https://docs.gradle.org/4.10.3/userguide/multi_project_builds.html
8-
*/
9-
101
rootProject.name = 'ForgeWrapper'
2+
3+
include 'legacy'

‎src/main/java/io/github/zekerzhayard/forgewrapper/installer/ClientInstall4MultiMC.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,20 @@
66
import net.minecraftforge.installer.actions.ClientInstall;
77
import net.minecraftforge.installer.actions.ProgressCallback;
88
import net.minecraftforge.installer.json.Install;
9+
import net.minecraftforge.installer.json.InstallV1;
910

1011
public class ClientInstall4MultiMC extends ClientInstall {
1112
protected File libraryDir;
1213
protected File minecraftJar;
1314

1415
public ClientInstall4MultiMC(Install profile, ProgressCallback monitor, File libraryDir, File minecraftJar) {
15-
super(profile, monitor);
16+
super(profile instanceof InstallV1 ? (InstallV1) profile : new InstallV1(profile), monitor);
1617
this.libraryDir = libraryDir;
1718
this.minecraftJar = minecraftJar;
1819
}
1920

2021
@Override
21-
public boolean run(File target, Predicate<String> optionals) {
22-
return this.processors.process(this.libraryDir, this.minecraftJar);
22+
public boolean run(File target, Predicate<String> optionals, File installer) {
23+
return this.processors.process(this.libraryDir, this.minecraftJar, this.libraryDir.getParentFile(), installer);
2324
}
2425
}

‎src/main/java/io/github/zekerzhayard/forgewrapper/installer/Installer.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
import java.io.File;
44

5+
import io.github.zekerzhayard.forgewrapper.installer.util.InstallerUtil;
56
import net.minecraftforge.installer.actions.ProgressCallback;
67
import net.minecraftforge.installer.json.Install;
7-
import net.minecraftforge.installer.json.Util;
88

99
public class Installer {
10-
public static boolean install(File libraryDir, File minecraftJar) {
10+
public static boolean install(File libraryDir, File minecraftJar, File installerJar, String forgeVersion) {
1111
ProgressCallback monitor = ProgressCallback.withOutputs(System.out);
12-
Install install = Util.loadInstallProfile();
12+
Install install = InstallerUtil.loadInstallProfile(forgeVersion);
1313
if (System.getProperty("java.net.preferIPv4Stack") == null) {
1414
System.setProperty("java.net.preferIPv4Stack", "true");
1515
}
@@ -18,6 +18,6 @@ public static boolean install(File libraryDir, File minecraftJar) {
1818
String jvmVersion = System.getProperty("java.vm.version", "missing jvm version");
1919
monitor.message(String.format("JVM info: %s - %s - %s", vendor, javaVersion, jvmVersion));
2020
monitor.message("java.net.preferIPv4Stack=" + System.getProperty("java.net.preferIPv4Stack"));
21-
return new ClientInstall4MultiMC(install, monitor, libraryDir, minecraftJar).run(null, input -> true);
21+
return InstallerUtil.runClientInstall(forgeVersion, install, monitor, libraryDir, minecraftJar, installerJar);
2222
}
2323
}

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import java.io.File;
44
import java.net.URL;
55
import java.net.URLClassLoader;
6-
import java.nio.file.Files;
76
import java.nio.file.Path;
87
import java.util.List;
98
import java.util.stream.Collectors;
@@ -17,7 +16,8 @@ public class Main {
1716
public static void main(String[] args) throws Exception {
1817
List<String> argsList = Stream.of(args).collect(Collectors.toList());
1918
String mcVersion = argsList.get(argsList.indexOf("--fml.mcVersion") + 1);
20-
String forgeFullVersion = mcVersion + "-" + argsList.get(argsList.indexOf("--fml.forgeVersion") + 1);
19+
String forgeVersion = argsList.get(argsList.indexOf("--fml.forgeVersion") + 1);
20+
String forgeFullVersion = mcVersion + "-" + forgeVersion;
2121

2222
IFileDetector detector = DetectorLoader.loadDetector();
2323
if (!detector.checkExtraFiles(forgeFullVersion)) {
@@ -26,13 +26,13 @@ public static void main(String[] args) throws Exception {
2626
// Check installer jar.
2727
Path installerJar = detector.getInstallerJar(forgeFullVersion);
2828
if (!IFileDetector.isFile(installerJar)) {
29-
throw new RuntimeException("Can't detect the forge installer!");
29+
throw new RuntimeException("Unable to detect the forge installer!");
3030
}
3131

3232
// Check vanilla Minecraft jar.
3333
Path minecraftJar = detector.getMinecraftJar(mcVersion);
3434
if (!IFileDetector.isFile(minecraftJar)) {
35-
throw new RuntimeException("Can't detect the Minecraft jar!");
35+
throw new RuntimeException("Unable to detect the Minecraft jar!");
3636
}
3737

3838
try (URLClassLoader ucl = URLClassLoader.newInstance(new URL[] {
@@ -41,13 +41,13 @@ public static void main(String[] args) throws Exception {
4141
installerJar.toUri().toURL()
4242
}, getParentClassLoader())) {
4343
Class<?> installer = ucl.loadClass("io.github.zekerzhayard.forgewrapper.installer.Installer");
44-
if (!(boolean) installer.getMethod("install", File.class, File.class).invoke(null, detector.getLibraryDir().toFile(), minecraftJar.toFile())) {
44+
if (!(boolean) installer.getMethod("install", File.class, File.class, File.class, String.class).invoke(null, detector.getLibraryDir().toFile(), minecraftJar.toFile(), installerJar.toFile(), forgeVersion)) {
4545
return;
4646
}
4747
}
4848
}
4949

50-
Launcher.main(args);
50+
Launcher.main(args); // TODO: this will be broken in forge 1.17
5151
}
5252

5353
// https://github.com/MinecraftForge/Installer/blob/fe18a164b5ebb15b5f8f33f6a149cc224f446dc2/src/main/java/net/minecraftforge/installer/actions/PostProcessors.java#L287-L303
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package io.github.zekerzhayard.forgewrapper.installer;
2+
3+
import java.util.function.Consumer;
4+
5+
// to support forge 1.17 (bootstraplauncher)
6+
public class MainV2 implements Consumer<String[]> {
7+
@Override
8+
public void accept(String[] args) {
9+
try {
10+
Main.main(args);
11+
} catch (Throwable t) {
12+
throw new RuntimeException(t);
13+
}
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package io.github.zekerzhayard.forgewrapper.installer.util;
2+
3+
import java.io.File;
4+
import java.util.regex.Matcher;
5+
import java.util.regex.Pattern;
6+
7+
import io.github.zekerzhayard.forgewrapper.installer.ClientInstall4MultiMC;
8+
import io.github.zekerzhayard.forgewrapper.installer.LegacyClientInstall4MultiMC;
9+
import net.minecraftforge.installer.actions.ProgressCallback;
10+
import net.minecraftforge.installer.json.Install;
11+
import net.minecraftforge.installer.json.Util;
12+
13+
public class InstallerUtil {
14+
public static Install loadInstallProfile(String forgeVersion) {
15+
if (isLegacyForge(forgeVersion, "36.1.65")) {
16+
return LegacyInstallerUtil.loadInstallProfile();
17+
} else {
18+
// to prevent ClassNotFoundException
19+
return new Object() {
20+
public Install get() {
21+
return Util.loadInstallProfile();
22+
}
23+
}.get();
24+
}
25+
}
26+
27+
public static boolean runClientInstall(String forgeVersion, Install profile, ProgressCallback monitor, File libraryDir, File minecraftJar, File installerJar) {
28+
if (isLegacyForge(forgeVersion, "36.1.65")) {
29+
return new LegacyClientInstall4MultiMC(profile, monitor, libraryDir, minecraftJar).run(null, input -> true);
30+
} else {
31+
return new ClientInstall4MultiMC(profile, monitor, libraryDir, minecraftJar).run(null, input -> true, installerJar);
32+
}
33+
}
34+
35+
private final static Pattern FORGE_VERSION_PATTERN = Pattern.compile("(?<major>\\d+)\\.(?<minor>\\d+)\\.(?<build>\\d+)");
36+
private static boolean isLegacyForge(String forgeVersion, String legacyForgeVersion) {
37+
Matcher m0 = FORGE_VERSION_PATTERN.matcher(forgeVersion);
38+
Matcher m1 = FORGE_VERSION_PATTERN.matcher(legacyForgeVersion);
39+
if (m0.find() && m1.find()) {
40+
return compareVersion(m0, m1, 0, "major", "minor", "build");
41+
}
42+
throw new RuntimeException("Missing forge version!");
43+
}
44+
45+
private static boolean compareVersion(Matcher m0, Matcher m1, int index, String... groups) {
46+
if (index == groups.length) return true; // the same as the legacy version
47+
int result = Integer.compare(Integer.parseInt(m0.group(groups[index])), Integer.parseInt(m1.group(groups[index])));
48+
if (result < 0) return true; // less than the legacy version
49+
if (result > 0) return false; // greater than the legacy version
50+
return compareVersion(m0, m1, index + 1, groups);
51+
}
52+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
io.github.zekerzhayard.forgewrapper.installer.MainV2

0 commit comments

Comments
 (0)
Please sign in to comment.