just savin'
authorPerttu Ahola <celeron55@gmail.com>
Wed, 22 Dec 2010 09:29:06 +0000 (11:29 +0200)
committerPerttu Ahola <celeron55@gmail.com>
Wed, 22 Dec 2010 09:29:06 +0000 (11:29 +0200)
src/guiInventoryMenu.cpp
src/guiInventoryMenu.h
src/inventory.cpp
src/inventory.h
src/main.cpp
src/player.cpp
src/server.cpp

index 370ebd5d1561f1cd1cb6052effd7e3d4fa732c0f..7bc5ca9e0ba0fd416dc3479c6bab9a0e0e3f0db5 100644 (file)
@@ -149,46 +149,19 @@ void GUIInventoryMenu::resizeGui()
                return;
        m_screensize_old = screensize;
 
-       for(u32 i=0; i<m_slots.size(); i++)
-       {
-               m_slots[i]->remove();
-       }
-       m_slots.clear();
-
        core::rect<s32> rect(
                        screensize.X/2 - 560/2,
-                       screensize.Y/2 - 300/2,
+                       screensize.Y/2 - 480/2,
                        screensize.X/2 + 560/2,
-                       screensize.Y/2 + 300/2
+                       screensize.Y/2 + 480/2
        );
        
        DesiredRect = rect;
        recalculateAbsolutePosition(false);
-
-       //v2s32 size = rect.getSize();
-
-       core::rect<s32> imgsize(0,0,48,48);
-       v2s32 basepos(30, 30);
-       for(s32 i=0; i<PLAYER_INVENTORY_SIZE; i++)
-       {
-               s32 x = (i%8) * 64;
-               s32 y = (i/8) * 64;
-               v2s32 p(x,y);
-               core::rect<s32> rect = imgsize + basepos + p;
-               GUIInventorySlot *item =
-                       new GUIInventorySlot(Environment, this, -1, rect);
-               m_slots.push_back(item);
-       }
-       
-       update();
 }
 
 void GUIInventoryMenu::update()
 {
-       for(s32 i=0; i<PLAYER_INVENTORY_SIZE; i++)
-       {
-               m_slots[i]->setItem(m_inventory->getItem(i));
-       }
 }
 
 void GUIInventoryMenu::draw()
@@ -204,6 +177,51 @@ void GUIInventoryMenu::draw()
        video::SColor bgcolor(140,0,0,0);
        driver->draw2DRectangle(bgcolor, AbsoluteRect, &AbsoluteClippingRect);
 
+       /*
+               Draw items
+       */
+       
+       {
+               InventoryList *ilist = m_inventory->getList("main");
+               if(ilist != NULL)
+               {
+                       core::rect<s32> imgsize(0,0,48,48);
+                       v2s32 basepos(30, 210);
+                       basepos += AbsoluteRect.UpperLeftCorner;
+                       for(s32 i=0; i<PLAYER_INVENTORY_SIZE; i++)
+                       {
+                               s32 x = (i%8) * 64;
+                               s32 y = (i/8) * 64;
+                               v2s32 p(x,y);
+                               core::rect<s32> rect = imgsize + basepos + p;
+                               drawInventoryItem(Environment, ilist->getItem(i),
+                                               rect, &AbsoluteClippingRect);
+                       }
+               }
+       }
+
+       {
+               InventoryList *ilist = m_inventory->getList("craft");
+               if(ilist != NULL)
+               {
+                       core::rect<s32> imgsize(0,0,48,48);
+                       v2s32 basepos(30, 30);
+                       basepos += AbsoluteRect.UpperLeftCorner;
+                       for(s32 i=0; i<9; i++)
+                       {
+                               s32 x = (i%3) * 64;
+                               s32 y = (i/3) * 64;
+                               v2s32 p(x,y);
+                               core::rect<s32> rect = imgsize + basepos + p;
+                               drawInventoryItem(Environment, ilist->getItem(i),
+                                               rect, &AbsoluteClippingRect);
+                       }
+               }
+       }
+
+       /*
+               Call base class
+       */
        gui::IGUIElement::draw();
 }
 
