Update inventory texture too
[oweals/minetest.git] / src / content_craft.cpp
index 069e68300b9bdf412c082a84b7aaa2fdc250c19e..024fc6f098d541b573b2d8f628fe7d7d62bdad06 100644 (file)
@@ -21,12 +21,13 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "inventory.h"
 #include "content_mapnode.h"
 #include "player.h"
+#include "mapnode.h" // For content_t
 
 /*
        items: actually *items[9]
        return value: allocates a new item, or returns NULL.
 */
-InventoryItem *craft_get_result(InventoryItem **items)
+InventoryItem *craft_get_result(InventoryItem **items, IGameDef *gamedef)
 {
        // Wood
        {
@@ -34,7 +35,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
                specs[0] = ItemSpec(ITEM_MATERIAL, CONTENT_TREE);
                if(checkItemCombination(items, specs))
                {
-                       return new MaterialItem(CONTENT_WOOD, 4);
+                       return new MaterialItem(gamedef, CONTENT_WOOD, 4);
                }
        }
 
@@ -44,7 +45,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
                specs[0] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
                if(checkItemCombination(items, specs))
                {
-                       return new CraftItem("Stick", 4);
+                       return new CraftItem(gamedef, "Stick", 4);
                }
        }
 
@@ -59,7 +60,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
                specs[8] = ItemSpec(ITEM_CRAFT, "Stick");
                if(checkItemCombination(items, specs))
                {
-                       return new MaterialItem(CONTENT_FENCE, 2);
+                       return new MaterialItem(gamedef, CONTENT_FENCE, 2);
                }
        }
 
@@ -75,8 +76,8 @@ InventoryItem *craft_get_result(InventoryItem **items)
                specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
                if(checkItemCombination(items, specs))
                {
-                       //return new MapBlockObjectItem("Sign");
-                       return new MaterialItem(CONTENT_SIGN_WALL, 1);
+                       //return new MapBlockObjectItem(gamedef, "Sign");
+                       return new MaterialItem(gamedef, CONTENT_SIGN_WALL, 1);
                }
        }
 
@@ -87,7 +88,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
                specs[3] = ItemSpec(ITEM_CRAFT, "Stick");
                if(checkItemCombination(items, specs))
                {
-                       return new MaterialItem(CONTENT_TORCH, 4);
+                       return new MaterialItem(gamedef, CONTENT_TORCH, 4);
                }
        }
 
@@ -101,7 +102,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
                specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
                if(checkItemCombination(items, specs))
                {
-                       return new ToolItem("WPick", 0);
+                       return new ToolItem(gamedef, "WPick", 0);
                }
        }
 
@@ -115,7 +116,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
                specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
                if(checkItemCombination(items, specs))
                {
-                       return new ToolItem("STPick", 0);
+                       return new ToolItem(gamedef, "STPick", 0);
                }
        }
 
@@ -129,7 +130,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
                specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
                if(checkItemCombination(items, specs))
                {
-                       return new ToolItem("SteelPick", 0);
+                       return new ToolItem(gamedef, "SteelPick", 0);
                }
        }
 
@@ -143,7 +144,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
                specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
                if(checkItemCombination(items, specs))
                {
-                       return new ToolItem("MesePick", 0);
+                       return new ToolItem(gamedef, "MesePick", 0);
                }
        }
 
@@ -155,7 +156,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
                specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
                if(checkItemCombination(items, specs))
                {
-                       return new ToolItem("WShovel", 0);
+                       return new ToolItem(gamedef, "WShovel", 0);
                }
        }
 
@@ -167,7 +168,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
                specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
                if(checkItemCombination(items, specs))
                {
-                       return new ToolItem("STShovel", 0);
+                       return new ToolItem(gamedef, "STShovel", 0);
                }
        }
 
@@ -179,7 +180,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
                specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
                if(checkItemCombination(items, specs))
                {
-                       return new ToolItem("SteelShovel", 0);
+                       return new ToolItem(gamedef, "SteelShovel", 0);
                }
        }
 
@@ -193,7 +194,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
                specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
                if(checkItemCombination(items, specs))
                {
-                       return new ToolItem("WAxe", 0);
+                       return new ToolItem(gamedef, "WAxe", 0);
                }
        }
 
@@ -207,7 +208,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
                specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
                if(checkItemCombination(items, specs))
                {
-                       return new ToolItem("STAxe", 0);
+                       return new ToolItem(gamedef, "STAxe", 0);
                }
        }
 
