Skip to content

Commit

Permalink
Version - add legacy versions with searge mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaneBeee committed Oct 4, 2024
1 parent 3b93a0d commit 7afc6d6
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 22 deletions.
5 changes: 5 additions & 0 deletions src/main/java/com/shanebeestudios/mcdeob/Processor.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,11 @@ public void remapJar() {
inheritanceProvider.add(new JarProvider(internalJars));
jarRemapper.remapJar(internalJars, new File(this.remappedJar.toUri()));
internalJars.close();

if (this.version.isSearge()) {
// Some versions like 1.12.2 include this nasty giant package
Util.stripFileFromJar(this.remappedJar, "it/*");
}
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down
61 changes: 39 additions & 22 deletions src/main/java/com/shanebeestudios/mcdeob/Version.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.shanebeestudios.mcdeob;

import com.shanebeestudios.mcdeob.util.Logger;
import com.shanebeestudios.mcdeob.util.Util;
import org.jetbrains.annotations.Nullable;
import org.json.JSONObject;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;

Expand All @@ -18,31 +20,38 @@ public class Version {
private static final Map<String, Version> SNAPSHOT_MAP = new LinkedHashMap<>();

public static void initVersions() {
JSONObject versionManifest;
try {
versionManifest = Util.getJsonFromURL("https://launchermeta.mojang.com/mc/game/version_manifest.json");
} catch (IOException e) {
throw new RuntimeException(e);
JSONObject mojangManifest = Util.getJsonFromURL("https://launchermeta.mojang.com/mc/game/version_manifest.json");
JSONObject seargeManifest = Util.getJsonFromURL("https://raw.githubusercontent.com/ShaneBeeStudios/Mappings/refs/heads/main/mappings/versions.json");

boolean searge = false;
List<String> seargeVersions = new ArrayList<>();
for (Object o : seargeManifest.getJSONArray("versions")) {
seargeVersions.add(o.toString());
}

for (Object o : versionManifest.getJSONArray("versions")) {
for (Object o : mojangManifest.getJSONArray("versions")) {
JSONObject versionObject = (JSONObject) o;
String id = versionObject.getString("id");
String type = versionObject.getString("type");
String url = versionObject.getString("url");

if (searge && !seargeVersions.contains(id)) {
continue;
}

ReleaseType releaseType = type.equalsIgnoreCase("release") ? ReleaseType.RELEASE : ReleaseType.SNAPSHOT;
Version version = new Version(id, releaseType, url);
Version version = new Version(id, releaseType, url, searge);
VERSION_MAP.put(id, version);
if (releaseType == ReleaseType.RELEASE) {
RELEASE_MAP.put(id, version);
} else {
SNAPSHOT_MAP.put(id, version);
}

// Mappings not available before 1.14.4, so we exit
// Mojang mappings not available before 1.14.4
// so we use searge mappings
if (id.equalsIgnoreCase("1.14.4")) {
break;
searge = true;
}
}
}
Expand All @@ -68,29 +77,33 @@ public static Version getByVersion(String version) {
private final String version;
private final ReleaseType releaseType;
private final String url;
private final boolean searge;

private Type type;
private String jarURL;
private String mapURL;

public Version(String version, ReleaseType releaseType, String url) {
public Version(String version, ReleaseType releaseType, String url, boolean searge) {
this.version = version;
this.releaseType = releaseType;
this.url = url;
this.searge = searge;
}

public boolean prepareVersion() {
try {
JSONObject versionInfo = Util.getJsonFromURL(this.url);
JSONObject downloads = versionInfo.getJSONObject("downloads");
if (downloads.has("server_mappings")) {
String typeName = this.type.getName();
this.jarURL = downloads.getJSONObject(typeName).getString("url");
this.mapURL = downloads.getJSONObject(typeName + "_mappings").getString("url");
return true;
}
} catch (IOException e) {
throw new RuntimeException(e);
JSONObject versionInfo = Util.getJsonFromURL(this.url);
JSONObject downloads = versionInfo.getJSONObject("downloads");
Logger.info("Downloads: " + downloads.toString(2));
if (downloads.has("server_mappings")) {
String typeName = this.type.getName();
this.jarURL = downloads.getJSONObject(typeName).getString("url");
this.mapURL = downloads.getJSONObject(typeName + "_mappings").getString("url");
return true;
} else if (this.searge) {
String typeName = this.type.getName();
this.jarURL = downloads.getJSONObject(typeName).getString("url");
this.mapURL = String.format("https://raw.githubusercontent.com/ShaneBeeStudios/Mappings/refs/heads/main/mappings/mappings_%s_%s.txt", typeName, this.version);
return true;
}
return false;
}
Expand Down Expand Up @@ -119,6 +132,10 @@ public String getMapURL() {
return this.mapURL;
}

public boolean isSearge() {
return this.searge;
}

public enum Type {
SERVER,
CLIENT;
Expand Down

0 comments on commit 7afc6d6

Please sign in to comment.