修复无法识别部分 Forge 模组信息的问题 (#4654)

This commit is contained in:
Glavo
2025-10-11 21:27:48 +08:00
committed by GitHub
parent 74878bda0c
commit 8ad5d83946
3 changed files with 25 additions and 4 deletions

View File

@@ -124,12 +124,14 @@ public final class ModManager {
LocalModFile modInfo = null;
List<Exception> exceptions = new ArrayList<>();
try (FileSystem fs = CompressingUtils.createReadOnlyZipFileSystem(file)) {
for (ModMetadataReader reader : supportedReaders) {
try {
modInfo = reader.fromFile(this, file, fs);
break;
} catch (Exception ignore) {
} catch (Exception e) {
exceptions.add(e);
}
}
@@ -138,7 +140,7 @@ public final class ModManager {
try {
modInfo = reader.fromFile(this, file, fs);
break;
} catch (Exception ignore) {
} catch (Exception ignored) {
}
}
}
@@ -147,6 +149,12 @@ public final class ModManager {
}
if (modInfo == null) {
Exception exception = new Exception("Failed to read mod metadata");
for (Exception e : exceptions) {
exception.addSuppressed(e);
}
LOG.warning("Failed to read mod metadata", exception);
String fileNameWithoutExtension = FileUtils.getNameWithoutExtension(file);
modInfo = new LocalModFile(this,

View File

@@ -244,7 +244,19 @@ public final class ForgeNewModMetadata {
private static ModLoaderType analyzeLoader(Toml toml, String modID, ModLoaderType loader) throws IOException {
List<HashMap<String, Object>> dependencies = toml.getList("dependencies." + modID);
if (dependencies == null) {
dependencies = toml.getList("dependencies"); // ??? I have no idea why some of the Forge mods use [[dependencies]]
try {
dependencies = toml.getList("dependencies"); // ??? I have no idea why some of the Forge mods use [[dependencies]]
} catch (ClassCastException e) {
try {
Toml table = toml.getTable("dependencies");
if (table == null)
return loader;
dependencies = table.getList(modID);
} catch (Throwable ignored) {
}
}
if (dependencies == null) {
return loader;
}