index 8bfade4c4e9eeab14618ef3d8621d3fece778c04..b581a1166a7ea0e9c35b521a9295c57fa0820e92 100644 (file)
@@ -61,6 +61,7 @@ public:
        void resizeGui();
 
        // Updates stuff from inventory to screen
+       // TODO: Remove, not used
        void update();
 
        void draw();
@@ -80,7 +81,6 @@ public:
        
 private:
        Inventory *m_inventory;
-       core::array<GUIInventorySlot*> m_slots;
        v2u32 m_screensize_old;
 };
 
index 3899c9394186cdf3e5cac86ed81d115c64618c88..069355affeeee45fd8235c7ca9e766efadc2c0e2 100644 (file)
@@ -136,30 +136,39 @@ MapBlockObject * MapBlockObjectItem::createObject
        Inventory
 */
 
-Inventory::Inventory(u32 size)
+InventoryList::InventoryList(std::string name, u32 size)
 {
+       m_name = name;
        m_size = size;
        clearItems();
 }
 
-Inventory::~Inventory()
+InventoryList::~InventoryList()
 {
        for(u32 i=0; i<m_items.size(); i++)
        {
-               delete m_items[i];
+               if(m_items[i])
+                       delete m_items[i];
        }
 }
 
-void Inventory::clearItems()
+void InventoryList::clearItems()
 {
+       for(u32 i=0; i<m_items.size(); i++)
+       {
+               if(m_items[i])
+                       delete m_items[i];
+       }
+
        m_items.clear();
+
        for(u32 i=0; i<m_size; i++)
        {
                m_items.push_back(NULL);
        }
 }
 
-void Inventory::serialize(std::ostream &os)
+void InventoryList::serialize(std::ostream &os)
 {
        //os.imbue(std::locale("C"));
        
@@ -181,7 +190,7 @@ void Inventory::serialize(std::ostream &os)
        os<<"end\n";
 }
 
-void Inventory::deSerialize(std::istream &is)
+void InventoryList::deSerialize(std::istream &is)
 {
        //is.imbue(std::locale("C"));
 
@@ -223,8 +232,18 @@ void Inventory::deSerialize(std::istream &is)
        }
 }
 
-Inventory & Inventory::operator = (Inventory &other)
+InventoryList::InventoryList(const InventoryList &other)
+{
+       /*
+               Do this so that the items get cloned. Otherwise the pointers
+               in the array will just get copied.
+       */
+       *this = other;
+}
+
+InventoryList & InventoryList::operator = (const InventoryList &other)
 {
+       m_name = other.m_name;
        m_size = other.m_size;
        clearItems();
        for(u32 i=0; i<other.m_items.size(); i++)
@@ -239,12 +258,17 @@ Inventory & Inventory::operator = (Inventory &other)
        return *this;
 }
 
-u32 Inventory::getSize()
+std::string InventoryList::getName()
+{
+       return m_name;
+}
+
+u32 InventoryList::getSize()
 {
        return m_items.size();
 }
 
-u32 Inventory::getUsedSlots()
+u32 InventoryList::getUsedSlots()
 {
        u32 num = 0;
        for(u32 i=0; i<m_items.size(); i++)
@@ -256,14 +280,14 @@ u32 Inventory::getUsedSlots()
        return num;
 }
 
-InventoryItem * Inventory::getItem(u32 i)
+InventoryItem * InventoryList::getItem(u32 i)
 {
        if(i > m_items.size() - 1)
                return NULL;
        return m_items[i];
 }
 
-InventoryItem * Inventory::changeItem(u32 i, InventoryItem *newitem)
+InventoryItem * InventoryList::changeItem(u32 i, InventoryItem *newitem)
 {
        assert(i < m_items.size());
 
@@ -272,7 +296,7 @@ InventoryItem * Inventory::changeItem(u32 i, InventoryItem *newitem)
        return olditem;
 }
 
