Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
78db75d
feat: 现在复用WorldManagePage
Mine-diamond Mar 23, 2026
efdc263
feat: 优化只读模式实现
Mine-diamond Mar 23, 2026
0a2225e
feat: 修改单复数
Mine-diamond Mar 23, 2026
320a9f4
feat: 添加重命名文件功能(还有bug)
Mine-diamond Mar 24, 2026
ff993eb
feat: 修改世界时关闭锁
Mine-diamond Mar 24, 2026
72a1d76
feat: 修改世界锁管理机制
Mine-diamond Mar 24, 2026
e60d3ab
feat: 优化重命名世界功能
Mine-diamond Mar 24, 2026
ce3bb09
feat: 优化复制世界功能
Mine-diamond Mar 24, 2026
bedf2d9
feat: 现在快速启动不会退出世界管理窗口
Mine-diamond Mar 24, 2026
7b8ced5
feat: 优化锁机制
Mine-diamond Mar 24, 2026
5f80dc6
feat: 复制/重命名世界弹窗会将世界默认名称设为默认值
Mine-diamond Mar 24, 2026
bbbe526
feat: 复制世界弹窗当值为当前值时不再取消复制
Mine-diamond Mar 24, 2026
a7814fb
feat: 优化代码
Mine-diamond Mar 24, 2026
ed0eddf
feat: 优化代码
Mine-diamond Mar 24, 2026
00ddeb1
feat: 添加还原存档功能
Mine-diamond Mar 25, 2026
0a3fd64
fix: 修复还原世界位置错误的问题
Mine-diamond Mar 25, 2026
a3f5e2e
fix: 修复还原世界位置错误的问题
Mine-diamond Mar 25, 2026
5a128b6
feat: update
Mine-diamond Mar 25, 2026
5aed9d7
feat: 备份文件以倒序显示
Mine-diamond Mar 25, 2026
3e8a253
feat: 数据包不支持文本添加i18n
Mine-diamond Mar 25, 2026
792727b
fix: 修复世界解析错误后无法禁用的错误
Mine-diamond Mar 25, 2026
87e1970
feat: 优化代码
Mine-diamond Mar 25, 2026
db5704e
feat: 分离压缩包世界到ArchiveWorld中
Mine-diamond Mar 25, 2026
77e606c
feat: 优化恢复备份功能
Mine-diamond Mar 25, 2026
7f40758
fix: 修复复制世界逻辑的错误
Mine-diamond Mar 25, 2026
239eec0
fix: 修复复制/重命名世界时可能的错误
Mine-diamond Mar 25, 2026
b3631f0
fix: 世界锁错误/文件名修建错误
Mine-diamond Mar 25, 2026
91a5c7d
fix: 添加i18n
Mine-diamond Mar 25, 2026
e441fef
feat: 优化代码
Mine-diamond Mar 25, 2026
50d7b1e
feat: 优化WorldLock代码
Mine-diamond Mar 26, 2026
f7ee941
feat: 优化重命名世界弹窗,使用异步
Mine-diamond Mar 26, 2026
91cc515
feat: 优化备份还原功能
Mine-diamond Mar 26, 2026
06e2525
feat: 现在支持安装文件夹格式的世界
Mine-diamond Mar 26, 2026
32227a5
feat: 优化功能
Mine-diamond Mar 26, 2026
a95c861
feat: 拆分方法
Mine-diamond Mar 26, 2026
f947be5
feat: 添加WorldDataSection来存储世界nbt
Mine-diamond Mar 26, 2026
3a69c01
feat: 预防性添加main修改
Mine-diamond Mar 26, 2026
86e3cf2
Merge branch 'main' into one-world-manage-page
Mine-diamond Mar 26, 2026
a131be1
fix: 意外地合并错误
Mine-diamond Mar 26, 2026
8f10b6c
feat: 优化代码
Mine-diamond Mar 26, 2026
3b6e9f5
feat: 优化代码
Mine-diamond Mar 27, 2026
e9bbd0c
feat: 优化代码
Mine-diamond Mar 27, 2026
b2629f4
feat: 优化代码
Mine-diamond Mar 27, 2026
547e7d8
feat: 优化代码
Mine-diamond Mar 27, 2026
7fbcd46
fix: 修复一些问题
Mine-diamond Mar 28, 2026
e41f114
fix: 修复一些问题
Mine-diamond Mar 28, 2026
0b473bb
fix: 暂存
Mine-diamond Mar 29, 2026
fc09d0a
feat: 优化重命名逻辑
Mine-diamond Apr 9, 2026
d702b29
Merge branch 'main' into one-world-manage-page
Mine-diamond Apr 9, 2026
deacfeb
fix: 现在是否支持数据包也看游戏版本而不是存档版本了
Mine-diamond Apr 9, 2026
dbe04ad
fix: 修复错误
Mine-diamond Apr 9, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions HMCL/src/main/java/org/jackhuang/hmcl/ui/Controllers.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
import org.jackhuang.hmcl.ui.versions.GameListPage;
import org.jackhuang.hmcl.ui.versions.VersionPage;
import org.jackhuang.hmcl.ui.versions.Versions;
import org.jackhuang.hmcl.ui.versions.WorldManagePage;
import org.jackhuang.hmcl.util.*;
import org.jackhuang.hmcl.util.i18n.I18n;
import org.jackhuang.hmcl.util.i18n.SupportedLocale;
Expand Down Expand Up @@ -128,6 +129,7 @@ public final class Controllers {
});
private static LauncherSettingsPage settingsPage;
private static Lazy<TerracottaPage> terracottaPage = new Lazy<>(TerracottaPage::new);
private static Lazy<WorldManagePage> worldManagePage = new Lazy<>(WorldManagePage::new);

