feat: auto patch invalid inventory id pre 0.25
This commit is contained in:
@@ -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
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user