fix neoforge

This commit is contained in:
Tungstend 2024-01-13 19:30:46 +08:00
parent b9d2f8840f
commit ac3851d8e4
2 changed files with 29 additions and 7 deletions

View File

@ -100,8 +100,9 @@ public final class LibraryAnalyzer implements Iterable<LibraryAnalyzer.LibraryMa
if (type == null) return version; if (type == null) return version;
List<Library> libraries = new ArrayList<>(); List<Library> libraries = new ArrayList<>();
for (Library library : version.getLibraries()) { List<Library> rawLibraries = version.getLibraries();
if (type.matchLibrary(library)) { for (Library library : rawLibraries) {
if (type.matchLibrary(library, rawLibraries)) {
// skip // skip
} else { } else {
libraries.add(library); libraries.add(library);
@ -136,9 +137,10 @@ public final class LibraryAnalyzer implements Iterable<LibraryAnalyzer.LibraryMa
Map<String, Pair<Library, String>> libraries = new HashMap<>(); Map<String, Pair<Library, String>> libraries = new HashMap<>();
for (Library library : version.resolve(null).getLibraries()) { List<Library> rawLibraries = version.resolve(null).getLibraries();
for (Library library : rawLibraries) {
for (LibraryType type : LibraryType.values()) { for (LibraryType type : LibraryType.values()) {
if (type.matchLibrary(library)) { if (type.matchLibrary(library, rawLibraries)) {
libraries.put(type.getPatchId(), pair(library, type.patchVersion(version, library.getVersion()))); libraries.put(type.getPatchId(), pair(library, type.patchVersion(version, library.getVersion())));
break; break;
} }
@ -186,10 +188,27 @@ public final class LibraryAnalyzer implements Iterable<LibraryAnalyzer.LibraryMa
} }
return super.patchVersion(gameVersion, libraryVersion); return super.patchVersion(gameVersion, libraryVersion);
} }
@Override
public boolean matchLibrary(Library library, List<Library> libraries) {
for (Library l : libraries) {
if (NEO_FORGE.matchLibrary(l, libraries)) {
return false;
}
}
return super.matchLibrary(library, libraries);
}
}, },
NEO_FORGE(true, "neoforge", Pattern.compile("net\\.neoforged\\.fancymodloader"), Pattern.compile("(core|loader)"), ModLoaderType.NEO_FORGED) { NEO_FORGE(true, "neoforge", Pattern.compile("net\\.neoforged\\.fancymodloader"), Pattern.compile("(core|loader)"), ModLoaderType.NEO_FORGED) {
private final Pattern NEO_FORGE_VERSION_MATCHER = Pattern.compile("^([0-9.]+)-(?<forge>[0-9.]+)(-([0-9.]+))?$");
@Override @Override
public String patchVersion(Version gameVersion, String libraryVersion) { public String patchVersion(Version gameVersion, String libraryVersion) {
Matcher matcher = NEO_FORGE_VERSION_MATCHER.matcher(libraryVersion);
if (matcher.find()) {
return matcher.group("forge");
}
String res = scanVersion(gameVersion); String res = scanVersion(gameVersion);
if (res != null) { if (res != null) {
return res; return res;
@ -267,7 +286,7 @@ public final class LibraryAnalyzer implements Iterable<LibraryAnalyzer.LibraryMa
return null; return null;
} }
public boolean matchLibrary(Library library) { public boolean matchLibrary(Library library, List<Library> libraries) {
return group.matcher(library.getGroupId()).matches() && artifact.matcher(library.getArtifactId()).matches(); return group.matcher(library.getGroupId()).matches() && artifact.matcher(library.getArtifactId()).matches();
} }

View File

@ -90,7 +90,7 @@ public final class NeoForgeInstallTask extends Task<Version> {
try (FileSystem fs = CompressingUtils.createReadOnlyZipFileSystem(installer)) { try (FileSystem fs = CompressingUtils.createReadOnlyZipFileSystem(installer)) {
String installProfileText = FileUtils.readText(fs.getPath("install_profile.json")); String installProfileText = FileUtils.readText(fs.getPath("install_profile.json"));
Map<?, ?> installProfile = JsonUtils.fromNonNullJson(installProfileText, Map.class); Map<?, ?> installProfile = JsonUtils.fromNonNullJson(installProfileText, Map.class);
if (LibraryAnalyzer.LibraryType.FORGE.getPatchId().equals(installProfile.get("profile")) && Files.exists(fs.getPath("META-INF/NEOFORGE.RSA"))) { if (LibraryAnalyzer.LibraryType.FORGE.getPatchId().equals(installProfile.get("profile")) && (Files.exists(fs.getPath("META-INF/NEOFORGE.RSA")) || installProfileText.contains("neoforge"))) {
ForgeNewInstallProfile profile = JsonUtils.fromNonNullJson(installProfileText, ForgeNewInstallProfile.class); ForgeNewInstallProfile profile = JsonUtils.fromNonNullJson(installProfileText, ForgeNewInstallProfile.class);
if (!gameVersion.get().equals(profile.getMinecraft())) if (!gameVersion.get().equals(profile.getMinecraft()))
throw new VersionMismatchException(profile.getMinecraft(), gameVersion.get()); throw new VersionMismatchException(profile.getMinecraft(), gameVersion.get());
@ -98,7 +98,10 @@ public final class NeoForgeInstallTask extends Task<Version> {
if (!neoForgeVersion.getId().equals(LibraryAnalyzer.LibraryType.FORGE.getPatchId()) || neoForgeVersion.getVersion() == null) { if (!neoForgeVersion.getId().equals(LibraryAnalyzer.LibraryType.FORGE.getPatchId()) || neoForgeVersion.getVersion() == null) {
throw new IOException("Invalid neoforge version."); throw new IOException("Invalid neoforge version.");
} }
return neoForgeVersion.setId(LibraryAnalyzer.LibraryType.NEO_FORGE.getPatchId()).setVersion(neoForgeVersion.getVersion().replace(LibraryAnalyzer.LibraryType.FORGE.getPatchId(), LibraryAnalyzer.LibraryType.NEO_FORGE.getPatchId())); return neoForgeVersion.setId(LibraryAnalyzer.LibraryType.NEO_FORGE.getPatchId())
.setVersion(
removePrefix(neoForgeVersion.getVersion().replace(LibraryAnalyzer.LibraryType.FORGE.getPatchId(), ""), "-")
);
}); });
} else if (LibraryAnalyzer.LibraryType.NEO_FORGE.getPatchId().equals(installProfile.get("profile")) || "NeoForge".equals(installProfile.get("profile"))) { } else if (LibraryAnalyzer.LibraryType.NEO_FORGE.getPatchId().equals(installProfile.get("profile")) || "NeoForge".equals(installProfile.get("profile"))) {
ForgeNewInstallProfile profile = JsonUtils.fromNonNullJson(installProfileText, ForgeNewInstallProfile.class); ForgeNewInstallProfile profile = JsonUtils.fromNonNullJson(installProfileText, ForgeNewInstallProfile.class);