private Controllers() {
}
Expand Down Expand Up @@ -208,6 +210,11 @@ public static Node getTerracottaPage() {
return terracottaPage.get();
}

// FXThread
public static WorldManagePage getWorldManagePage() {
return worldManagePage.get();
}

// FXThread
public static DecoratorController getDecorator() {
return decorator;
Expand Down Expand Up @@ -635,6 +642,7 @@ public static void shutdown() {
accountListPage = null;
settingsPage = null;
terracottaPage = null;
worldManagePage = null;
decorator = null;
stage = null;
scene = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,11 @@ public PromptDialogPane(Builder builder) {
List<BooleanBinding> bindings = new ArrayList<>();
int rowIndex = 0;
for (Builder.Question<?> question : builder.questions) {
if (question instanceof Builder.StringQuestion) {
Builder.StringQuestion stringQuestion = (Builder.StringQuestion) question;
if (question instanceof Builder.StringQuestion stringQuestion) {
JFXTextField textField = new JFXTextField();
textField.textProperty().addListener((a, b, newValue) -> stringQuestion.value = textField.getText());
textField.setText(stringQuestion.value);
textField.setValidators(((Builder.StringQuestion) question).validators.toArray(new ValidatorBase[0]));
textField.setValidators(stringQuestion.validators.toArray(new ValidatorBase[0]));
if (stringQuestion.promptText != null) {
textField.setPromptText(stringQuestion.promptText);
}
Expand All @@ -73,35 +72,35 @@ public PromptDialogPane(Builder builder) {
if (StringUtils.isNotBlank(question.question.get())) {
body.addRow(rowIndex++, new Label(question.question.get()), textField);
} else {
GridPane.setColumnSpan(textField, 1);
GridPane.setColumnSpan(textField, 2);
body.addRow(rowIndex++, textField);
}
GridPane.setMargin(textField, new Insets(0, 0, 20, 0));
} else if (question instanceof Builder.BooleanQuestion) {
} else if (question instanceof Builder.BooleanQuestion booleanQuestion) {
HBox hBox = new HBox();
GridPane.setColumnSpan(hBox, 1);
GridPane.setColumnSpan(hBox, 2);
JFXCheckBox checkBox = new JFXCheckBox();
hBox.getChildren().setAll(checkBox);
HBox.setMargin(checkBox, new Insets(0, 0, 0, -10));
checkBox.setSelected(((Builder.BooleanQuestion) question).value);
checkBox.setSelected(booleanQuestion.value);
checkBox.selectedProperty().addListener((a, b, newValue) -> ((Builder.BooleanQuestion) question).value = newValue);
checkBox.setText(question.question.get());
body.addRow(rowIndex++, hBox);
} else if (question instanceof Builder.CandidatesQuestion) {
} else if (question instanceof Builder.CandidatesQuestion candidatesQuestion) {
JFXComboBox<String> comboBox = new JFXComboBox<>();
comboBox.getItems().setAll(((Builder.CandidatesQuestion) question).candidates);
comboBox.getItems().setAll(candidatesQuestion.candidates);
comboBox.getSelectionModel().selectedIndexProperty().addListener((a, b, newValue) ->
((Builder.CandidatesQuestion) question).value = newValue.intValue());
candidatesQuestion.value = newValue.intValue());
comboBox.getSelectionModel().select(0);
if (StringUtils.isNotBlank(question.question.get())) {
body.addRow(rowIndex++, new Label(question.question.get()), comboBox);
} else {
GridPane.setColumnSpan(comboBox, 1);
GridPane.setColumnSpan(comboBox, 2);
body.addRow(rowIndex++, comboBox);
}
} else if (question instanceof Builder.HintQuestion) {
HintPane pane = new HintPane();
GridPane.setColumnSpan(pane, 1);
GridPane.setColumnSpan(pane, 2);
pane.textProperty().bind(question.question);
body.addRow(rowIndex++, pane);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
package org.jackhuang.hmcl.ui.versions;

import javafx.beans.property.BooleanProperty;
import javafx.beans.property.ReadOnlyBooleanProperty;
import javafx.collections.ObservableList;
import javafx.scene.control.Skin;
import javafx.stage.FileChooser;
Expand Down Expand Up @@ -45,15 +45,12 @@
import static org.jackhuang.hmcl.util.logging.Logger.LOG;

public final class DataPackListPage extends ListPageBase<DataPackListPageSkin.DataPackInfoObject> implements WorldManagePage.WorldRefreshable {
private final World world;
private final DataPack dataPack;
final BooleanProperty readOnly;
private final WorldManagePage worldManagePage;
private World world;
private DataPack dataPack;

public DataPackListPage(WorldManagePage worldManagePage) {
world = worldManagePage.getWorld();
dataPack = new DataPack(world.getFile().resolve("datapacks"));
setItems(MappedObservableList.create(dataPack.getPacks(), DataPackListPageSkin.DataPackInfoObject::new));
readOnly = worldManagePage.readOnlyProperty();
this.worldManagePage = worldManagePage;
FXUtils.applyDragListener(this, it -> Objects.equals("zip", FileUtils.getExtension(it)),
this::installMultiDataPack, this::refresh);

Expand All @@ -62,7 +59,7 @@ public DataPackListPage(WorldManagePage worldManagePage) {

private void installMultiDataPack(List<Path> dataPackPath) {
dataPackPath.forEach(this::installSingleDataPack);
if (readOnly.get()) {
if (readOnlyProperty().get()) {
Controllers.showToast(i18n("datapack.reload.toast"));
}
}
Expand All @@ -80,13 +77,27 @@ protected Skin<?> createDefaultSkin() {
return new DataPackListPageSkin(this);
}

@Override
public void refresh() {
setLoading(true);
setFailedReason(null);
world = worldManagePage.getWorld();
if (!worldManagePage.currentWorldSupportDataPack.get()) {
setFailedReason(i18n("datapack.not_support.info"));
setLoading(false);
return;
}
dataPack = new DataPack(world.getFile().resolve("datapacks"));
setItems(MappedObservableList.create(dataPack.getPacks(), DataPackListPageSkin.DataPackInfoObject::new));
Task.runAsync(dataPack::loadFromDir)
.withRunAsync(Schedulers.javafx(), () -> setLoading(false))
.start();
}

public ReadOnlyBooleanProperty readOnlyProperty() {
return worldManagePage.readOnlyProperty();
}

public void add() {
FileChooser chooser = new FileChooser();
chooser.setTitle(i18n("datapack.add.title"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import javafx.beans.InvalidationListener;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.ReadOnlyBooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.collections.transformation.FilteredList;
import javafx.geometry.Insets;
Expand Down Expand Up @@ -95,7 +96,7 @@ final class DataPackListPageSkin extends SkinBase<DataPackListPage> {
ComponentList root = new ComponentList();
root.getStyleClass().add("no-padding");
listView = new JFXListView<>();
filteredList = new FilteredList<>(skinnable.getItems());
filteredList = new FilteredList<>(skinnable.itemsProperty());

{
toolbarPane = new TransitionPane();
Expand All @@ -119,9 +120,9 @@ final class DataPackListPageSkin extends SkinBase<DataPackListPage> {
skinnable.enableSelected(listView.getSelectionModel().getSelectedItems()));
JFXButton disableButton = createToolbarButton2(i18n("mods.disable"), SVG.CLOSE, () ->
skinnable.disableSelected(listView.getSelectionModel().getSelectedItems()));
removeButton.disableProperty().bind(getSkinnable().readOnly);
enableButton.disableProperty().bind(getSkinnable().readOnly);
disableButton.disableProperty().bind(getSkinnable().readOnly);
removeButton.disableProperty().bind(getSkinnable().readOnlyProperty());
enableButton.disableProperty().bind(getSkinnable().readOnlyProperty());
disableButton.disableProperty().bind(getSkinnable().readOnlyProperty());

selectingToolbar.getChildren().addAll(
removeButton,
Expand Down Expand Up @@ -163,6 +164,7 @@ final class DataPackListPageSkin extends SkinBase<DataPackListPage> {

FXUtils.onChangeAndOperate(listView.getSelectionModel().selectedItemProperty(),
selectedItem -> isSelecting.set(selectedItem != null));
toolbarPane.disableProperty().bind(skinnable.loadingProperty().or(skinnable.failedReasonProperty().isNotNull()));
root.getContent().add(toolbarPane);

updateBarByStateWeakListener = FXUtils.observeWeak(() -> {
Expand All @@ -180,8 +182,9 @@ final class DataPackListPageSkin extends SkinBase<DataPackListPage> {
SpinnerPane center = new SpinnerPane();
ComponentList.setVgrow(center, Priority.ALWAYS);
center.loadingProperty().bind(skinnable.loadingProperty());
center.failedReasonProperty().bind(skinnable.failedReasonProperty());

listView.setCellFactory(x -> new DataPackInfoListCell(listView, getSkinnable().readOnly));
listView.setCellFactory(x -> new DataPackInfoListCell(listView, getSkinnable().readOnlyProperty()));
listView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
this.listView.setItems(filteredList);

Expand Down Expand Up @@ -304,7 +307,7 @@ private final class DataPackInfoListCell extends MDListCell<DataPackInfoObject>
final TwoLineListItem content = new TwoLineListItem();
BooleanProperty booleanProperty;

DataPackInfoListCell(JFXListView<DataPackInfoObject> listView, BooleanProperty isReadOnlyProperty) {
DataPackInfoListCell(JFXListView<DataPackInfoObject> listView, ReadOnlyBooleanProperty isReadOnlyProperty) {
super(listView);

HBox container = new HBox(8);
Expand Down
147 changes: 147 additions & 0 deletions HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ImportableWorld.java
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

我觉得这个类的设计就很奇怪,尤其是 ImportableWorld 这个名字我认为非常不恰当。

我认为你可以把它改名叫 WorldInfo 之类的名字,或者修改 World 使其不可变,然后用新的可变类来管理对世界的修改。

Copy link
Copy Markdown
Contributor Author

@Mine-diamond Mine-diamond Apr 5, 2026

Choose a reason for hiding this comment

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

这个不是表达世界信息的类的,而是表达“即将被导入的世界的”,Import:导入,Importable:可导入的,为什么会认为是扩展的意思呢?
这个类的作用就是表示安装世界或在世界备份页面时的静态世界文件的,而World类现在仅表示在世界文件夹,可被世界管理页面管理的类的。

Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
/*
* 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.nio.file.FileSystem;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.stream.Stream;

/// @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 {
try (Stream<Path> stream = Files.list(fs.getPath("/"))) {
List<Path> files = stream.toList();
if (files.size() != 1 || !Files.isDirectory(files.get(0))) {
throw new IOException("Not a valid world zip file");
}

root = files.get(0);
hasTopLevelDirectory = true;
fileName = FileUtils.getName(root);
}
}

checkAndLoadLevelData(World.findLevelDatPath(root));
this.icon = World.loadIcon(root);
}
} else if (Files.isDirectory(sourcePath)) {
this.sourcePath = sourcePath;
fileName = FileUtils.getName(this.sourcePath);
this.isArchive = false;
this.hasTopLevelDirectory = false;

checkAndLoadLevelData(World.findLevelDatPath(this.sourcePath));
} else {
throw new IOException("Path " + sourcePath + " cannot be recognized as an archive Minecraft world");
}
}

private void checkAndLoadLevelData(Path levelDatPath) throws IOException {
CompoundTag levelData = NBTCodec.of().readTag(levelDatPath, TagType.COMPOUND);
if (!(levelData.get("Data") instanceof CompoundTag data))
throw new IOException("level.dat missing Data");

if (data.get("LevelName") instanceof StringTag levelNameTag) {
this.worldName = levelNameTag.getValue();
} else {
throw new IOException("level.dat missing LevelName");
}

if (data.get("Version") instanceof CompoundTag versionTag &&
versionTag.get("Name") instanceof StringTag nameTag) {
this.gameVersion = GameVersionNumber.asGameVersion(nameTag.getValue());
}

if (!(data.get("LastPlayed") instanceof LongTag))
throw new IOException("level.dat missing LastPlayed");
}

public Path getSourcePath() {
return sourcePath;
}

public String getFileName() {
return fileName;
}

public boolean hasTopLevelDirectory() {
return hasTopLevelDirectory;
}

public String getWorldName() {
return worldName;
}

public @Nullable GameVersionNumber getGameVersion() {
return gameVersion;
}

public @Nullable Image getIcon() {
return icon;
}

public void install(Path savesDir, String name) throws IOException {
Path targetPath = FileUtils.getNonConflictingDirectory(savesDir, FileUtils.getSafeWorldFolderName(name));

if (isArchive) {
if (hasTopLevelDirectory) {
new Unzipper(sourcePath, targetPath).setSubDirectory("/" + fileName + "/").unzip();
} else {
new Unzipper(sourcePath, targetPath).unzip();
}
} else {
FileUtils.copyDirectory(sourcePath, targetPath, path -> !path.contains("session.lock"));
}
new World(targetPath).setWorldName(name);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.channels.FileChannel;
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;
import java.time.LocalDateTime;
Expand All @@ -37,17 +36,15 @@ public final class WorldBackupTask extends Task<Path> {

private final World world;
private final Path backupsDir;
private final boolean needLock;

public WorldBackupTask(World world, Path backupsDir, boolean needLock) {
public WorldBackupTask(World world, Path backupsDir) {
this.world = world;
this.backupsDir = backupsDir;
this.needLock = needLock;
}

@Override
public void execute() throws Exception {
try (FileChannel lockChannel = needLock ? world.lock() : null) {
try (World.WorldLock.Guard guard = world.getWorldLock().guard()) {
Files.createDirectories(backupsDir);
String time = LocalDateTime.now().format(WorldBackupsPage.TIME_FORMATTER);
String baseName = time + "_" + world.getFileName();
Expand Down
Loading