@@ -221,7 +222,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
                specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
                if(checkItemCombination(items, specs))
                {
-                       return new ToolItem("SteelAxe", 0);
+                       return new ToolItem(gamedef, "SteelAxe", 0);
                }
        }
 
@@ -233,7 +234,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
                specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
                if(checkItemCombination(items, specs))
                {
-                       return new ToolItem("WSword", 0);
+                       return new ToolItem(gamedef, "WSword", 0);
                }
        }
 
@@ -245,7 +246,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
                specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
                if(checkItemCombination(items, specs))
                {
-                       return new ToolItem("STSword", 0);
+                       return new ToolItem(gamedef, "STSword", 0);
                }
        }
 
@@ -257,7 +258,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
                specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
                if(checkItemCombination(items, specs))
                {
-                       return new ToolItem("SteelSword", 0);
+                       return new ToolItem(gamedef, "SteelSword", 0);
                }
        }
 
@@ -275,7 +276,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
                specs[8] = ItemSpec(ITEM_CRAFT, "steel_ingot");
                if(checkItemCombination(items, specs))
                {
-                       return new MaterialItem(CONTENT_RAIL, 15);
+                       return new MaterialItem(gamedef, CONTENT_RAIL, 15);
                }
        }
 
@@ -292,7 +293,25 @@ InventoryItem *craft_get_result(InventoryItem **items)
                specs[8] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
                if(checkItemCombination(items, specs))
                {
-                       return new MaterialItem(CONTENT_CHEST, 1);
+                       return new MaterialItem(gamedef, CONTENT_CHEST, 1);
+               }
+       }
+
+       // Locking Chest
+       {
+               ItemSpec specs[9];
+               specs[0] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
+               specs[1] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
+               specs[2] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
+               specs[3] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
+               specs[4] = ItemSpec(ITEM_CRAFT, "steel_ingot");
+               specs[5] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
+               specs[6] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
+               specs[7] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
+               specs[8] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
+               if(checkItemCombination(items, specs))
+               {
+                       return new MaterialItem(gamedef, CONTENT_LOCKABLE_CHEST, 1);
                }
        }
 
@@ -309,7 +328,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
                specs[8] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE);
                if(checkItemCombination(items, specs))
                {
-                       return new MaterialItem(CONTENT_FURNACE, 1);
+                       return new MaterialItem(gamedef, CONTENT_FURNACE, 1);
                }
        }
 
@@ -327,7 +346,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
                specs[8] = ItemSpec(ITEM_CRAFT, "steel_ingot");
                if(checkItemCombination(items, specs))
                {
-                       return new MaterialItem(CONTENT_STEEL, 1);
+                       return new MaterialItem(gamedef, CONTENT_STEEL, 1);
                }
        }
 
@@ -340,7 +359,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
                specs[7] = ItemSpec(ITEM_MATERIAL, CONTENT_SAND);
                if(checkItemCombination(items, specs))
                {
-                       return new MaterialItem(CONTENT_SANDSTONE, 1);
+                       return new MaterialItem(gamedef, CONTENT_SANDSTONE, 1);
                }
        }
 
@@ -353,7 +372,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
                specs[7] = ItemSpec(ITEM_CRAFT, "lump_of_clay");
                if(checkItemCombination(items, specs))
                {
-                       return new MaterialItem(CONTENT_CLAY, 1);
+                       return new MaterialItem(gamedef, CONTENT_CLAY, 1);
                }
        }
 
@@ -366,7 +385,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
                specs[7] = ItemSpec(ITEM_CRAFT, "clay_brick");
                if(checkItemCombination(items, specs))
                {
-                       return new MaterialItem(CONTENT_BRICK, 1);
+                       return new MaterialItem(gamedef, CONTENT_BRICK, 1);
                }
        }
 
@@ -378,7 +397,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
                specs[5] = ItemSpec(ITEM_MATERIAL, CONTENT_PAPYRUS);
                if(checkItemCombination(items, specs))
                {
-                       return new CraftItem("paper", 1);
+                       return new CraftItem(gamedef, "paper", 1);
                }
        }
 
@@ -390,7 +409,7 @@ InventoryItem *craft_get_result(InventoryItem **items)
                specs[7] = ItemSpec(ITEM_CRAFT, "paper");
                if(checkItemCombination(items, specs))
                {
-                       return new CraftItem("book", 1);
+                       return new CraftItem(gamedef, "book", 1);
                }
        }
 