-void Inventory::deleteItem(u32 i)
+void InventoryList::deleteItem(u32 i)
 {
        assert(i < m_items.size());
        InventoryItem *item = changeItem(i, NULL);
@@ -280,7 +304,7 @@ void Inventory::deleteItem(u32 i)
                delete item;
 }
 
-bool Inventory::addItem(InventoryItem *newitem)
+bool InventoryList::addItem(InventoryItem *newitem)
 {
        // If it is a MaterialItem, try to find an already existing one
        // and just increment the counter
@@ -324,9 +348,9 @@ bool Inventory::addItem(InventoryItem *newitem)
        return false;
 }
 
-void Inventory::print(std::ostream &o)
+void InventoryList::print(std::ostream &o)
 {
-       o<<"Player inventory:"<<std::endl;
+       o<<"InventoryList:"<<std::endl;
        for(u32 i=0; i<m_items.size(); i++)
        {
                InventoryItem *item = m_items[i];
@@ -338,5 +362,130 @@ void Inventory::print(std::ostream &o)
                }
        }
 }
+
+/*
+       Inventory
+*/
+
+Inventory::~Inventory()
+{
+       clear();
+}
+
+void Inventory::clear()
+{
+       for(u32 i=0; i<m_lists.size(); i++)
+       {
+               delete m_lists[i];
+       }
+       m_lists.clear();
+}
+
+Inventory::Inventory()
+{
+}
+
+Inventory::Inventory(const Inventory &other)
+{
+       *this = other;
+}
+
+Inventory & Inventory::operator = (const Inventory &other)
+{
+       clear();
+       for(u32 i=0; i<other.m_lists.size(); i++)
+       {
+               m_lists.push_back(new InventoryList(*other.m_lists[i]));
+       }
+       return *this;
+}
+
+void Inventory::serialize(std::ostream &os)
+{
+       for(u32 i=0; i<m_lists.size(); i++)
+       {
+               InventoryList *list = m_lists[i];
+               os<<"List "<<list->getName()<<" "<<list->getSize()<<"\n";
+               list->serialize(os);
+       }
+
+       os<<"end\n";
+}
+
+void Inventory::deSerialize(std::istream &is)
+{
+       clear();
+
+       for(;;)
+       {
+               std::string line;
+               std::getline(is, line, '\n');
+
+               std::istringstream iss(line);
+
+               std::string name;
+               std::getline(iss, name, ' ');
+
+               if(name == "end")
+               {
+                       break;
+               }
+               else if(name == "List")
+               {
+                       std::string listname;
+                       u32 listsize;
+
+                       std::getline(iss, listname, ' ');
+                       iss>>listsize;
+
+                       InventoryList *list = new InventoryList(listname, listsize);
+                       list->deSerialize(is);
+
+                       m_lists.push_back(list);
+               }
+               else
+               {
+                       throw SerializationError("Unknown inventory identifier");
+               }
+       }
+}
+
+InventoryList * Inventory::addList(const std::string &name, u32 size)
+{
+       s32 i = getListIndex(name);
+       if(i != -1)
+       {
+               if(m_lists[i]->getSize() != size)
+               {
+                       delete m_lists[i];
+                       m_lists[i] = new InventoryList(name, size);
+               }
+               return m_lists[i];
+       }
+       else
+       {
+               m_lists.push_back(new InventoryList(name, size));
+               return m_lists.getLast();
+       }
+}
+
+InventoryList * Inventory::getList(const std::string &name)
+{
+       s32 i = getListIndex(name);
+       if(i == -1)
+               return NULL;
+       return m_lists[i];
+}
+
+s32 Inventory::getListIndex(const std::string &name)
+{
+       for(u32 i=0; i<m_lists.size(); i++)
+       {
+               if(m_lists[i]->getName() == name)
+                       return i;
+       }
+       return -1;
+}
+
        
 //END
