From fbad4dff093993475d05714ebcf329db43eed1f6 Mon Sep 17 00:00:00 2001 From: friendlyhj Date: Mon, 3 Aug 2026 11:30:03 +0800 Subject: [PATCH] always scan Mod annotation --- .../mixinbooter/service/ModDiscoverer.java | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/main/java/zone/rong/mixinbooter/service/ModDiscoverer.java b/src/main/java/zone/rong/mixinbooter/service/ModDiscoverer.java index 43b84db..c864929 100644 --- a/src/main/java/zone/rong/mixinbooter/service/ModDiscoverer.java +++ b/src/main/java/zone/rong/mixinbooter/service/ModDiscoverer.java @@ -251,6 +251,8 @@ public static void discover() { return; } discovered = true; + + long startTime = System.currentTimeMillis(); Gson gson; try { gson = new GsonBuilder().setLenient().create(); @@ -275,7 +277,7 @@ public static void discover() { } catch (URISyntaxException ignored) { } } - LOGGER.info("Finished gathering {} mods...", modIdToFiles.keySet().size()); + LOGGER.info("Finished gathering {} mods, took {} ms.", modIdToFiles.keySet().size(), System.currentTimeMillis() - startTime); LOGGER.debug("Mods gathered: {}", String.join(", ", modIdToFiles.keySet())); } @@ -349,12 +351,13 @@ private static void scanJar(Gson gson, File jar) { } } ZipEntry entry = jarFile.getEntry("mcmod.info"); - List modIds = entry != null ? parseMcmodInfo(gson, jarFile.getInputStream(entry)) : Collections.emptyList(); - if (modIds.isEmpty()) { - String modId = scanModAnnotation(jarFile); - if (modId != null) { - modIds = Collections.singletonList(modId); - } + Set modIds = new HashSet<>(); + if (entry != null) { + parseMcmodInfo(gson, jarFile.getInputStream(entry), modIds); + } + String modAnnotationId = scanModAnnotation(jarFile); + if (modAnnotationId != null) { + modIds.add(modAnnotationId); } for (String modId : modIds) { recordMod(modId, jar); @@ -374,7 +377,7 @@ private static void recordMod(String modId, File source) { /** * Logs if a mod jar bundles its own Mixin engine of any fork variety. */ - private static void checkIfJarBundlesMixin(File jar, JarFile jarFile, List modIds) { + private static void checkIfJarBundlesMixin(File jar, JarFile jarFile, Set modIds) { if (modIds.isEmpty() || modIds.contains("mixinbooter")) { return; } @@ -383,9 +386,8 @@ private static void checkIfJarBundlesMixin(File jar, JarFile jarFile, List parseMcmodInfo(Gson gson, InputStream stream) { + private static void parseMcmodInfo(Gson gson, InputStream stream, Set ids) { try { - List ids = new ArrayList<>(); JsonElement root = gson.fromJson(new InputStreamReader(stream, StandardCharsets.UTF_8), JsonElement.class); if (root.isJsonArray()) { for (JsonElement element : root.getAsJsonArray()) { @@ -400,19 +402,16 @@ private static List parseMcmodInfo(Gson gson, InputStream stream) { } } } - return ids; } catch (Throwable t) { LOGGER.error("Failed to parse mcmod.info", t); } finally { IOUtils.closeQuietly(stream); } - return Collections.emptyList(); } /** * Scans the jar's classes for the first {@code @Mod} annotation and returns its {@code modid} - * or {@code null} if none declares one. This is the fallback for mods that declare their id via - * the annotation rather than {@code mcmod.info}. + * or {@code null} if none declares one. * Reads bytecode only and unreadable entries are skipped, the walk stops at the first match. */ private static String scanModAnnotation(JarFile jar) {