@@ -408,35 +427,65 @@ InventoryItem *craft_get_result(InventoryItem **items)
                specs[8] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
                if(checkItemCombination(items, specs))
                {
-                       return new MaterialItem(CONTENT_BOOKSHELF, 1);
+                       return new MaterialItem(gamedef, CONTENT_BOOKSHELF, 1);
+               }
+       }
+
+       // Ladder
+       {
+               ItemSpec specs[9];
+               specs[0] = ItemSpec(ITEM_CRAFT, "Stick");
+               specs[2] = ItemSpec(ITEM_CRAFT, "Stick");
+               specs[3] = ItemSpec(ITEM_CRAFT, "Stick");
+               specs[4] = ItemSpec(ITEM_CRAFT, "Stick");
+               specs[5] = ItemSpec(ITEM_CRAFT, "Stick");
+               specs[6] = ItemSpec(ITEM_CRAFT, "Stick");
+               specs[8] = ItemSpec(ITEM_CRAFT, "Stick");
+               if(checkItemCombination(items, specs))
+               {
+                       return new MaterialItem(gamedef, CONTENT_LADDER, 1);
+               }
+       }
+       
+       // Iron Apple
+       {
+               ItemSpec specs[9];
+               specs[1] = ItemSpec(ITEM_CRAFT, "steel_ingot");
+               specs[3] = ItemSpec(ITEM_CRAFT, "steel_ingot");
+               specs[4] = ItemSpec(ITEM_CRAFT, "apple");
+               specs[5] = ItemSpec(ITEM_CRAFT, "steel_ingot");
+               specs[7] = ItemSpec(ITEM_CRAFT, "steel_ingot");
+               if(checkItemCombination(items, specs))
+               {
+                       return new CraftItem(gamedef, "apple_iron", 1);
                }
        }
 
        return NULL;
 }
 
-void craft_set_creative_inventory(Player *player)
+void craft_set_creative_inventory(Player *player, IGameDef *gamedef)
 {
        player->resetInventory();
        
        // Give some good tools
        {
-               InventoryItem *item = new ToolItem("MesePick", 0);
+               InventoryItem *item = new ToolItem(gamedef, "MesePick", 0);
                void* r = player->inventory.addItem("main", item);
                assert(r == NULL);
        }
        {
-               InventoryItem *item = new ToolItem("SteelPick", 0);
+               InventoryItem *item = new ToolItem(gamedef, "SteelPick", 0);
                void* r = player->inventory.addItem("main", item);
                assert(r == NULL);
        }
        {
-               InventoryItem *item = new ToolItem("SteelAxe", 0);
+               InventoryItem *item = new ToolItem(gamedef, "SteelAxe", 0);
                void* r = player->inventory.addItem("main", item);
                assert(r == NULL);
        }
        {
-               InventoryItem *item = new ToolItem("SteelShovel", 0);
+               InventoryItem *item = new ToolItem(gamedef, "SteelShovel", 0);
                void* r = player->inventory.addItem("main", item);
                assert(r == NULL);
        }
@@ -446,7 +495,7 @@ void craft_set_creative_inventory(Player *player)
        */
        
        // CONTENT_IGNORE-terminated list
-       u8 material_items[] = {
+       content_t material_items[] = {
                CONTENT_TORCH,
                CONTENT_COBBLE,
                CONTENT_MUD,
@@ -469,16 +518,17 @@ void craft_set_creative_inventory(Player *player)
                CONTENT_CHEST,
                CONTENT_FURNACE,
                CONTENT_SIGN_WALL,
+               CONTENT_LAVASOURCE,
                CONTENT_IGNORE
        };
        
-       u8 *mip = material_items;
+       content_t *mip = material_items;
        for(u16 i=0; i<PLAYER_INVENTORY_SIZE; i++)
        {
                if(*mip == CONTENT_IGNORE)
                        break;
 
-               InventoryItem *item = new MaterialItem(*mip, 1);
+               InventoryItem *item = new MaterialItem(gamedef, *mip, 1);
                player->inventory.addItem("main", item);
 
                mip++;
@@ -488,7 +538,7 @@ void craft_set_creative_inventory(Player *player)
        assert(USEFUL_CONTENT_COUNT <= PLAYER_INVENTORY_SIZE);
        
        // add torch first
-       InventoryItem *item = new MaterialItem(CONTENT_TORCH, 1);
+       InventoryItem *item = new MaterialItem(gamedef, CONTENT_TORCH, 1);
        player->inventory.addItem("main", item);
        
        // Then others
@@ -499,86 +549,86 @@ void craft_set_creative_inventory(Player *player)
                        || i == CONTENT_COALSTONE)
                        continue;
 
-               InventoryItem *item = new MaterialItem(i, 1);
+               InventoryItem *item = new MaterialItem(gamedef, i, 1);
                player->inventory.addItem("main", item);
        }
 #endif
 
        /*// Sign
        {
-               InventoryItem *item = new MapBlockObjectItem("Sign Example text");
+               InventoryItem *item = new MapBlockObjectItem(gamedef, "Sign Example text");
                void* r = player->inventory.addItem("main", item);
                assert(r == NULL);
        }*/
 }
 