index c18aa5dce20997fe89fff24936d28cf7d43af570..d37761cfedfc3906eaf4fcef49a693b3acc10f15 100644 (file)
@@ -196,18 +196,21 @@ private:
        std::string m_inventorystring;
 };
 
-class Inventory
+class InventoryList
 {
 public:
-       Inventory(u32 size);
-       ~Inventory();
+       InventoryList(std::string name, u32 size);
+       ~InventoryList();
        void clearItems();
        void serialize(std::ostream &os);
        void deSerialize(std::istream &is);
 
-       Inventory & operator = (Inventory &other);
+       InventoryList(const InventoryList &other);
+       InventoryList & operator = (const InventoryList &other);
 
+       std::string getName();
        u32 getSize();
+       // Count used slots
        u32 getUsedSlots();
        
        InventoryItem * getItem(u32 i);
@@ -222,6 +225,40 @@ public:
 private:
        core::array<InventoryItem*> m_items;
        u32 m_size;
+       std::string m_name;
+};
+
+class Inventory
+{
+public:
+       ~Inventory();
+
+       void clear();
+
+       Inventory();
+       Inventory(const Inventory &other);
+       Inventory & operator = (const Inventory &other);
+       
+       void serialize(std::ostream &os);
+       void deSerialize(std::istream &is);
+
+       InventoryList * addList(const std::string &name, u32 size);
+       InventoryList * getList(const std::string &name);
+       bool deleteList(const std::string &name);
+       // A shorthand for adding items
+       bool addItem(const std::string &listname, InventoryItem *newitem)
+       {
+               InventoryList *list = getList(listname);
+               if(list == NULL)
+                       return false;
+               return list->addItem(newitem);
+       }
+       
+private:
+       // -1 if not found
+       s32 getListIndex(const std::string &name);
+
+       core::array<InventoryList*> m_lists;
 };
 
 #endif
index 4b696236d7814cbb974f21e94d8331987122e5b5..7fecbe3bd9b68ce086a0c6476e9491b0261c63f9 100644 (file)
@@ -172,6 +172,7 @@ SUGG: Split Inventory into ClientInventory and ServerInventory
 Doing now:\r
 ======================================================================\r
 \r
+TODO: Convert the text input system to use a modal menu\r
 \r
 ======================================================================\r
 \r
@@ -269,10 +270,22 @@ extern void set_default_settings();
 //u16 g_selected_material = 0;\r
 u16 g_selected_item = 0;\r
 \r
+/*\r
+       GUI Stuff\r
+*/\r
 gui::IGUIEnvironment* guienv = NULL;\r
 GUIPauseMenu *pauseMenu = NULL;\r
 GUIInventoryMenu *inventoryMenu = NULL;\r
 \r
+bool noMenuActive()\r
+{\r
+       if(pauseMenu && pauseMenu->isVisible())\r
+               return false;\r
+       if(inventoryMenu && inventoryMenu->isVisible())\r
+               return false;\r
+       return true;\r
+}\r
+\r
 std::wstring g_text_buffer;\r
 bool g_text_buffer_accepted = false;\r
 \r
