Skip to content

Commit 9947fef

Browse files
Edit version json instead of maintaining our own (IrisShaders#16)
* Edit version json instead of maintaining owown * Only apply profile json edition to iris-loader Code is awful, but passing the boolean feels bad when half of the things passed to the method could be derived from it * Fix spacing Co-authored-by: Justsnoopy30 <justsnoopy30@hypercubemc.tk>
1 parent 037888e commit 9947fef

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

src/main/java/net/hypercubemc/iris_installer/Installer.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -203,15 +203,6 @@ public void start() {
203203
return;
204204
}
205205

206-
// Use IMS's custom fabric loader if "Install as Fabric Mod" is not set
207-
if (!installAsMod) {
208-
Reference.metaServerUrl = "https://raw.githubusercontent.com/IrisShaders/Iris-Installer-Maven/master/";
209-
System.out.println("Using custom loader");
210-
} else {
211-
Reference.metaServerUrl = "https://meta.fabricmc.net/";
212-
System.out.println("Using fabric loader");
213-
}
214-
215206
String loaderName = installAsMod ? "fabric-loader" : "iris-fabric-loader";
216207

217208
try {

src/main/java/net/hypercubemc/iris_installer/VanillaLauncherIntegration.java

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package net.hypercubemc.iris_installer;
22

3+
import mjson.Json;
34
import net.fabricmc.installer.client.ProfileInstaller;
45
import net.fabricmc.installer.util.Reference;
56
import net.fabricmc.installer.util.Utils;
@@ -12,7 +13,6 @@
1213
import java.nio.file.Files;
1314
import java.nio.file.Path;
1415
import java.util.*;
15-
import java.util.List;
1616
import java.util.stream.Collectors;
1717

1818
public class VanillaLauncherIntegration {
@@ -34,7 +34,7 @@ public static void installVersion(Path mcDir, String gameVersion, String loaderN
3434
String versionId = String.format("%s-%s-%s", loaderName, loaderVersion, gameVersion);
3535
Path versionsDir = mcDir.resolve("versions");
3636
Path profileDir = versionsDir.resolve(versionId);
37-
Path profileJson = profileDir.resolve(versionId + ".json");
37+
Path profileJsonPath = profileDir.resolve(versionId + ".json");
3838
if (!Files.exists(profileDir)) {
3939
Files.createDirectories(profileDir);
4040
}
@@ -43,7 +43,27 @@ public static void installVersion(Path mcDir, String gameVersion, String loaderN
4343
Files.deleteIfExists(dummyJar);
4444
Files.createFile(dummyJar);
4545
URL profileUrl = new URL(Reference.getMetaServerEndpoint(String.format("v2/versions/loader/%s/%s/profile/json", gameVersion, loaderVersion)));
46-
Utils.downloadFile(profileUrl, profileJson);
46+
Json profileJson = Json.read(profileUrl);
47+
if (loaderName.equals("iris-fabric-loader")) {
48+
editVersionJson(profileJson);
49+
}
50+
Utils.writeToFile(profileJsonPath, profileJson.toString());
51+
}
52+
53+
private static void editVersionJson(Json profileJson) {
54+
Json.Factory factory = Json.factory();
55+
Map<String, Json> json = profileJson.asJsonMap();
56+
// Replace fabric-loader-etc with iris-fabric-loader-etc
57+
json.compute("id", (ignored, existing) -> factory.string("iris-" + existing.asString()));
58+
// Replace loader maven url and name
59+
for (Json entry : json.get("libraries").asJsonList()) {
60+
final String id = "net.fabricmc:fabric-loader:";
61+
String name = entry.asJsonMap().get("name").asString();
62+
if (name.startsWith("net.fabricmc:fabric-loader:")) {
63+
entry.asJsonMap().put("name", factory.string("net.coderbot:iris-loader:" + name.substring(id.length())));
64+
entry.asJsonMap().put("url", factory.string("https://raw.githubusercontent.com/IrisShaders/Iris-Installer-Maven/master/"));
65+
}
66+
}
4767
}
4868

4969
private static void installProfile(Path mcDir, Path instanceDir, String profileName, String versionId, Icon icon, ProfileInstaller.LauncherType launcherType) throws IOException {

0 commit comments

Comments
 (0)