-void craft_give_initial_stuff(Player *player)
+void craft_give_initial_stuff(Player *player, IGameDef *gamedef)
 {
        {
-               InventoryItem *item = new ToolItem("SteelPick", 0);
+               InventoryItem *item = new ToolItem(gamedef, "SteelPick", 0);
                void* r = player->inventory.addItem("main", item);
                assert(r == NULL);
        }
        {
-               InventoryItem *item = new MaterialItem(CONTENT_TORCH, 99);
+               InventoryItem *item = new MaterialItem(gamedef, CONTENT_TORCH, 99);
                void* r = player->inventory.addItem("main", item);
                assert(r == NULL);
        }
        {
-               InventoryItem *item = new ToolItem("SteelAxe", 0);
+               InventoryItem *item = new ToolItem(gamedef, "SteelAxe", 0);
                void* r = player->inventory.addItem("main", item);
                assert(r == NULL);
        }
        {
-               InventoryItem *item = new ToolItem("SteelShovel", 0);
+               InventoryItem *item = new ToolItem(gamedef, "SteelShovel", 0);
                void* r = player->inventory.addItem("main", item);
                assert(r == NULL);
        }
        {
-               InventoryItem *item = new MaterialItem(CONTENT_COBBLE, 99);
+               InventoryItem *item = new MaterialItem(gamedef, CONTENT_COBBLE, 99);
                void* r = player->inventory.addItem("main", item);
                assert(r == NULL);
        }
        /*{
-               InventoryItem *item = new MaterialItem(CONTENT_MESE, 6);
+               InventoryItem *item = new MaterialItem(gamedef, CONTENT_MESE, 6);
                void* r = player->inventory.addItem("main", item);
                assert(r == NULL);
        }
        {
-               InventoryItem *item = new MaterialItem(CONTENT_COALSTONE, 6);
+               InventoryItem *item = new MaterialItem(gamedef, CONTENT_COALSTONE, 6);
                void* r = player->inventory.addItem("main", item);
                assert(r == NULL);
        }
        {
-               InventoryItem *item = new MaterialItem(CONTENT_WOOD, 6);
+               InventoryItem *item = new MaterialItem(gamedef, CONTENT_WOOD, 6);
                void* r = player->inventory.addItem("main", item);
                assert(r == NULL);
        }
        {
-               InventoryItem *item = new CraftItem("Stick", 4);
+               InventoryItem *item = new CraftItem(gamedef, "Stick", 4);
                void* r = player->inventory.addItem("main", item);
                assert(r == NULL);
        }
        {
-               InventoryItem *item = new ToolItem("WPick", 32000);
+               InventoryItem *item = new ToolItem(gamedef, "WPick", 32000);
                void* r = player->inventory.addItem("main", item);
                assert(r == NULL);
        }
        {
-               InventoryItem *item = new ToolItem("STPick", 32000);
+               InventoryItem *item = new ToolItem(gamedef, "STPick", 32000);
                void* r = player->inventory.addItem("main", item);
                assert(r == NULL);
        }*/
        /*// and some signs
        for(u16 i=0; i<4; i++)
        {
-               InventoryItem *item = new MapBlockObjectItem("Sign Example text");
+               InventoryItem *item = new MapBlockObjectItem(gamedef, "Sign Example text");
                bool r = player->inventory.addItem("main", item);
                assert(r == true);
        }*/
        /*// Give some other stuff
        {
-               InventoryItem *item = new MaterialItem(CONTENT_TREE, 999);
+               InventoryItem *item = new MaterialItem(gamedef, CONTENT_TREE, 999);
                bool r = player->inventory.addItem("main", item);
                assert(r == true);
        }*/