Skip to content

Commit

Permalink
Fix compatibility with Java 9+.
Browse files Browse the repository at this point in the history
Remove unnecessary functions.
  • Loading branch information
ZekerZhayard committed Mar 28, 2020
1 parent fb8888a commit 9f65af3
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 319 deletions.
20 changes: 4 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

Allow [MultiMC](https://github.com/MultiMC/MultiMC5) to launch Minecraft 1.13+ with Forge.

## How to use
**ForgeWrapper has been adopted by MultiMC, you do not need to perform the following steps manually. (2020-03-29)**

## How to use (Outdated)

### Install Forge Only
1. Download Forge installer for Minecraft 1.13+ [here](https://files.minecraftforge.net/).
2. Download ForgeWrapper jar file at the [release](https://github.com/ZekerZhayard/ForgeWrapper/releases) page.
3. Run the below command in terminal:
Expand All @@ -14,17 +15,4 @@ Allow [MultiMC](https://github.com/MultiMC/MultiMC5) to launch Minecraft 1.13+ w
*Notice: If you don't specify a MultiMC instance path, ForgeWrapper will create the instance folder in current working space.*

4. If the instance folder which just created is not in `MultiMC/instances` folder, you just need to move to the `MultiMC/instances` folder.
5. Run MultiMC, and you will see a new instance named `forge-<mcVersion>-<forgeVersion>`.

### Install CurseForge Modpack
1. Download the modpack zip file.
2. Download ForgeWrapper jar file at the [release](https://github.com/ZekerZhayard/ForgeWrapper/releases) page.
3. Run the below command in terminal:
```
java -jar <ForgeWrapper.jar> --cursepack=<curseforge-modpack.zip> [--instance=<instance-path>]
```
*Notice: If you don't specify a MultiMC instance path, ForgeWrapper will create the instance folder in current working space.*

4. If the instance folder which just created is not in `MultiMC/instances` folder, you just need to move to the `MultiMC/instances` folder.
5. Run MultiMC, and you will see a new instance named `<modpackName>-<modpackVersion>`.
*Notice: CurseForge modpack will be installed on first launch by [cursepacklocator](https://github.com/cpw/cursepacklocator), it will take a few minutes.*
5. Run MultiMC, and you will see a new instance named `forge-<mcVersion>-<forgeVersion>`.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ apply plugin: "idea"

sourceCompatibility = targetCompatibility = 1.8

version = "1.4.0"
version = "1.4.1"
group = "io.github.zekerzhayard"
archivesBaseName = rootProject.name

Expand Down
166 changes: 0 additions & 166 deletions src/main/java/cpw/mods/forge/cursepacklocator/Murmur2.java

This file was deleted.

65 changes: 0 additions & 65 deletions src/main/java/io/github/zekerzhayard/forgewrapper/Utils.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -22,33 +21,27 @@
import com.google.gson.JsonNull;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import io.github.zekerzhayard.forgewrapper.Utils;

public class Converter {
public static void convert(Path installerPath, Path targetDir, Path multimcDir, String cursepack) throws Exception {
if (cursepack != null) {
installerPath = getForgeInstallerFromCursePack(cursepack);
}

public static void convert(Path installerPath, Path targetDir, Path multimcDir) throws Exception {
JsonObject installer = getJsonFromZip(installerPath, "version.json");
JsonObject installProfile = getJsonFromZip(installerPath, "install_profile.json");
List<String> arguments = getAdditionalArgs(installer);
String mcVersion = arguments.get(arguments.indexOf("--fml.mcVersion") + 1);
String forgeVersion = arguments.get(arguments.indexOf("--fml.forgeVersion") + 1);
String forgeFullVersion = "forge-" + mcVersion + "-" + forgeVersion;
String instanceName = cursepack == null ? forgeFullVersion : installerPath.toFile().getName().replace("-installer.jar", "");
StringBuilder wrapperVersion = new StringBuilder();

JsonObject pack = convertPackJson(mcVersion);
JsonObject patches = convertPatchesJson(installer, installProfile, mcVersion, forgeVersion, wrapperVersion, cursepack);
JsonObject patches = convertPatchesJson(installer, installProfile, mcVersion, forgeVersion, wrapperVersion);

Files.createDirectories(targetDir);

// Copy mmc-pack.json and instance.cfg to <instance> folder.
Path instancePath = targetDir.resolve(instanceName);
Path instancePath = targetDir.resolve(forgeFullVersion);
Files.createDirectories(instancePath);
Files.copy(new ByteArrayInputStream(pack.toString().getBytes(StandardCharsets.UTF_8)), instancePath.resolve("mmc-pack.json"), StandardCopyOption.REPLACE_EXISTING);
Files.copy(new ByteArrayInputStream(("InstanceType=OneSix\nname=" + instanceName).getBytes(StandardCharsets.UTF_8)), instancePath.resolve("instance.cfg"), StandardCopyOption.REPLACE_EXISTING);
Files.copy(new ByteArrayInputStream(("InstanceType=OneSix\nname=" + forgeFullVersion).getBytes(StandardCharsets.UTF_8)), instancePath.resolve("instance.cfg"), StandardCopyOption.REPLACE_EXISTING);

// Copy ForgeWrapper to <instance>/libraries folder.
Path librariesPath = instancePath.resolve("libraries");
Expand All @@ -60,22 +53,9 @@ public static void convert(Path installerPath, Path targetDir, Path multimcDir,
Files.createDirectories(patchesPath);
Files.copy(new ByteArrayInputStream(patches.toString().getBytes(StandardCharsets.UTF_8)), patchesPath.resolve("net.minecraftforge.json"), StandardCopyOption.REPLACE_EXISTING);

// Extract all curse pack entries to <instance>/.minecraft folder.
Path minecraftPath = instancePath.resolve(".minecraft");
if (cursepack != null) {
ZipFile zip = new ZipFile(cursepack);
Enumeration<? extends ZipEntry> entries = zip.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
Path targetFolder = minecraftPath.resolve(entry.getName());
Files.createDirectories(targetFolder.getParent());
Files.copy(zip.getInputStream(entry), targetFolder, StandardCopyOption.REPLACE_EXISTING);
}
}

// Copy forge installer to MultiMC/libraries/net/minecraftforge/forge/<mcVersion>-<forgeVersion> folder.
if (multimcDir != null) {
Path targetInstallerPath = multimcDir.resolve("net").resolve("minecraftforge").resolve("forge").resolve(forgeVersion);
Path targetInstallerPath = multimcDir.resolve("libraries").resolve("net").resolve("minecraftforge").resolve("forge").resolve(forgeVersion);
Files.createDirectories(targetInstallerPath);
Files.copy(installerPath, targetInstallerPath.resolve(forgeFullVersion + "-installer.jar"), StandardCopyOption.REPLACE_EXISTING);
}
Expand All @@ -101,28 +81,6 @@ public static JsonObject getJsonFromZip(Path path, String json) {
}
}

private static Path getForgeInstallerFromCursePack(String cursepack) throws Exception {
JsonObject manifest = getJsonFromZip(Paths.get(cursepack), "manifest.json");
JsonObject minecraft = getElement(manifest, "minecraft").getAsJsonObject();
String mcVersion = getElement(minecraft, "version").getAsString();
String forgeVersion = null;
for (JsonElement element : getElement(minecraft, "modLoaders").getAsJsonArray()) {
String id = getElement(element.getAsJsonObject(), "id").getAsString();
if (id.startsWith("forge-")) {
forgeVersion = id.replace("forge-", "");
break;
}
}
if (forgeVersion == null) {
throw new RuntimeException("The curse pack is invalid!");
}
String packName = getElement(manifest, "name").getAsString();
String packVersion = getElement(manifest, "version").getAsString();
Path installer = Paths.get(System.getProperty("java.io.tmpdir", "."), String.format("%s-%s-installer.jar", packName, packVersion));
Utils.download(String.format("https://files.minecraftforge.net/maven/net/minecraftforge/forge/%s-%s/forge-%s-%s-installer.jar", mcVersion, forgeVersion, mcVersion, forgeVersion), installer.toString());
return installer;
}

// Convert mmc-pack.json:
// - Replace Minecraft version
private static JsonObject convertPackJson(String mcVersion) {
Expand All @@ -142,7 +100,7 @@ private static JsonObject convertPackJson(String mcVersion) {
// - Add libraries
// - Add forge-launcher url
// - Replace Minecraft & Forge versions
private static JsonObject convertPatchesJson(JsonObject installer, JsonObject installProfile, String mcVersion, String forgeVersion, StringBuilder wrapperVersion, String cursepack) {
private static JsonObject convertPatchesJson(JsonObject installer, JsonObject installProfile, String mcVersion, String forgeVersion, StringBuilder wrapperVersion) {
JsonObject patches = new JsonParser().parse(new InputStreamReader(Converter.class.getResourceAsStream("/patches/net.minecraftforge.json"))).getAsJsonObject();
JsonArray mavenFiles = getElement(patches, "mavenFiles").getAsJsonArray();
JsonArray libraries = getElement(patches, "libraries").getAsJsonArray();
Expand All @@ -160,12 +118,6 @@ private static JsonObject convertPatchesJson(JsonObject installer, JsonObject in
wrapperVersion.append(getElement(lib.getAsJsonObject(), "MMC-filename").getAsString());
}
}
if (cursepack != null) {
JsonObject cursepacklocator = new JsonObject();
cursepacklocator.addProperty("name", "cpw.mods.forge:cursepacklocator:1.2.0");
cursepacklocator.addProperty("url", "https://files.minecraftforge.net/maven/");
libraries.add(cursepacklocator);
}
Map<String, String> additionalUrls = new HashMap<>();
String path = String.format("net/minecraftforge/forge/%s-%s/forge-%s-%s", mcVersion, forgeVersion, mcVersion, forgeVersion);
additionalUrls.put(path + "-universal.jar", "https://files.minecraftforge.net/maven/" + path + "-universal.jar");
Expand Down
Loading

0 comments on commit 9f65af3

Please sign in to comment.