Convert legacy chest inventory list "0" to "main"
authorPerttu Ahola <celeron55@gmail.com>
Fri, 1 Jun 2012 16:51:45 +0000 (19:51 +0300)
committerPerttu Ahola <celeron55@gmail.com>
Sun, 3 Jun 2012 19:31:00 +0000 (22:31 +0300)
src/content_nodemeta.cpp

index 18690612d497ed611b71b802b9fd02c26337f268..ba4a0e5137df529cd81551590cfe08de13d88d4b 100644 (file)
@@ -64,8 +64,17 @@ static bool content_nodemeta_deserialize_legacy_body(
        else if(id == NODEMETA_CHEST) // ChestNodeMetadata
        {
                meta->getInventory()->deSerialize(is);
+
+               // 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");
+               }
+
                meta->setString("formspec","invsize[8,9;]"
-                               "list[current_name;0;0,0;8,4;]"
+                               "list[current_name;main;0,0;8,4;]"
                                "list[current_player;main;0,5;8,4;]");
                return false;
        }
@@ -73,8 +82,17 @@ static bool content_nodemeta_deserialize_legacy_body(
        {
                meta->setString("owner", deSerializeString(is));
                meta->getInventory()->deSerialize(is);
+
+               // 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");
+               }
+
                meta->setString("formspec","invsize[8,9;]"
-                               "list[current_name;0;0,0;8,4;]"
+                               "list[current_name;main;0,0;8,4;]"
                                "list[current_player;main;0,5;8,4;]");
                return false;
        }