@@ -353,9 +366,7 @@ public:
                                {\r
                                        if(event.KeyInput.Key == irr::KEY_ESCAPE)\r
                                        {\r
-                                               if(g_game_focused == true\r
-                                                               && !pauseMenu->isVisible()\r
-                                                               && !inventoryMenu->isVisible())\r
+                                               if(g_game_focused == true && noMenuActive())\r
                                                {\r
                                                        dstream<<DTIME<<"MyEventReceiver: "\r
                                                                        <<"Launching pause menu"<<std::endl;\r
@@ -369,9 +380,7 @@ public:
                                {\r
                                        if(event.KeyInput.Key == irr::KEY_KEY_I)\r
                                        {\r
-                                               if(g_game_focused == true\r
-                                                               && !inventoryMenu->isVisible()\r
-                                                               && !pauseMenu->isVisible())\r
+                                               if(g_game_focused == true && noMenuActive())\r
                                                {\r
                                                        dstream<<DTIME<<"MyEventReceiver: "\r
                                                                        <<"Launching inventory"<<std::endl;\r
@@ -428,44 +437,53 @@ public:
 \r
                if(event.EventType == irr::EET_MOUSE_INPUT_EVENT)\r
                {\r
-                       //dstream<<"MyEventReceiver: mouse input"<<std::endl;\r
-                       left_active = event.MouseInput.isLeftPressed();\r
-                       middle_active = event.MouseInput.isMiddlePressed();\r
-                       right_active = event.MouseInput.isRightPressed();\r
-\r
-                       if(event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN)\r
-                       {\r
-                               leftclicked = true;\r
-                       }\r
-                       if(event.MouseInput.Event == EMIE_RMOUSE_PRESSED_DOWN)\r
-                       {\r
-                               rightclicked = true;\r
-                       }\r
-                       if(event.MouseInput.Event == EMIE_LMOUSE_LEFT_UP)\r
+                       if(noMenuActive() == false)\r
                        {\r
-                               leftreleased = true;\r
+                               left_active = false;\r
+                               middle_active = false;\r
+                               right_active = false;\r
                        }\r
-                       if(event.MouseInput.Event == EMIE_RMOUSE_LEFT_UP)\r
-                       {\r
-                               rightreleased = true;\r
-                       }\r
-                       if(event.MouseInput.Event == EMIE_MOUSE_WHEEL)\r
+                       else\r
                        {\r
-                               /*dstream<<"event.MouseInput.Wheel="\r
-                                               <<event.MouseInput.Wheel<<std::endl;*/\r
-                               if(event.MouseInput.Wheel < 0)\r
+                               //dstream<<"MyEventReceiver: mouse input"<<std::endl;\r
+                               left_active = event.MouseInput.isLeftPressed();\r
+                               middle_active = event.MouseInput.isMiddlePressed();\r
+                               right_active = event.MouseInput.isRightPressed();\r
+\r
+                               if(event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN)\r
                                {\r
-                                       if(g_selected_item < PLAYER_INVENTORY_SIZE-1)\r
-                                               g_selected_item++;\r
-                                       else\r
-                                               g_selected_item = 0;\r
+                                       leftclicked = true;\r
                                }\r
-                               else if(event.MouseInput.Wheel > 0)\r
+                               if(event.MouseInput.Event == EMIE_RMOUSE_PRESSED_DOWN)\r
                                {\r
-                                       if(g_selected_item > 0)\r
-                                               g_selected_item--;\r
-                                       else\r
-                                               g_selected_item = PLAYER_INVENTORY_SIZE-1;\r
+                                       rightclicked = true;\r
+                               }\r
+                               if(event.MouseInput.Event == EMIE_LMOUSE_LEFT_UP)\r
+                               {\r
+                                       leftreleased = true;\r
+                               }\r
+                               if(event.MouseInput.Event == EMIE_RMOUSE_LEFT_UP)\r
+                               {\r
+                                       rightreleased = true;\r
+                               }\r
+                               if(event.MouseInput.Event == EMIE_MOUSE_WHEEL)\r
+                               {\r
+                                       /*dstream<<"event.MouseInput.Wheel="\r
+                                                       <<event.MouseInput.Wheel<<std::endl;*/\r
+                                       if(event.MouseInput.Wheel < 0)\r
+                                       {\r
+                                               if(g_selected_item < PLAYER_INVENTORY_SIZE-1)\r
+                                                       g_selected_item++;\r
+                                               else\r
+                                                       g_selected_item = 0;\r
+                                       }\r
+                                       else if(event.MouseInput.Wheel > 0)\r
+                                       {\r
+                                               if(g_selected_item > 0)\r
+                                                       g_selected_item--;\r
+                                               else\r
+                                                       g_selected_item = PLAYER_INVENTORY_SIZE-1;\r
+                                       }\r
                                }\r
                        }\r
                }\r
@@ -933,16 +951,18 @@ public:
 \r
                start = m_selection - m_itemcount / 2;\r
 \r
+               InventoryList *mainlist = m_inventory->getList("main");\r
+\r
                for(s32 i=0; i<m_itemcount; i++)\r
                {\r
                        s32 j = i + start;\r
 \r
-                       if(j > (s32)m_inventory->getSize() - 1)\r
-                               j -= m_inventory->getSize();\r
+                       if(j > (s32)mainlist->getSize() - 1)\r
+                               j -= mainlist->getSize();\r
                        if(j < 0)\r
-                               j += m_inventory->getSize();\r
+                               j += mainlist->getSize();\r
                        \r
-                       InventoryItem *item = m_inventory->getItem(j);\r
+                       InventoryItem *item = mainlist->getItem(j);\r
                        // Null items\r
                        if(item == NULL)\r
                        {\r
@@ -1475,7 +1495,7 @@ int main(int argc, char *argv[])
        */\r
        \r
        // This is a copy of the inventory that the client's environment has\r
-       Inventory local_inventory(PLAYER_INVENTORY_SIZE);\r
+       Inventory local_inventory;\r
        \r
        GUIQuickInventory *quick_inventory = new GUIQuickInventory\r
                        (guienv, NULL, v2s32(10, 70), 5, &local_inventory);\r
@@ -1806,8 +1826,7 @@ int main(int argc, char *argv[])
                \r
                if((device->isWindowActive()\r
                                && g_game_focused\r
-                               && !pauseMenu->isVisible()\r
-                               && !inventoryMenu->isVisible()\r
+                               && noMenuActive()\r
                                )\r
                                || random_input)\r
                {\r
index d38d5eac8ad60f995a41862d494a3f508c3e2353..e6caff03cdd92f06f24ae968ce85cc4420f8dd5d 100644 (file)
@@ -29,12 +29,13 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 Player::Player():
        touching_ground(false),
        in_water(false),
-       inventory(PLAYER_INVENTORY_SIZE),
        peer_id(PEER_ID_NEW),
        m_speed(0,0,0),
        m_position(0,0,0)
 {
        updateName("<not set>");
+       inventory.addList("main", PLAYER_INVENTORY_SIZE);
+       inventory.addList("craft", 9);
 }
 
 Player::~Player()
index 9e809bb9a0a72339e8e392175f0faaa311c265c2..9952cb8ebb05a4444c81b1cdc51d0216fc070c8b 100644 (file)
@@ -1252,7 +1252,7 @@ void Server::AsyncRunStep()
                        {
                                // Add to inventory and send inventory
                                InventoryItem *item = new MaterialItem(material, 1);
-                               player->inventory.addItem(item);
+                               player->inventory.addItem("main", item);
                                SendInventory(player->peer_id);
                        }
 
@@ -1632,11 +1632,12 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
                // Left click
                if(button == 0)
                {
-                       if(g_settings.getBool("creative_mode") == false)
+                       InventoryList *ilist = player->inventory.getList("main");
+                       if(g_settings.getBool("creative_mode") == false && ilist != NULL)
                        {
                        
                                // Skip if inventory has no free space
-                               if(player->inventory.getUsedSlots() == player->inventory.getSize())
+                               if(ilist->getUsedSlots() == ilist->getSize())
                                {
                                        dout_server<<"Player inventory has no free space"<<std::endl;
                                        return;
@@ -1645,7 +1646,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
                                // Add to inventory and send inventory
                                InventoryItem *item = new MapBlockObjectItem
                                                (obj->getInventoryString());
-                               player->inventory.addItem(item);
+                               ilist->addItem(item);
                                SendInventory(player->peer_id);
                        }
 
@@ -1746,8 +1747,12 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
                else if(action == 1)
                {
 
+                       InventoryList *ilist = player->inventory.getList("main");
+                       if(ilist == NULL)
+                               return;
+
                        // Get item
-                       InventoryItem *item = player->inventory.getItem(item_i);
+                       InventoryItem *item = ilist->getItem(item_i);
                        
                        // If there is no item, it is not possible to add it anywhere
                        if(item == NULL)
@@ -1796,11 +1801,12 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
                                /*
                                        Handle inventory
                                */
-                               if(g_settings.getBool("creative_mode") == false)
+                               InventoryList *ilist = player->inventory.getList("main");
+                               if(g_settings.getBool("creative_mode") == false && ilist)
                                {
                                        // Remove from inventory and send inventory
                                        if(mitem->getCount() == 1)
-                                               player->inventory.deleteItem(item_i);
+                                               ilist->deleteItem(item_i);
                                        else
                                                mitem->remove(1);
                                        // Send inventory
@@ -1819,11 +1825,12 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
                                /*
                                        Handle inventory
                                */
-                               if(g_settings.getBool("creative_mode") == false)
+                               InventoryList *ilist = player->inventory.getList("main");
+                               if(g_settings.getBool("creative_mode") == false && ilist)
                                {
                                        // Remove from inventory and send inventory
                                        if(mitem->getCount() == 1)
-                                               player->inventory.deleteItem(item_i);
+                                               ilist->deleteItem(item_i);
                                        else
                                                mitem->remove(1);
                                        // Send inventory
@@ -1930,10 +1937,11 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
 
                                //dout_server<<"Placed object"<<std::endl;
 
-                               if(g_settings.getBool("creative_mode") == false)
+                               InventoryList *ilist = player->inventory.getList("main");
+                               if(g_settings.getBool("creative_mode") == false && ilist)
                                {
                                        // Remove from inventory and send inventory
-                                       player->inventory.deleteItem(item_i);
+                                       ilist->deleteItem(item_i);
                                        // Send inventory
                                        SendInventory(peer_id);
                                }
@@ -2190,18 +2198,18 @@ void Server::peerAdded(con::Peer *peer)
                                        continue;
 
                                InventoryItem *item = new MaterialItem(i, 1);
-                               player->inventory.addItem(item);
+                               player->inventory.addItem("main", item);
                        }
                        // Sign
                        {
                                InventoryItem *item = new MapBlockObjectItem("Sign Example text");
-                               bool r = player->inventory.addItem(item);
+                               bool r = player->inventory.addItem("main", item);
                                assert(r == true);
                        }
                        /*// Rat
                        {
                                InventoryItem *item = new MapBlockObjectItem("Rat");
-                               bool r = player->inventory.addItem(item);
+                               bool r = player->inventory.addItem("main", item);
                                assert(r == true);
                        }*/
                }
@@ -2210,21 +2218,21 @@ void Server::peerAdded(con::Peer *peer)
                        // Give some lights
                        {
                                InventoryItem *item = new MaterialItem(3, 999);
-                               bool r = player->inventory.addItem(item);
+                               bool r = player->inventory.addItem("main", item);
                                assert(r == true);
                        }
                        // and some signs
                        for(u16 i=0; i<4; i++)
                        {
                                InventoryItem *item = new MapBlockObjectItem("Sign Example text");
-                               bool r = player->inventory.addItem(item);
+                               bool r = player->inventory.addItem("main", item);
                                assert(r == true);
                        }
                        /*// and some rats
                        for(u16 i=0; i<4; i++)
                        {
                                InventoryItem *item = new MapBlockObjectItem("Rat");
-                               bool r = player->inventory.addItem(item);
+                               bool r = player->inventory.addItem("main", item);
                                assert(r == true);
                        }*/
                }