Skip to content

feat:增强数据包/资源包mcmeta的解析能力 - #4612

Merged
Glavo merged 20 commits into
HMCL-dev:mainfrom
Mine-diamond:fix-datapack
Nov 15, 2025
Merged

feat:增强数据包/资源包mcmeta的解析能力#4612
Glavo merged 20 commits into
HMCL-dev:mainfrom
Mine-diamond:fix-datapack

Conversation

@Mine-diamond

@Mine-diamond Mine-diamond commented Oct 5, 2025

Copy link
Copy Markdown
Contributor

close #3952

  • 添加1.21.9新字段min_formatmax_format支持 参考资源包数据包
  • 添加更完整的文本组件解析文本支持
  • 当无法解析mcmeta数据时尽量解析部分数据而不会崩溃或出错

Comment thread HMCLCore/src/main/java/org/jackhuang/hmcl/mod/modinfo/PackMcMeta.java Outdated
@Mine-diamond
Mine-diamond marked this pull request as ready for review October 6, 2025 13:24
@Glavo
Glavo requested a review from Copilot November 8, 2025 13:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 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 parseMinecraftColorCodes method to parse and preserve Minecraft color/format codes in text
  • Introduced PackVersion record 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.

Comment on lines +179 to +184
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);

Copilot AI Nov 8, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里copilot说的是错误的,文本组件中,第一个列表元素将成为根组件,同时也代表了第一个列表元素的样式会继承到所有后续组件中,即成为了整个文本组件的全局样式。见文本组件#组件继承

# Conflicts:
#	HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/DatapackListPageSkin.java
@Glavo
Glavo merged commit f13d53d into HMCL-dev:main Nov 15, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] 数据包管理页面出现错误

4 participants