Skip to content

Commit 45db1e3

Browse files
committed
feat: update configuration files and add files
1 parent 88926bb commit 45db1e3

File tree

11 files changed

+69
-15
lines changed

11 files changed

+69
-15
lines changed

CHANGELOG.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [0.7.0] - 2025-06-02
11+
12+
### Changed
13+
14+
- Adapt to LeviLamina 1.2.0(BDS-1.21.70.04)
15+
- Deprecate `base64Nbt` in `dimension_config.json` files and add `sNbt` configuration. Improve the readability of configuration files
16+
1017
## [0.6.1] - 2025-03-05
1118

1219
### Fixed
@@ -89,7 +96,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
8996

9097
- Release the first version
9198

92-
[Unreleased]: https://github.com/LiteLDev/MoreDimensions/compare/v0.6.1...HEAD
99+
[Unreleased]: https://github.com/LiteLDev/MoreDimensions/compare/v0.7.0...HEAD
100+
[0.7.0]: https://github.com/LiteLDev/MoreDimensions/compare/v0.6.1...v0.7.0
93101
[0.6.1]: https://github.com/LiteLDev/MoreDimensions/compare/v0.6.0...v0.6.1
94102
[0.6.0]: https://github.com/LiteLDev/MoreDimensions/compare/v0.5.0...v0.6.0
95103
[0.5.0]: https://github.com/LiteLDev/MoreDimensions/compare/v0.4.1...v0.5.0

src/more_dimensions/api/dimension/CustomDimensionManager.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
#include "CustomDimensionManager.h"
33

4+
#include "mc/nbt/Tag.h"
45
#include "more_dimensions/MoreDimenison.h"
56
#include "more_dimensions/core/dimension/CustomDimensionConfig.h"
67
#include "more_dimensions/core/dimension/FakeDimensionId.h"
@@ -183,7 +184,7 @@ CustomDimensionManager::CustomDimensionManager() : impl(std::make_unique<Impl>()
183184
name,
184185
Impl::DimensionInfo{
185186
info.dimId,
186-
*CompoundTag::fromBinaryNbt(decompress(ll::base64_utils::decode(info.base64Nbt)))
187+
*CompoundTag::fromSnbt(info.sNbt)
187188
}
188189
);
189190
}
@@ -261,7 +262,7 @@ DimensionType CustomDimensionManager::addDimension(
261262
impl->customDimensionMap.emplace(dimName, info);
262263
CustomDimensionConfig::getConfig().dimensionList.emplace(
263264
dimName,
264-
CustomDimensionConfig::Config::Info{info.id, ll::base64_utils::encode(compress(info.nbt.toBinaryNbt()))}
265+
CustomDimensionConfig::Config::Info{info.id, info.nbt.toSnbt(SnbtFormat::Minimize)}
265266
);
266267
CustomDimensionConfig::saveConfigFile();
267268
}

src/more_dimensions/api/dimension/CustomDimensionManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
#include "more_dimensions/core/Macros.h"
44

5+
#include "mc/deps/core/utility/AutomaticID.h"
56
#include "mc/nbt/CompoundTag.h"
67
#include "mc/world/level/GeneratorType.h"
7-
#include <mc/deps/core/utility/AutomaticID.h>
88

99
class Dimension;
1010
class ILevel;

src/more_dimensions/core/dimension/CustomDimensionConfig.cpp

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,37 @@
11

22
#include "CustomDimensionConfig.h"
33

4+
#include "mc/nbt/Tag.h"
45
#include "more_dimensions/MoreDimenison.h"
56

7+
#include "snappy.h"
8+
69
#include "ll/api/Config.h"
710
#include "ll/api/service/Bedrock.h"
11+
#include "ll/api/utils/Base64Utils.h"
812
#include "ll/api/utils/ErrorUtils.h"
913

14+
#include "mc/nbt/CompoundTag.h"
1015
#include "mc/server/PropertiesSettings.h"
1116

17+
1218
namespace more_dimensions::CustomDimensionConfig {
1319

1420
// static ll::Logger logger("CustomDimensionConfig");
1521
auto& logger = MoreDimenison::getInstance().getSelf().getLogger();
1622

23+
std::string compress(std::string_view sv) {
24+
std::string res;
25+
snappy::Compress(sv.data(), sv.size(), &res);
26+
return res;
27+
}
28+
29+
std::string decompress(std::string_view sv) {
30+
std::string res;
31+
snappy::Uncompress(sv.data(), sv.size(), &res);
32+
return res;
33+
}
34+
1735
static std::filesystem::path dimensionConfigPath{u8"./worlds"};
1836

1937
void setDimensionConfigPath() {
@@ -27,7 +45,25 @@ void setDimensionConfigPath() {
2745
bool loadConfigFile() {
2846
if (std::ifstream(dimensionConfigPath).good()) {
2947
try {
30-
if (ll::config::loadConfig(getConfig(), dimensionConfigPath)) {
48+
if (ll::config::loadConfig(
49+
getConfig(),
50+
dimensionConfigPath,
51+
[](Config& config, nlohmann::ordered_json& data) {
52+
if (data["version"] < config.version) {
53+
for (auto& item : data["dimensionList"]) {
54+
item["sNbt"] =
55+
CompoundTag::fromBinaryNbt(decompress(ll::base64_utils::decode(item["base64Nbt"])))
56+
->toSnbt(SnbtFormat::Minimize);
57+
item.erase("base64Nbt");
58+
}
59+
}
60+
data.erase("version");
61+
auto patch = ll::reflection::serialize<nlohmann::ordered_json>(config);
62+
patch.value().merge_patch(data);
63+
data = *std::move(patch);
64+
return true;
65+
}
66+
)) {
3167
logger.info("Config file load success!");
3268
return true;
3369
}
@@ -51,7 +87,7 @@ bool loadConfigFile() {
5187
}
5288

5389
bool saveConfigFile() {
54-
bool result = false;
90+
bool result{};
5591
try {
5692
result = ll::config::saveConfig(getConfig(), dimensionConfigPath);
5793
} catch (...) {
@@ -64,4 +100,17 @@ bool saveConfigFile() {
64100
}
65101
return true;
66102
}
103+
104+
// void updateConfigVersion() {
105+
// if (getConfig().version < 4) {
106+
// logger.info("Config need update");
107+
// auto config = getConfig();
108+
// for (auto& item : config.dimensionList) {
109+
// auto oldStrNbt = item.second.base64Nbt;
110+
// item.second.base64Nbt = CompoundTag::fromBinaryNbt(decompress(ll::base64_utils::decode(oldStrNbt)))
111+
// ->toSnbt(SnbtFormat::Minimize);
112+
// }
113+
// saveConfigFile();
114+
// }
115+
// }
67116
} // namespace more_dimensions::CustomDimensionConfig

src/more_dimensions/core/dimension/CustomDimensionConfig.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
#pragma once
22

3-
#include "ll/api/base/StdInt.h"
4-
5-
#include "mc/world/level/GeneratorType.h"
6-
73
#include <string>
84
#include <unordered_map>
95

@@ -12,13 +8,13 @@ namespace more_dimensions::CustomDimensionConfig {
128
struct Config {
139
struct Info {
1410
int dimId{};
15-
std::string base64Nbt;
11+
std::string sNbt;
1612
};
17-
int version = 3;
13+
int version = 4;
1814
std::unordered_map<std::string, Info> dimensionList{};
1915
};
2016

21-
static Config& getConfig() {
17+
inline Config& getConfig() {
2218
static Config instance;
2319
return instance;
2420
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)