feat: auto patch invalid inventory id pre 0.25

This commit is contained in:
MihailRis
2024-11-19 12:18:59 +03:00
parent 371fdaedce
commit e70d30b9a2
2 changed files with 7 additions and 4 deletions
+5
View File
@@ -148,6 +148,11 @@ std::unique_ptr<Level> World::load(
0 0
); );
player->deserialize(playerMap); player->deserialize(playerMap);
auto& inventory = player->getInventory();
// invalid inventory id pre 0.25
if (inventory->getId() == 0) {
inventory->setId(level->getWorld()->getNextInventoryId());
}
level->inventories->store(player->getInventory()); level->inventories->store(player->getInventory());
} }
} else { } else {
+2 -4
View File
@@ -27,7 +27,7 @@ struct WorldInfo : public Serializable {
std::string name; std::string name;
std::string generator; std::string generator;
uint64_t seed; uint64_t seed;
int64_t nextInventoryId = 0; int64_t nextInventoryId = 1;
/// @brief Day/night loop timer in range 0..1 where /// @brief Day/night loop timer in range 0..1 where
/// 0.0 - is midnight and /// 0.0 - is midnight and
@@ -58,8 +58,6 @@ class World {
const Content* const content; const Content* const content;
std::vector<ContentPack> packs; std::vector<ContentPack> packs;
int64_t nextInventoryId = 1;
void writeResources(const Content* content); void writeResources(const Content* content);
public: public:
std::shared_ptr<WorldFiles> wfile; std::shared_ptr<WorldFiles> wfile;
@@ -155,7 +153,7 @@ public:
/// @brief Get next inventory id and increment it's counter /// @brief Get next inventory id and increment it's counter
/// @return integer >= 1 /// @return integer >= 1
int64_t getNextInventoryId() { int64_t getNextInventoryId() {
return nextInventoryId++; return info.nextInventoryId++;
} }
/// @brief Get current world Content instance /// @brief Get current world Content instance