Fix loading of legacy chests
authorPerttu Ahola <celeron55@gmail.com>
Sat, 2 Jun 2012 21:32:49 +0000 (00:32 +0300)
committerPerttu Ahola <celeron55@gmail.com>
Sun, 3 Jun 2012 19:31:01 +0000 (22:31 +0300)
src/content_nodemeta.cpp
src/inventory.cpp
src/inventory.h

index a2a341ae0701742afa5c79ac0eb6f0af3ec4d9fb..2f32cf16a871338c5d107ec3af498a5324a8f2f0 100644 (file)
@@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "inventory.h"
 #include "log.h"
 #include "utility.h"
+#include <sstream>
 
 #define NODEMETA_GENERIC 1
 #define NODEMETA_SIGN 14
@@ -70,11 +71,10 @@ static bool content_nodemeta_deserialize_legacy_body(
                // Rename inventory list "0" to "main"
                Inventory *inv = meta->getInventory();
                if(!inv->getList("main") && inv->getList("0")){
-                       inv->addList("main", 8*4);
-                       *inv->getList("main") = *inv->getList("0");
-                       inv->deleteList("0");
+                       inv->getList("0")->setName("main");
                }
-
+               assert(inv->getList("main") && !inv->getList("0"));
+               
                meta->setString("formspec","invsize[8,9;]"
                                "list[current_name;main;0,0;8,4;]"
                                "list[current_player;main;0,5;8,4;]");
@@ -88,11 +88,10 @@ static bool content_nodemeta_deserialize_legacy_body(
                // Rename inventory list "0" to "main"
                Inventory *inv = meta->getInventory();
                if(!inv->getList("main") && inv->getList("0")){
-                       inv->addList("main", 8*4);
-                       *inv->getList("main") = *inv->getList("0");
-                       inv->deleteList("0");
+                       inv->getList("0")->setName("main");
                }
-
+               assert(inv->getList("main") && !inv->getList("0"));
+               
                meta->setString("formspec","invsize[8,9;]"
                                "list[current_name;main;0,0;8,4;]"
                                "list[current_player;main;0,5;8,4;]");
index df75ebcd53b006c5bd867b5ddb883343fe22c6a1..7c31c85c8bfe4527bfc402c885a7d3614b2ffe77 100644 (file)
@@ -458,6 +458,11 @@ void InventoryList::setSize(u32 newsize)
        m_size = newsize;
 }
 
+void InventoryList::setName(const std::string &name)
+{
+       m_name = name;
+}
+
 void InventoryList::serialize(std::ostream &os) const
 {
        //os.imbue(std::locale("C"));
index 411eabb0977c4939351d1e7ceb03331b3d1c67f5..e280bbf798486b733c0771c0baa4609a98208003 100644 (file)
@@ -176,6 +176,7 @@ public:
        ~InventoryList();
        void clearItems();
        void setSize(u32 newsize);
+       void setName(const std::string &name);
        void serialize(std::ostream &os) const;
        void deSerialize(std::istream &is);