-
Notifications
You must be signed in to change notification settings - Fork 848
feat: 优化世界管理 #5842
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?
feat: 优化世界管理 #5842
Changes from all commits
78db75d
efdc263
0a2225e
320a9f4
ff993eb
72a1d76
e60d3ab
ce3bb09
bedf2d9
7b8ced5
5f80dc6
bbbe526
a7814fb
ed0eddf
00ddeb1
0a3fd64
a3f5e2e
5a128b6
5aed9d7
3e8a253
792727b
87e1970
db5704e
77e606c
7f40758
239eec0
b3631f0
91a5c7d
e441fef
50d7b1e
f7ee941
91cc515
06e2525
32227a5
a95c861
f947be5
3a69c01
86e3cf2
a131be1
8f10b6c
3b6e9f5
e9bbd0c
b2629f4
547e7d8
7fbcd46
e41f114
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,171 @@ | ||||||
| /* | ||||||
| * Hello Minecraft! Launcher | ||||||
| * Copyright (C) 2026 huangyuhui <huanghongxun2008@126.com> and contributors | ||||||
| * | ||||||
| * This program is free software: you can redistribute it and/or modify | ||||||
| * it under the terms of the GNU General Public License as published by | ||||||
| * the Free Software Foundation, either version 3 of the License, or | ||||||
| * (at your option) any later version. | ||||||
| * | ||||||
| * This program is distributed in the hope that it will be useful, | ||||||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||||
| * GNU General Public License for more details. | ||||||
| * | ||||||
| * You should have received a copy of the GNU General Public License | ||||||
| * along with this program. If not, see <https://www.gnu.org/licenses/>. | ||||||
| */ | ||||||
| package org.jackhuang.hmcl.ui.versions; | ||||||
|
|
||||||
| import javafx.scene.image.Image; | ||||||
| import org.glavo.nbt.io.NBTCodec; | ||||||
| import org.glavo.nbt.tag.CompoundTag; | ||||||
| import org.glavo.nbt.tag.LongTag; | ||||||
| import org.glavo.nbt.tag.StringTag; | ||||||
| import org.glavo.nbt.tag.TagType; | ||||||
| import org.jackhuang.hmcl.game.World; | ||||||
| import org.jackhuang.hmcl.util.io.CompressingUtils; | ||||||
| import org.jackhuang.hmcl.util.io.FileUtils; | ||||||
| import org.jackhuang.hmcl.util.io.Unzipper; | ||||||
| import org.jackhuang.hmcl.util.versioning.GameVersionNumber; | ||||||
| import org.jetbrains.annotations.Nullable; | ||||||
|
|
||||||
| import java.io.IOException; | ||||||
| import java.io.InputStream; | ||||||
| import java.nio.file.FileSystem; | ||||||
| import java.nio.file.Files; | ||||||
| import java.nio.file.Path; | ||||||
| import java.util.List; | ||||||
|
|
||||||
| import static org.jackhuang.hmcl.util.logging.Logger.LOG; | ||||||
|
|
||||||
| /// @author mineDiamond | ||||||
| public final class ImportableWorld { | ||||||
| private final Path sourcePath; | ||||||
| private final String fileName; | ||||||
| private final boolean isArchive; | ||||||
| private final boolean hasTopLevelDirectory; | ||||||
| private String worldName; | ||||||
| private @Nullable GameVersionNumber gameVersion; | ||||||
| private @Nullable Image icon; | ||||||
|
|
||||||
| public ImportableWorld(Path sourcePath) throws IOException { | ||||||
| if (Files.isRegularFile(sourcePath)) { | ||||||
| this.sourcePath = sourcePath; | ||||||
| this.isArchive = true; | ||||||
|
|
||||||
| try (FileSystem fs = CompressingUtils.readonly(this.sourcePath).setAutoDetectEncoding(true).build()) { | ||||||
| Path root; | ||||||
| if (Files.isRegularFile(fs.getPath("/level.dat"))) { | ||||||
| root = fs.getPath("/"); | ||||||
| hasTopLevelDirectory = false; | ||||||
| fileName = FileUtils.getName(this.sourcePath); | ||||||
| } else { | ||||||
| List<Path> files = Files.list(fs.getPath("/")).toList(); | ||||||
| if (files.size() != 1 || !Files.isDirectory(files.get(0))) { | ||||||
| throw new IOException("Not a valid world zip file"); | ||||||
|
Comment on lines
+64
to
+66
|
||||||
| } | ||||||
|
|
||||||
| root = files.get(0); | ||||||
| hasTopLevelDirectory = true; | ||||||
| fileName = FileUtils.getName(root); | ||||||
| } | ||||||
|
|
||||||
| Path levelDat = root.resolve("level.dat"); | ||||||
| if (!Files.exists(levelDat)) { //version 20w14infinite | ||||||
| levelDat = root.resolve("special_level.dat"); | ||||||
| } | ||||||
| if (!Files.exists(levelDat)) { | ||||||
| throw new IOException("Not a valid world zip file since level.dat or special_level.dat cannot be found."); | ||||||
| } | ||||||
| checkAndLoadLevelData(levelDat); | ||||||
|
|
||||||
| Path iconFile = root.resolve("icon.png"); | ||||||
| if (Files.isRegularFile(iconFile)) { | ||||||
| try (InputStream inputStream = Files.newInputStream(iconFile)) { | ||||||
| icon = new Image(inputStream, 64, 64, true, false); | ||||||
| if (icon.isError()) | ||||||
| throw icon.getException(); | ||||||
| } catch (Exception e) { | ||||||
| LOG.warning("Failed to load world icon", e); | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
| } else if (Files.isDirectory(sourcePath)) { | ||||||
| this.sourcePath = sourcePath; | ||||||
| fileName = FileUtils.getName(this.sourcePath); | ||||||
| this.isArchive = false; | ||||||
| this.hasTopLevelDirectory = false; | ||||||
|
|
||||||
| Path levelDatPath = this.sourcePath.resolve("level.dat"); | ||||||
| if (!Files.exists(levelDatPath)) { // version 20w14infinite | ||||||
| levelDatPath = this.sourcePath.resolve("special_level.dat"); | ||||||
| } | ||||||
| if (!Files.exists(levelDatPath)) { | ||||||
| throw new IOException("Not a valid world directory since level.dat or special_level.dat cannot be found."); | ||||||
| } | ||||||
| checkAndLoadLevelData(levelDatPath); | ||||||
| } else { | ||||||
| throw new IOException("Path " + sourcePath + " cannot be recognized as a archive Minecraft world"); | ||||||
|
||||||
| throw new IOException("Path " + sourcePath + " cannot be recognized as a archive Minecraft world"); | |
| throw new IOException("Path " + sourcePath + " cannot be recognized as an archive Minecraft world"); |
Uh oh!
There was an error while loading. Please reload this page.