-
Notifications
You must be signed in to change notification settings - Fork 820
简化 DefaultLauncher#getEnvVars 与 McbbsModpackExportTask#execute
#5271
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR attempts to simplify two methods by replacing explicit conditional checks with loop-based iteration. It adds a new getLibraries() helper method to LibraryAnalyzer that returns all detected library types.
Changes:
- Added
getLibraries()method toLibraryAnalyzerthat returns all library types present in the analyzed version - Refactored
McbbsModpackExportTask#executeto use a loop overgetLibraries()instead of explicitifPresent()calls for each library type - Refactored
DefaultLauncher#getEnvVarsto use a loop overgetModLoaders()instead of explicit checks for each mod loader type
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| HMCLCore/src/main/java/org/jackhuang/hmcl/download/LibraryAnalyzer.java | Adds new getLibraries() method to return all detected library types |
| HMCLCore/src/main/java/org/jackhuang/hmcl/mod/mcbbs/McbbsModpackExportTask.java | Replaces explicit library type checks with loop over getLibraries() |
| HMCLCore/src/main/java/org/jackhuang/hmcl/launch/DefaultLauncher.java | Replaces explicit mod loader checks with loop over getModLoaders(), adds ModLoaderType import |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| else if (type == ModLoaderType.LEGACY_FABRIC) env.put("INST_LEGACYFABRIC", "1"); | ||
| else env.put("INST_" + type.name().toUpperCase(Locale.ROOT), "1"); | ||
| } | ||
|
|
Copilot
AI
Jan 23, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This refactoring breaks functionality for LITE_LOADER and OPTIFINE:
-
LITE_LOADER: The ModLoaderType enum value is
LITE_LOADER, sotype.name().toUpperCase()will produce "LITE_LOADER", resulting in environment variableINST_LITE_LOADER. However, the old code setINST_LITELOADER(no underscore). This is a breaking change. -
OPTIFINE: The LibraryType.OPTIFINE has
modLoader = falsein its definition (line 304 of LibraryAnalyzer.java), so it won't be included ingetModLoaders()results. The old code setINST_OPTIFINE, but the new code will not set this variable at all.
To fix this, you should either:
- Add special cases for LITE_LOADER and handle OPTIFINE separately, or
- Iterate over all libraries that need environment variables (not just mod loaders) and use a mapping function to handle the naming differences
| else if (type == ModLoaderType.LEGACY_FABRIC) env.put("INST_LEGACYFABRIC", "1"); | |
| else env.put("INST_" + type.name().toUpperCase(Locale.ROOT), "1"); | |
| } | |
| else if (type == ModLoaderType.LEGACY_FABRIC) env.put("INST_LEGACYFABRIC", "1"); | |
| else if (type == ModLoaderType.LITE_LOADER) env.put("INST_LITELOADER", "1"); | |
| else env.put("INST_" + type.name().toUpperCase(Locale.ROOT), "1"); | |
| } | |
| if (analyzer.hasOptiFine()) { | |
| env.put("INST_OPTIFINE", "1"); | |
| } |
| for (LibraryAnalyzer.LibraryType type : analyzer.getLibraries()) { | ||
| if (type == MINECRAFT) addons.add(new McbbsModpackManifest.Addon(MINECRAFT.getPatchId(), gameVersion)); | ||
| else addons.add(new McbbsModpackManifest.Addon(type.getPatchId(), analyzer.getVersion(type).orElseThrow())); | ||
| } |
Copilot
AI
Jan 23, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This refactoring introduces multiple critical issues:
-
Potential runtime exceptions: Using
orElseThrow()can cause exceptions even whenhas(type)is true, becausegetVersion()can return an empty Optional if the version string is null in the internal map. -
Changed behavior - includes unintended library types: The old code explicitly handled specific library types (MINECRAFT, FORGE, CLEANROOM, NEO_FORGE, LITELOADER, OPTIFINE, FABRIC, QUILT, LEGACY_FABRIC). The new code includes ALL library types, which means it will also add FABRIC_API, QUILT_API, LEGACY_FABRIC_API, and BOOTSTRAP_LAUNCHER to the manifest. These were not included before and could break the modpack format.
To fix these issues:
- Replace
orElseThrow()with safe handling like filtering out libraries without versions first, or using a default value - Filter library types to only include the relevant ones that should be in the manifest, similar to the explicit list in the old code
No description provided.