feat:增强数据包/资源包mcmeta的解析能力 - #4612
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR enhances Minecraft datapack and resource pack description parsing to properly handle color codes and format versions. The changes improve the accuracy of color code processing and add support for pack version ranges (min_format/max_format).
- Fixed incorrect regex pattern that was matching invalid Minecraft color codes
- Added new
parseMinecraftColorCodesmethod to parse and preserve Minecraft color/format codes in text - Introduced
PackVersionrecord to support pack format version ranges with major.minor versioning
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| HMCLCore/src/main/java/org/jackhuang/hmcl/util/StringUtils.java | Fixed color code regex pattern bug, added new parseMinecraftColorCodes method for parsing Minecraft color/format codes, and minor whitespace cleanup |
| HMCLCore/src/main/java/org/jackhuang/hmcl/mod/modinfo/PackMcMeta.java | Added PackVersion record for version range support, refactored PackInfoDeserializer to parse JSON text components with color codes using the new parsing utility |
| HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/DatapackListPageSkin.java | Removed call to parseColorEscapes to preserve color codes in descriptions, replaced wildcard import with specific imports |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (!jsonArray.isEmpty() && jsonArray.get(0) instanceof JsonObject jsonObj && jsonObj.get("color") instanceof JsonPrimitive primitive) { | ||
| color = primitive.getAsString(); | ||
| } | ||
| } else if (json.isJsonArray()) { | ||
| JsonArray arr = json.getAsJsonArray(); | ||
| if (arr.size() == 0) { | ||
| return ""; | ||
| } else { | ||
| return parseText(arr.get(0)); | ||
|
|
||
| for (JsonElement childElement : jsonArray) { | ||
| parseComponent(childElement, parts, color); |
There was a problem hiding this comment.
The logic for extracting color from the first element of a JsonArray (lines 179-180) and then applying it to all child elements may not be correct. In Minecraft's JSON text format, each element in an array can have its own color. The color from the first element shouldn't necessarily apply to all subsequent elements. Consider whether this color extraction logic is needed at all, or if each child element should be parsed independently.
There was a problem hiding this comment.
这里copilot说的是错误的,文本组件中,第一个列表元素将成为根组件,同时也代表了第一个列表元素的样式会继承到所有后续组件中,即成为了整个文本组件的全局样式。见文本组件#组件继承
# Conflicts: # HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/DatapackListPageSkin.java
close #3952
min_format和max_format支持 参考资源包,数据包