mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-09-10 12:26:16 -04:00
parent
e0764d6f0c
commit
af3719403d
@ -112,11 +112,29 @@ public final class ForgeNewModMetadata {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final int ACC_FORGE = 0x01;
|
||||||
|
|
||||||
|
private static final int ACC_NEO_FORGED = 0x02;
|
||||||
|
|
||||||
public static LocalModFile fromFile(ModManager modManager, Path modFile, FileSystem fs) throws IOException, JsonParseException {
|
public static LocalModFile fromFile(ModManager modManager, Path modFile, FileSystem fs) throws IOException, JsonParseException {
|
||||||
Path modstoml = fs.getPath("META-INF/mods.toml");
|
try {
|
||||||
if (Files.notExists(modstoml))
|
return fromFile0("META-INF/mods.toml", ACC_FORGE | ACC_NEO_FORGED, ModLoaderType.FORGE, modManager, modFile, fs);
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
return fromFile0("META-INF/neoforge.mods.toml", ACC_NEO_FORGED, ModLoaderType.NEO_FORGED, modManager, modFile, fs);
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
}
|
||||||
|
|
||||||
throw new IOException("File " + modFile + " is not a Forge 1.13+ or NeoForge mod.");
|
throw new IOException("File " + modFile + " is not a Forge 1.13+ or NeoForge mod.");
|
||||||
Toml toml = new Toml().read(FileUtils.readText(modstoml));
|
}
|
||||||
|
|
||||||
|
private static LocalModFile fromFile0(String tomlPath, int loaderACC, ModLoaderType defaultLoader, ModManager modManager, Path modFile, FileSystem fs) throws IOException, JsonParseException {
|
||||||
|
Path modToml = fs.getPath(tomlPath);
|
||||||
|
if (Files.notExists(modToml))
|
||||||
|
throw new IOException("File " + modFile + " is not a Forge 1.13+ or NeoForge mod.");
|
||||||
|
Toml toml = new Toml().read(FileUtils.readText(modToml));
|
||||||
ForgeNewModMetadata metadata = toml.to(ForgeNewModMetadata.class);
|
ForgeNewModMetadata metadata = toml.to(ForgeNewModMetadata.class);
|
||||||
if (metadata == null || metadata.getMods().isEmpty())
|
if (metadata == null || metadata.getMods().isEmpty())
|
||||||
throw new IOException("Mod " + modFile + " `mods.toml` is malformed..");
|
throw new IOException("Mod " + modFile + " `mods.toml` is malformed..");
|
||||||
@ -132,28 +150,34 @@ public final class ForgeNewModMetadata {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ModLoaderType modLoaderType = analyzeModLoader(toml, mod.getModId());
|
ModLoaderType type = analyzeLoader(toml, mod.getModId(), loaderACC, defaultLoader);
|
||||||
if (modLoaderType == null) {
|
|
||||||
throw new IOException("File " + modFile + " is not a Forge 1.13+ or NeoForge mod.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return new LocalModFile(modManager, modManager.getLocalMod(mod.getModId(), modLoaderType), modFile, mod.getDisplayName(), new LocalModFile.Description(mod.getDescription()),
|
return new LocalModFile(modManager, modManager.getLocalMod(mod.getModId(), type), modFile, mod.getDisplayName(), new LocalModFile.Description(mod.getDescription()),
|
||||||
mod.getAuthors(), jarVersion == null ? mod.getVersion() : mod.getVersion().replace("${file.jarVersion}", jarVersion), "",
|
mod.getAuthors(), jarVersion == null ? mod.getVersion() : mod.getVersion().replace("${file.jarVersion}", jarVersion), "",
|
||||||
mod.getDisplayURL(),
|
mod.getDisplayURL(),
|
||||||
metadata.getLogoFile());
|
metadata.getLogoFile());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ModLoaderType analyzeModLoader(Toml toml, String modID) {
|
private static ModLoaderType analyzeLoader(Toml toml, String modID, int loaderACC, ModLoaderType defaultLoader) throws IOException {
|
||||||
List<HashMap<String, Object>> dependencies = toml.getList("dependencies." + modID);
|
List<HashMap<String, Object>> dependencies = toml.getList("dependencies." + modID);
|
||||||
if (dependencies != null) {
|
if (dependencies != null) {
|
||||||
for (HashMap<String, Object> dependency : dependencies) {
|
for (HashMap<String, Object> dependency : dependencies) {
|
||||||
switch ((String) dependency.get("modId")) {
|
switch ((String) dependency.get("modId")) {
|
||||||
case "forge": return ModLoaderType.FORGE;
|
case "forge": return checkLoaderACC(loaderACC, ACC_FORGE, ModLoaderType.FORGE);
|
||||||
case "neoforge": return ModLoaderType.NEO_FORGED;
|
case "neoforge": return checkLoaderACC(loaderACC, ACC_NEO_FORGED, ModLoaderType.NEO_FORGED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
// ??? I have no idea why some of the Forge mods doesn't provide this key.
|
||||||
|
return defaultLoader;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ModLoaderType checkLoaderACC(int current, int target, ModLoaderType res) throws IOException {
|
||||||
|
if ((target & current) != 0) {
|
||||||
|
return res;
|
||||||
|
} else {
|
||||||
|
throw new IOException("Mismatched loader.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user