Skip to content

Commit 456d139

Browse files
authored
更新 GameVersionNumber 解析规则 (#4917)
1. 支持 [Minecraft 新版本号方案](https://www.minecraft.net/en-us/article/minecraft-new-version-numbering-system) 2. 支持对版本号进行归一化处理。
1 parent 7ac22ad commit 456d139

File tree

19 files changed

+676
-253
lines changed

19 files changed

+676
-253
lines changed

HMCL/src/main/java/org/jackhuang/hmcl/game/HMCLGameRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ else if (libraryAnalyzer.has(LibraryAnalyzer.LibraryType.OPTIFINE))
338338
GameVersionNumber versionNumber = GameVersionNumber.asGameVersion(gameVersion);
339339
if (versionNumber.isAprilFools()) {
340340
return VersionIconType.APRIL_FOOLS.getIcon();
341-
} else if (versionNumber instanceof GameVersionNumber.Snapshot) {
341+
} else if (versionNumber instanceof GameVersionNumber.LegacySnapshot) {
342342
return VersionIconType.COMMAND.getIcon();
343343
} else if (versionNumber instanceof GameVersionNumber.Old) {
344344
return VersionIconType.CRAFT_TABLE.getIcon();

HMCL/src/main/java/org/jackhuang/hmcl/ui/download/VersionsPage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ public void updateItem(RemoteVersion remoteVersion, boolean empty) {
233233
}
234234
setGraphic(pane);
235235

236-
twoLineListItem.setTitle(I18n.getDisplaySelfVersion(remoteVersion));
236+
twoLineListItem.setTitle(I18n.getDisplayVersion(remoteVersion));
237237
if (remoteVersion.getReleaseDate() != null) {
238238
twoLineListItem.setSubtitle(I18n.formatDateTime(remoteVersion.getReleaseDate()));
239239
} else {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import org.jackhuang.hmcl.ui.construct.TwoLineListItem;
4040
import org.jackhuang.hmcl.util.Pair;
4141
import org.jackhuang.hmcl.util.StringUtils;
42+
import org.jackhuang.hmcl.util.i18n.I18n;
4243
import org.jetbrains.annotations.NotNull;
4344

4445
import java.nio.file.*;
@@ -245,7 +246,7 @@ private static final class BackupInfoSkin extends SkinBase<BackupInfo> {
245246
item.setSubtitle(formatDateTime(skinnable.getBackupTime()) + (skinnable.count == 0 ? "" : " (" + skinnable.count + ")"));
246247

247248
if (world.getGameVersion() != null)
248-
item.addTag(world.getGameVersion());
249+
item.addTag(I18n.getDisplayVersion(world.getGameVersion()));
249250
}
250251

251252
{

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.jackhuang.hmcl.game.World;
2424
import org.jackhuang.hmcl.task.Task;
2525
import org.jackhuang.hmcl.ui.wizard.WizardSinglePage;
26+
import org.jackhuang.hmcl.util.i18n.I18n;
2627

2728
import java.nio.file.Path;
2829
import java.nio.file.Paths;
@@ -41,7 +42,8 @@ public WorldExportPage(World world, Path export, Runnable onFinish) {
4142
this.world = world;
4243

4344
path.set(export.toString());
44-
gameVersion.set(world.getGameVersion());
45+
if (world.getGameVersion() != null)
46+
gameVersion.set(I18n.getDisplayVersion(world.getGameVersion()));
4547
worldName.set(world.getWorldName());
4648
}
4749

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ private void updateControls() {
122122

123123
Label gameVersionLabel = new Label();
124124
FXUtils.copyOnDoubleClick(gameVersionLabel);
125-
gameVersionLabel.setText(world.getGameVersion());
125+
if (world.getGameVersion() != null)
126+
gameVersionLabel.setText(world.getGameVersion().toNormalizedString());
126127
BorderPane.setAlignment(gameVersionLabel, Pos.CENTER_RIGHT);
127128
gameVersionPane.setRight(gameVersionLabel);
128129
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
import org.jackhuang.hmcl.ui.SVG;
3333
import org.jackhuang.hmcl.ui.construct.*;
3434
import org.jackhuang.hmcl.util.ChunkBaseApp;
35-
import org.jackhuang.hmcl.util.versioning.GameVersionNumber;
35+
import org.jackhuang.hmcl.util.i18n.I18n;
3636

3737
import java.time.Instant;
3838

@@ -72,10 +72,10 @@ public WorldListItemSkin(WorldListItem skinnable) {
7272
item.setMouseTransparent(true);
7373
if (world.getWorldName() != null)
7474
item.setTitle(parseColorEscapes(world.getWorldName()));
75-
item.setSubtitle(i18n("world.datetime", formatDateTime(Instant.ofEpochMilli(world.getLastPlayed())), world.getGameVersion() == null ? i18n("message.unknown") : world.getGameVersion()));
75+
item.setSubtitle(i18n("world.datetime", formatDateTime(Instant.ofEpochMilli(world.getLastPlayed()))));
7676

7777
if (world.getGameVersion() != null)
78-
item.addTag(world.getGameVersion());
78+
item.addTag(I18n.getDisplayVersion(world.getGameVersion()));
7979
if (world.isLocked())
8080
item.addTag(i18n("world.locked"));
8181
}
@@ -126,7 +126,7 @@ public void showPopupMenu(JFXPopup.PopupHPosition hPosition, double initOffsetX,
126126
new IconedMenuItem(SVG.FORT, i18n("world.chunkbase.nether_fortress"), () -> ChunkBaseApp.openNetherFortressFinder(world), popup)
127127
);
128128

129-
if (GameVersionNumber.compare(world.getGameVersion(), "1.13") >= 0) {
129+
if (world.getGameVersion() != null && world.getGameVersion().compareTo("1.13") >= 0) {
130130
popupMenu.getContent().add(new IconedMenuItem(SVG.LOCATION_CITY, i18n("world.chunkbase.end_city"),
131131
() -> ChunkBaseApp.openEndCityFinder(world), popup));
132132
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.jackhuang.hmcl.task.Task;
2929
import org.jackhuang.hmcl.ui.*;
3030
import org.jackhuang.hmcl.util.io.FileUtils;
31+
import org.jackhuang.hmcl.util.versioning.GameVersionNumber;
3132

3233
import java.io.IOException;
3334
import java.nio.file.FileAlreadyExistsException;
@@ -49,7 +50,7 @@ public final class WorldListPage extends ListPageBase<WorldListItem> implements
4950
private List<World> worlds;
5051
private Profile profile;
5152
private String id;
52-
private String gameVersion;
53+
private GameVersionNumber gameVersion;
5354

5455
public WorldListPage() {
5556
FXUtils.applyDragListener(this, it -> "zip".equals(FileUtils.getExtension(it)), modpacks -> {
@@ -87,7 +88,7 @@ public void refresh() {
8788
return;
8889

8990
setLoading(true);
90-
Task.runAsync(() -> gameVersion = profile.getRepository().getGameVersion(id).orElse(null))
91+
Task.runAsync(() -> gameVersion = profile.getRepository().getGameVersion(id).map(GameVersionNumber::asGameVersion).orElse(null))
9192
.thenApplyAsync(unused -> {
9293
try (Stream<World> stream = World.getWorlds(savesDir)) {
9394
return stream.parallel().collect(Collectors.toList());

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import org.jackhuang.hmcl.ui.decorator.DecoratorAnimatedPage;
3434
import org.jackhuang.hmcl.ui.decorator.DecoratorPage;
3535
import org.jackhuang.hmcl.util.ChunkBaseApp;
36-
import org.jackhuang.hmcl.util.versioning.GameVersionNumber;
3736

3837
import java.io.IOException;
3938
import java.nio.channels.FileChannel;
@@ -84,7 +83,7 @@ public WorldManagePage(World world, Path backupsDir) {
8483
.addNavigationDrawerTab(header, worldBackupsTab, i18n("world.backup"), SVG.ARCHIVE, SVG.ARCHIVE_FILL);
8584

8685
if (world.getGameVersion() != null && // old game will not write game version to level.dat
87-
GameVersionNumber.asGameVersion(world.getGameVersion()).isAtLeast("1.13", "17w43a")) {
86+
world.getGameVersion().isAtLeast("1.13", "17w43a")) {
8887
header.getTabs().add(datapackTab);
8988
sideBar.addNavigationDrawerTab(header, datapackTab, i18n("world.datapack"), SVG.EXTENSION, SVG.EXTENSION_FILL);
9089
}
@@ -102,7 +101,7 @@ public WorldManagePage(World world, Path backupsDir) {
102101
new IconedMenuItem(SVG.FORT, i18n("world.chunkbase.nether_fortress"), () -> ChunkBaseApp.openNetherFortressFinder(world), popup)
103102
);
104103

105-
if (GameVersionNumber.compare(world.getGameVersion(), "1.13") >= 0) {
104+
if (world.getGameVersion() != null && world.getGameVersion().compareTo("1.13") >= 0) {
106105
popupMenu.getContent().add(
107106
new IconedMenuItem(SVG.LOCATION_CITY, i18n("world.chunkbase.end_city"), () -> ChunkBaseApp.openEndCityFinder(world), popup));
108107
}

HMCL/src/main/java/org/jackhuang/hmcl/util/ChunkBaseApp.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public final class ChunkBaseApp {
4949

5050
public static boolean isSupported(@NotNull World world) {
5151
return world.getSeed() != null && world.getGameVersion() != null &&
52-
GameVersionNumber.asGameVersion(world.getGameVersion()).compareTo(MIN_GAME_VERSION) >= 0;
52+
world.getGameVersion().compareTo(MIN_GAME_VERSION) >= 0;
5353
}
5454

5555
public static ChunkBaseApp newBuilder(String app, long seed) {
@@ -60,31 +60,31 @@ public static void openSeedMap(World world) {
6060
assert isSupported(world);
6161

6262
newBuilder("seed-map", Objects.requireNonNull(world.getSeed()))
63-
.addPlatform(GameVersionNumber.asGameVersion(world.getGameVersion()), world.isLargeBiomes(), SEED_MAP_GAME_VERSIONS)
63+
.addPlatform(world.getGameVersion(), world.isLargeBiomes(), SEED_MAP_GAME_VERSIONS)
6464
.open();
6565
}
6666

6767
public static void openStrongholdFinder(World world) {
6868
assert isSupported(world);
6969

7070
newBuilder("stronghold-finder", Objects.requireNonNull(world.getSeed()))
71-
.addPlatform(GameVersionNumber.asGameVersion(world.getGameVersion()), world.isLargeBiomes(), STRONGHOLD_FINDER_GAME_VERSIONS)
71+
.addPlatform(world.getGameVersion(), world.isLargeBiomes(), STRONGHOLD_FINDER_GAME_VERSIONS)
7272
.open();
7373
}
7474

7575
public static void openNetherFortressFinder(World world) {
7676
assert isSupported(world);
7777

7878
newBuilder("nether-fortress-finder", Objects.requireNonNull(world.getSeed()))
79-
.addPlatform(GameVersionNumber.asGameVersion(world.getGameVersion()), false, NETHER_FORTRESS_GAME_VERSIONS)
79+
.addPlatform(world.getGameVersion(), false, NETHER_FORTRESS_GAME_VERSIONS)
8080
.open();
8181
}
8282

8383
public static void openEndCityFinder(World world) {
8484
assert isSupported(world);
8585

8686
newBuilder("endcity-finder", Objects.requireNonNull(world.getSeed()))
87-
.addPlatform(GameVersionNumber.asGameVersion(world.getGameVersion()), false, END_CITY_GAME_VERSIONS)
87+
.addPlatform(world.getGameVersion(), false, END_CITY_GAME_VERSIONS)
8888
.open();
8989
}
9090

HMCL/src/main/java/org/jackhuang/hmcl/util/i18n/I18n.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.jackhuang.hmcl.download.RemoteVersion;
2121
import org.jackhuang.hmcl.download.game.GameRemoteVersion;
2222
import org.jackhuang.hmcl.util.i18n.translator.Translator;
23+
import org.jackhuang.hmcl.util.versioning.GameVersionNumber;
2324
import org.jetbrains.annotations.Nullable;
2425
import org.jetbrains.annotations.PropertyKey;
2526

@@ -76,7 +77,11 @@ public static String formatSpeed(long bytes) {
7677
return getTranslator().formatSpeed(bytes);
7778
}
7879

79-
public static String getDisplaySelfVersion(RemoteVersion version) {
80+
public static String getDisplayVersion(RemoteVersion version) {
81+
return getTranslator().getDisplayVersion(version);
82+
}
83+
84+
public static String getDisplayVersion(GameVersionNumber version) {
8085
return getTranslator().getDisplayVersion(version);
8186
}
8287

0 commit comments

Comments
 (0)