Skip to content

Commit ee652f6

Browse files
authored
优化原理图管理功能 (#3978)
1 parent d317844 commit ee652f6

5 files changed

Lines changed: 75 additions & 40 deletions

File tree

HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/VersionPage.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ protected Skin(VersionPage control) {
299299
new IconedMenuItem(SVG.SETTINGS, i18n("folder.config"), () -> control.onBrowse("config"), browsePopup),
300300
new IconedMenuItem(SVG.TEXTURE, i18n("folder.resourcepacks"), () -> control.onBrowse("resourcepacks"), browsePopup),
301301
new IconedMenuItem(SVG.WB_SUNNY, i18n("folder.shaderpacks"), () -> control.onBrowse("shaderpacks"), browsePopup),
302+
new IconedMenuItem(SVG.SCHEMA, i18n("folder.schematics"), () -> control.onBrowse("schematics"), browsePopup),
302303
new IconedMenuItem(SVG.SCREENSHOT_MONITOR, i18n("folder.screenshots"), () -> control.onBrowse("screenshots"), browsePopup),
303304
new IconedMenuItem(SVG.PUBLIC, i18n("folder.saves"), () -> control.onBrowse("saves"), browsePopup),
304305
new IconedMenuItem(SVG.SCRIPT, i18n("folder.logs"), () -> control.onBrowse("logs"), browsePopup)

HMCL/src/main/resources/assets/lang/I18N.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,7 @@ folder.mod=Mods
435435
folder.resourcepacks=Resource Packs
436436
folder.shaderpacks=Shader Packs
437437
folder.saves=Saves
438+
folder.schematics=Schematics
438439
folder.screenshots=Screenshots
439440

440441
game=Games

HMCL/src/main/resources/assets/lang/I18N_zh.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,7 @@ folder.mod=模組目錄
406406
folder.resourcepacks=資源包目錄
407407
folder.shaderpacks=著色器包目錄
408408
folder.saves=遊戲存檔目錄
409+
folder.schematics=原理圖目錄
409410
folder.screenshots=截圖目錄
410411

411412
game=遊戲

HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ folder.mod=模组文件夹
415415
folder.resourcepacks=资源包文件夹
416416
folder.shaderpacks=光影包文件夹
417417
folder.saves=存档文件夹
418+
folder.schematics=原理图文件夹
418419
folder.screenshots=截图文件夹
419420

420421
game=游戏

HMCLCore/src/main/java/org/jackhuang/hmcl/schematic/LitematicFile.java

Lines changed: 71 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -64,100 +64,131 @@ public static LitematicFile load(Path file) throws IOException {
6464
else if (!(versionTag instanceof IntTag))
6565
throw new IOException("Version tag is not an integer");
6666

67-
6867
Tag metadataTag = root.get("Metadata");
6968
if (metadataTag == null)
7069
throw new IOException("Metadata tag not found");
7170
else if (!(metadataTag instanceof CompoundTag))
7271
throw new IOException("Metadata tag is not a compound tag");
7372

74-
return new LitematicFile(file, root);
73+
int regions = 0;
74+
Tag regionsTag = root.get("Regions");
75+
if (regionsTag instanceof CompoundTag)
76+
regions = ((CompoundTag) regionsTag).size();
77+
78+
return new LitematicFile(file, (CompoundTag) metadataTag,
79+
((IntTag) versionTag).getValue(),
80+
tryGetInt(root.get("SubVersion")),
81+
tryGetInt(root.get("MinecraftDataVersion")),
82+
regions
83+
);
7584
}
7685

7786
private final @NotNull Path file;
78-
private final @NotNull CompoundTag root;
7987

80-
private LitematicFile(@NotNull Path file, @NotNull CompoundTag root) {
88+
private final int version;
89+
private final int subVersion;
90+
private final int minecraftDataVersion;
91+
private final int regionCount;
92+
private final int[] previewImageData;
93+
private final String name;
94+
private final String author;
95+
private final String description;
96+
private final Instant timeCreated;
97+
private final Instant timeModified;
98+
private final int totalBlocks;
99+
private final int totalVolume;
100+
private final Point3D enclosingSize;
101+
102+
private LitematicFile(@NotNull Path file, @NotNull CompoundTag metadata,
103+
int version, int subVersion, int minecraftDataVersion, int regionCount) {
81104
this.file = file;
82-
this.root = root;
83-
}
105+
this.version = version;
106+
this.subVersion = subVersion;
107+
this.minecraftDataVersion = minecraftDataVersion;
108+
this.regionCount = regionCount;
109+
110+
Tag previewImageData = metadata.get("PreviewImageData");
111+
this.previewImageData = previewImageData instanceof IntArrayTag
112+
? ((IntArrayTag) previewImageData).getValue()
113+
: null;
114+
115+
this.name = tryGetString(metadata.get("Name"));
116+
this.author = tryGetString(metadata.get("Author"));
117+
this.description = tryGetString(metadata.get("Description"));
118+
this.timeCreated = tryGetLongTimestamp(metadata.get("TimeCreated"));
119+
this.timeModified = tryGetLongTimestamp(metadata.get("TimeModified"));
120+
this.totalBlocks = tryGetInt(metadata.get("TotalBlocks"));
121+
this.totalVolume = tryGetInt(metadata.get("TotalVolume"));
122+
123+
124+
Point3D enclosingSize = null;
125+
Tag enclosingSizeTag = metadata.get("EnclosingSize");
126+
if (enclosingSizeTag instanceof CompoundTag) {
127+
CompoundTag list = (CompoundTag) enclosingSizeTag;
128+
int x = tryGetInt(list.get("x"));
129+
int y = tryGetInt(list.get("y"));
130+
int z = tryGetInt(list.get("z"));
131+
132+
if (x >= 0 && y >= 0 && z >= 0)
133+
enclosingSize = new Point3D(x, y, z);
134+
}
135+
this.enclosingSize = enclosingSize;
84136

85-
private @NotNull CompoundTag getMetadata() {
86-
return root.get("Metadata");
87137
}
88138

89139
public @NotNull Path getFile() {
90140
return file;
91141
}
92142

93143
public int getVersion() {
94-
return root.<IntTag>get("Version").getValue();
144+
return version;
95145
}
96146

97147
public int getSubVersion() {
98-
return tryGetInt(root.get("SubVersion"));
148+
return subVersion;
99149
}
100150

101151
public int getMinecraftDataVersion() {
102-
return tryGetInt(root.get("MinecraftDataVersion"));
152+
return minecraftDataVersion;
103153
}
104154

105155
public int[] getPreviewImageData() {
106-
Tag previewImageData = getMetadata().get("PreviewImageData");
107-
if (previewImageData instanceof IntArrayTag) {
108-
return ((IntArrayTag) previewImageData).getValue().clone();
109-
} else {
110-
return null;
111-
}
156+
return previewImageData != null ? previewImageData.clone() : null;
112157
}
113158

114159
public String getName() {
115-
return tryGetString(getMetadata().get("Name"));
160+
return name;
116161
}
117162

118163
public String getAuthor() {
119-
return tryGetString(getMetadata().get("Author"));
164+
return author;
120165
}
121166

122167
public String getDescription() {
123-
return tryGetString(getMetadata().get("Description"));
168+
return description;
124169
}
125170

126171
public Instant getTimeCreated() {
127-
return tryGetLongTimestamp(getMetadata().get("TimeCreated"));
172+
return timeCreated;
128173
}
129174

130175
public Instant getTimeModified() {
131-
return tryGetLongTimestamp(getMetadata().get("TimeModified"));
176+
return timeModified;
132177
}
133178

134179
public int getTotalBlocks() {
135-
return tryGetInt(getMetadata().get("TotalBlocks"));
180+
return totalBlocks;
136181
}
137182

138183
public int getTotalVolume() {
139-
return tryGetInt(getMetadata().get("TotalVolume"));
184+
return totalVolume;
140185
}
141186

142187
public Point3D getEnclosingSize() {
143-
Tag enclosingSizeTag = getMetadata().get("EnclosingSize");
144-
if (enclosingSizeTag instanceof CompoundTag) {
145-
CompoundTag list = (CompoundTag) enclosingSizeTag;
146-
int x = tryGetInt(list.get("x"));
147-
int y = tryGetInt(list.get("y"));
148-
int z = tryGetInt(list.get("z"));
149-
150-
if (x >= 0 && y >= 0 && z >= 0)
151-
return new Point3D(x, y, z);
152-
}
153-
154-
return null;
188+
return enclosingSize;
155189
}
156190

157191
public int getRegionCount() {
158-
Tag regions = root.get("Regions");
159-
if (regions instanceof CompoundTag)
160-
return ((CompoundTag) regions).size();
161-
else return 0;
192+
return regionCount;
162193
}
163194
}

0 commit comments

Comments
 (0)