Add back support for architectury.common.json and quilt in AW remapping

Signed-off-by: shedaniel <daniel@shedaniel.me>
This commit is contained in:
shedaniel
2022-08-11 02:26:20 +08:00
parent 8457a11f8b
commit 7052f0f95f

View File

@@ -28,6 +28,7 @@ import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import org.objectweb.asm.commons.Remapper;
@@ -58,14 +59,41 @@ public class AccessWidenerUtils {
}
public static AccessWidenerData readAccessWidenerData(Path inputJar) throws IOException {
byte[] modJsonBytes = ZipUtils.unpack(inputJar, "fabric.mod.json");
JsonObject jsonObject = LoomGradlePlugin.GSON.fromJson(new String(modJsonBytes, StandardCharsets.UTF_8), JsonObject.class);
String fieldName = "accessWidener";
byte[] modJsonBytes = ZipUtils.unpackNullable(inputJar, "fabric.mod.json");
if (!jsonObject.has("accessWidener")) {
return null;
if (modJsonBytes == null) {
modJsonBytes = ZipUtils.unpackNullable(inputJar, "architectury.common.json");
if (modJsonBytes == null) {
modJsonBytes = ZipUtils.unpackNullable(inputJar, "quilt.mod.json");
if (modJsonBytes != null) {
fieldName = "access_widener";
} else {
// No access widener data
// We can just ignore in architectury
return null;
}
}
}
JsonObject jsonObject = LoomGradlePlugin.GSON.fromJson(new String(modJsonBytes, StandardCharsets.UTF_8), JsonObject.class);
String accessWidenerPath;
if (fieldName.equals("access_widener") && jsonObject.get(fieldName).isJsonArray()) {
JsonArray array = jsonObject.get(fieldName).getAsJsonArray();
if (array.size() != 1) {
throw new UnsupportedOperationException("Loom does not support multiple access wideners in one mod!");
}
accessWidenerPath = array.get(0).getAsString();
} else {
accessWidenerPath = jsonObject.get(fieldName).getAsString();
}
String accessWidenerPath = jsonObject.get("accessWidener").getAsString();
byte[] accessWidener = ZipUtils.unpack(inputJar, accessWidenerPath);
AccessWidenerReader.Header header = AccessWidenerReader.readHeader(accessWidener);