Skip to content

Commit 0b3f66f

Browse files
committed
Support both dimensions formats
1 parent e7f589f commit 0b3f66f

2 files changed

Lines changed: 21 additions & 13 deletions

File tree

src/savefile.cpp

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,17 @@ bool Dimension::operator==(const Dimension &other) const {
1818
}
1919

2020
fs::path Dimension::suffix() const {
21+
return fs::path(fmt::format("dimensions/{}/{}/region", ns, id));
22+
}
23+
24+
fs::path Dimension::special_suffix() const {
2125
if (id == "overworld")
2226
return "region";
2327
else if (id == "the_nether")
2428
return fs::path("DIM-1/region");
2529
else if (id == "the_end")
2630
return fs::path("DIM1/region");
27-
else
28-
return fs::path(fmt::format("dimensions/{}/{}/region", ns, id));
31+
return "";
2932
}
3033

3134
bool assert_save(const fs::path &root) {
@@ -67,36 +70,40 @@ SaveFile::SaveFile(const fs::path &_folder) : folder(_folder) {
6770
getDimensions();
6871
}
6972

73+
#define VALID(path) (fs::exists((path)) && !fs::is_empty((path)))
7074
void SaveFile::getDimensions() {
71-
#define VALID(path) fs::exists((path)) && !fs::is_empty((path))
72-
if (VALID(folder / "region"))
73-
dimensions.push_back(Dimension("overworld"));
75+
if VALID (folder / "region")
76+
dimensions.push_back(Dimension("minecraft", "overworld"));
7477

75-
if (VALID(folder / "DIM1/region"))
76-
dimensions.push_back(Dimension("the_end"));
78+
if VALID (folder / "DIM1/region")
79+
dimensions.push_back(Dimension("minecraft", "the_end"));
7780

78-
if (VALID(folder / "DIM-1/region"))
79-
dimensions.push_back(Dimension("the_nether"));
81+
if VALID (folder / "DIM-1/region")
82+
dimensions.push_back(Dimension("minecraft", "the_nether"));
8083

8184
fs::path dim_folder = folder / "dimensions";
8285

83-
if (VALID(dim_folder))
86+
if VALID (dim_folder)
8487
for (auto &ns : fs::directory_iterator(dim_folder))
8588
for (auto &id : fs::directory_iterator(ns.path()))
8689
dimensions.push_back(Dimension(ns.path().filename().string(),
8790
id.path().filename().string()));
88-
#undef VALID
8991
}
9092

91-
fs::path
92-
SaveFile::region(const Dimension &dim = std::string("overworld")) const {
93+
fs::path SaveFile::region(const Dimension &dim) const {
9394
auto found = std::find(dimensions.begin(), dimensions.end(), dim);
9495

9596
if (found == dimensions.end())
9697
return "";
9798

99+
// Check now for the old region/DIM1/DIM-1
100+
if VALID (folder / dim.special_suffix()) {
101+
return folder / dim.special_suffix();
102+
}
103+
98104
return folder / dim.suffix();
99105
}
106+
#undef VALID
100107

101108
void to_json(json &j, const Dimension &d) {
102109
j = fmt::format("{}:{}", d.ns, d.id);

src/savefile.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ struct Dimension {
1919
bool operator==(const Dimension &) const;
2020

2121
fs::path suffix() const;
22+
fs::path special_suffix() const;
2223

2324
std::string to_string() { return fmt::format("{}:{}", ns, id); };
2425
};

0 commit comments

Comments
 (0)