diff options
author | shedaniel <daniel@shedaniel.me> | 2021-12-08 21:38:24 +0800 |
---|---|---|
committer | shedaniel <daniel@shedaniel.me> | 2021-12-08 21:38:24 +0800 |
commit | a6a1d5d29b6393e70bf63e872ebdd42a25e0680b (patch) | |
tree | f7ecc57af5ee1cfd04fde6811c3bd75808ccf6c9 /src/main | |
parent | 3c8e1f8b31ab96322887c77dd1ed2a138727dee6 (diff) | |
download | architectury-loom-a6a1d5d29b6393e70bf63e872ebdd42a25e0680b.tar.gz architectury-loom-a6a1d5d29b6393e70bf63e872ebdd42a25e0680b.tar.bz2 architectury-loom-a6a1d5d29b6393e70bf63e872ebdd42a25e0680b.zip |
Move architectury.common.json check behind fabric.mod.json
Signed-off-by: shedaniel <daniel@shedaniel.me>
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/net/fabricmc/loom/configuration/accesswidener/AccessWidenerFile.java | 76 |
1 files changed, 38 insertions, 38 deletions
diff --git a/src/main/java/net/fabricmc/loom/configuration/accesswidener/AccessWidenerFile.java b/src/main/java/net/fabricmc/loom/configuration/accesswidener/AccessWidenerFile.java index 5bc892e9..4961e71d 100644 --- a/src/main/java/net/fabricmc/loom/configuration/accesswidener/AccessWidenerFile.java +++ b/src/main/java/net/fabricmc/loom/configuration/accesswidener/AccessWidenerFile.java @@ -45,44 +45,6 @@ public record AccessWidenerFile( * Reads the access-widener contained in a mod jar, or returns null if there is none. */ public static AccessWidenerFile fromModJar(Path modJarPath) { - if (ZipUtils.contains(modJarPath, "architectury.common.json")) { - String awPath = null; - byte[] commonJsonBytes; - - try { - commonJsonBytes = ZipUtils.unpackNullable(modJarPath, "architectury.common.json"); - } catch (IOException e) { - throw new UncheckedIOException("Failed to read access-widener file from: " + modJarPath.toAbsolutePath(), e); - } - - if (commonJsonBytes != null) { - JsonObject jsonObject = new Gson().fromJson(new String(commonJsonBytes, StandardCharsets.UTF_8), JsonObject.class); - - if (jsonObject.has("accessWidener")) { - awPath = jsonObject.get("accessWidener").getAsString(); - } else { - throw new IllegalArgumentException("The architectury.common.json file does not contain an accessWidener field."); - } - } else { - // ??????????? - throw new IllegalArgumentException("The architectury.common.json file does not exist."); - } - - byte[] content; - - try { - content = ZipUtils.unpack(modJarPath, awPath); - } catch (IOException e) { - throw new UncheckedIOException("Could not find access widener file (%s) defined in the architectury.common.json file of %s".formatted(awPath, modJarPath.toAbsolutePath()), e); - } - - return new AccessWidenerFile( - awPath, - modJarPath.getFileName().toString(), - content - ); - } - byte[] modJsonBytes; try { @@ -92,6 +54,44 @@ public record AccessWidenerFile( } if (modJsonBytes == null) { + if (ZipUtils.contains(modJarPath, "architectury.common.json")) { + String awPath = null; + byte[] commonJsonBytes; + + try { + commonJsonBytes = ZipUtils.unpackNullable(modJarPath, "architectury.common.json"); + } catch (IOException e) { + throw new UncheckedIOException("Failed to read access-widener file from: " + modJarPath.toAbsolutePath(), e); + } + + if (commonJsonBytes != null) { + JsonObject jsonObject = new Gson().fromJson(new String(commonJsonBytes, StandardCharsets.UTF_8), JsonObject.class); + + if (jsonObject.has("accessWidener")) { + awPath = jsonObject.get("accessWidener").getAsString(); + } else { + throw new IllegalArgumentException("The architectury.common.json file does not contain an accessWidener field."); + } + } else { + // ??????????? + throw new IllegalArgumentException("The architectury.common.json file does not exist."); + } + + byte[] content; + + try { + content = ZipUtils.unpack(modJarPath, awPath); + } catch (IOException e) { + throw new UncheckedIOException("Could not find access widener file (%s) defined in the architectury.common.json file of %s".formatted(awPath, modJarPath.toAbsolutePath()), e); + } + + return new AccessWidenerFile( + awPath, + modJarPath.getFileName().toString(), + content + ); + } + return null; } |