From e70d30b9a259aebbb8f2be84efa6af37c03ed965 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Tue, 19 Nov 2024 12:18:59 +0300 Subject: [PATCH] feat: auto patch invalid inventory id pre 0.25 --- src/world/World.cpp | 5 +++++ src/world/World.hpp | 6 ++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/world/World.cpp b/src/world/World.cpp index 6401fa0e..0f6ea373 100644 --- a/src/world/World.cpp +++ b/src/world/World.cpp @@ -148,6 +148,11 @@ std::unique_ptr World::load( 0 ); 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()); } } else { diff --git a/src/world/World.hpp b/src/world/World.hpp index 61e92cfc..2f8e7fb3 100644 --- a/src/world/World.hpp +++ b/src/world/World.hpp @@ -27,7 +27,7 @@ struct WorldInfo : public Serializable { std::string name; std::string generator; uint64_t seed; - int64_t nextInventoryId = 0; + int64_t nextInventoryId = 1; /// @brief Day/night loop timer in range 0..1 where /// 0.0 - is midnight and @@ -58,8 +58,6 @@ class World { const Content* const content; std::vector packs; - int64_t nextInventoryId = 1; - void writeResources(const Content* content); public: std::shared_ptr wfile; @@ -155,7 +153,7 @@ public: /// @brief Get next inventory id and increment it's counter /// @return integer >= 1 int64_t getNextInventoryId() { - return nextInventoryId++; + return info.nextInventoryId++; } /// @brief Get current world Content instance