Remove burn time definitions from FurnaceNodeMetadata
authorPerttu Ahola <celeron55@gmail.com>
Wed, 16 Nov 2011 00:22:41 +0000 (02:22 +0200)
committerPerttu Ahola <celeron55@gmail.com>
Tue, 29 Nov 2011 17:13:46 +0000 (19:13 +0200)
src/content_mapnode.cpp
src/content_nodemeta.cpp
src/inventory.cpp
src/inventory.h
src/materials.cpp
src/materials.h
src/nodedef.cpp
src/nodedef.h
src/scriptapi.cpp

index 30a70679a88c602c5d472fb860e20483f604470c..c3e507e218702ccf9449978bec09d76223651cb5 100644 (file)
@@ -254,6 +254,7 @@ void content_mapnode_init(IWritableNodeDefManager *nodemgr)
        f->is_ground_content = true;
        f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
        f->cookresult_item = "CraftItem lump_of_coal 1";
+       f->furnace_burntime = 30;
        setWoodLikeMaterialProperties(f->material, 1.0);
        
        i = CONTENT_JUNGLETREE;
@@ -263,6 +264,7 @@ void content_mapnode_init(IWritableNodeDefManager *nodemgr)
        f->setTexture(1, "jungletree_top.png");
        f->param_type = CPT_MINERAL;
        f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
+       f->furnace_burntime = 30;
        setWoodLikeMaterialProperties(f->material, 1.0);
        
        i = CONTENT_JUNGLEGRASS;
@@ -277,6 +279,7 @@ void content_mapnode_init(IWritableNodeDefManager *nodemgr)
        f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
        f->walkable = false;
        setLeavesLikeMaterialProperties(f->material, 1.0);
+       f->furnace_burntime = 2;
 
        i = CONTENT_LEAVES;
        f = nodemgr->getModifiable(i);
@@ -289,6 +292,7 @@ void content_mapnode_init(IWritableNodeDefManager *nodemgr)
        f->extra_dug_item_rarity = 20;
        f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
        setLeavesLikeMaterialProperties(f->material, 1.0);
+       f->furnace_burntime = 1.0;
 
        i = CONTENT_CACTUS;
        f = nodemgr->getModifiable(i);
@@ -300,6 +304,7 @@ void content_mapnode_init(IWritableNodeDefManager *nodemgr)
        f->is_ground_content = true;
        f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
        setWoodLikeMaterialProperties(f->material, 0.75);
+       f->furnace_burntime = 15;
 
        i = CONTENT_PAPYRUS;
        f = nodemgr->getModifiable(i);
@@ -312,6 +317,7 @@ void content_mapnode_init(IWritableNodeDefManager *nodemgr)
        f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
        f->walkable = false;
        setLeavesLikeMaterialProperties(f->material, 0.5);
+       f->furnace_burntime = 1;
 
        i = CONTENT_BOOKSHELF;
        f = nodemgr->getModifiable(i);
@@ -324,6 +330,7 @@ void content_mapnode_init(IWritableNodeDefManager *nodemgr)
        f->param_type = CPT_MINERAL;
        f->is_ground_content = true;
        setWoodLikeMaterialProperties(f->material, 0.75);
+       f->furnace_burntime = 30;
 
        i = CONTENT_GLASS;
        f = nodemgr->getModifiable(i);
@@ -350,6 +357,7 @@ void content_mapnode_init(IWritableNodeDefManager *nodemgr)
        f->selection_box.type = NODEBOX_FIXED;
        f->selection_box.fixed = core::aabbox3d<f32>(
                        -BS/7, -BS/2, -BS/7, BS/7, BS/2, BS/7);
+       f->furnace_burntime = 30/2;
        setWoodLikeMaterialProperties(f->material, 0.75);
 
        i = CONTENT_RAIL;
@@ -367,6 +375,7 @@ void content_mapnode_init(IWritableNodeDefManager *nodemgr)
        f->air_equivalent = true; // grass grows underneath
        f->walkable = false;
        f->selection_box.type = NODEBOX_FIXED;
+       f->furnace_burntime = 5;
        setDirtLikeMaterialProperties(f->material, 0.75);
 
        i = CONTENT_LADDER;
@@ -383,6 +392,7 @@ void content_mapnode_init(IWritableNodeDefManager *nodemgr)
        f->walkable = false;
        f->climbable = true;
        f->selection_box.type = NODEBOX_WALLMOUNTED;
+       f->furnace_burntime = 5;
        setWoodLikeMaterialProperties(f->material, 0.5);
 
        // Deprecated
@@ -398,6 +408,7 @@ void content_mapnode_init(IWritableNodeDefManager *nodemgr)
        f->setInventoryTextureCube("wood.png", "wood.png", "wood.png");
        f->is_ground_content = true;
        f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
+       f->furnace_burntime = 30/4;
        setWoodLikeMaterialProperties(f->material, 0.75);
        
        i = CONTENT_MESE;
@@ -406,6 +417,7 @@ void content_mapnode_init(IWritableNodeDefManager *nodemgr)
        f->setInventoryTextureCube("mese.png", "mese.png", "mese.png");
        f->is_ground_content = true;
        f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
+       f->furnace_burntime = 30;
        setStoneLikeMaterialProperties(f->material, 0.5);
        
        i = CONTENT_CLOUD;
@@ -509,6 +521,7 @@ void content_mapnode_init(IWritableNodeDefManager *nodemgr)
        f->post_effect_color = video::SColor(192, 255, 64, 0);
        // New-style lava source material (mostly unused)
        f->setSpecialMaterial(0, MaterialSpec("lava.png", false));
+       f->furnace_burntime = 60;
        
        i = CONTENT_TORCH;
        f = nodemgr->getModifiable(i);
@@ -533,6 +546,7 @@ void content_mapnode_init(IWritableNodeDefManager *nodemgr)
        f->selection_box.wall_side = core::aabbox3d<f32>(
                        -BS/2, -BS/3.333, -BS/10, -BS/2+BS/3.333, BS/3.333, BS/10);
        setConstantMaterialProperties(f->material, 0.0);
+       f->furnace_burntime = 4;
        
        i = CONTENT_SIGN_WALL;
        f = nodemgr->getModifiable(i);
@@ -550,6 +564,7 @@ void content_mapnode_init(IWritableNodeDefManager *nodemgr)
                f->initial_metadata = new SignNodeMetadata(NULL, "Some sign");
        setConstantMaterialProperties(f->material, 0.5);
        f->selection_box.type = NODEBOX_WALLMOUNTED;
+       f->furnace_burntime = 10;
        
        i = CONTENT_CHEST;
        f = nodemgr->getModifiable(i);
@@ -564,6 +579,7 @@ void content_mapnode_init(IWritableNodeDefManager *nodemgr)
        if(f->initial_metadata == NULL)
                f->initial_metadata = new ChestNodeMetadata(NULL);
        setWoodLikeMaterialProperties(f->material, 1.0);
+       f->furnace_burntime = 30;
        
        i = CONTENT_LOCKABLE_CHEST;
        f = nodemgr->getModifiable(i);
@@ -578,6 +594,7 @@ void content_mapnode_init(IWritableNodeDefManager *nodemgr)
        if(f->initial_metadata == NULL)
                f->initial_metadata = new LockingChestNodeMetadata(NULL);
        setWoodLikeMaterialProperties(f->material, 1.0);
+       f->furnace_burntime = 30;
 
        i = CONTENT_FURNACE;
        f = nodemgr->getModifiable(i);
@@ -629,6 +646,7 @@ void content_mapnode_init(IWritableNodeDefManager *nodemgr)
        f->setInventoryTexture("nc_front.png");
        f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
        setStoneLikeMaterialProperties(f->material, 3.0);
+       f->furnace_burntime = 1;
        
        i = CONTENT_NC_RB;
        f = nodemgr->getModifiable(i);
@@ -636,6 +654,7 @@ void content_mapnode_init(IWritableNodeDefManager *nodemgr)
        f->setInventoryTexture("nc_rb.png");
        f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
        setStoneLikeMaterialProperties(f->material, 3.0);
+       f->furnace_burntime = 1;
 
        i = CONTENT_SAPLING;
        f = nodemgr->getModifiable(i);
@@ -649,6 +668,7 @@ void content_mapnode_init(IWritableNodeDefManager *nodemgr)
        f->air_equivalent = false;
        f->walkable = false;
        setConstantMaterialProperties(f->material, 0.0);
+       f->furnace_burntime = 10;
        
        i = CONTENT_APPLE;
        f = nodemgr->getModifiable(i);
@@ -663,6 +683,7 @@ void content_mapnode_init(IWritableNodeDefManager *nodemgr)
        f->air_equivalent = true;
        f->dug_item = std::string("CraftItem apple 1");
        setConstantMaterialProperties(f->material, 0.0);
+       f->furnace_burntime = 3;
 }
 
 
index 50dcbd080c0866595e50184a09439754a12355f1..17b4a3da4381fdffcffc1287c04146596985fe9c 100644 (file)
@@ -326,7 +326,7 @@ bool FurnaceNodeMetadata::step(float dtime)
                // accomodate any result item
                if(room_available)
                {
-                       m_src_totaltime = 3;
+                       m_src_totaltime = src_item->getCookTime();
                }
                else
                {
@@ -381,85 +381,12 @@ bool FurnaceNodeMetadata::step(float dtime)
                assert(fuel_list);
                const InventoryItem *fuel_item = fuel_list->getItem(0);
 
-               if(ItemSpec(ITEM_MATERIAL, CONTENT_TREE).checkItem(fuel_item))
-               {
-                       m_fuel_totaltime = 30;
-                       m_fuel_time = 0;
-                       fuel_list->decrementMaterials(1);
-                       changed = true;
-               }
-               else if(ItemSpec(ITEM_MATERIAL, CONTENT_JUNGLETREE).checkItem(fuel_item))
-               {
-                       m_fuel_totaltime = 30;
-                       m_fuel_time = 0;
-                       fuel_list->decrementMaterials(1);
-                       changed = true;
-               }
-               else if(ItemSpec(ITEM_MATERIAL, CONTENT_FENCE).checkItem(fuel_item))
-               {
-                       m_fuel_totaltime = 30/2;
-                       m_fuel_time = 0;
-                       fuel_list->decrementMaterials(1);
-                       changed = true;
-               }
-               else if(ItemSpec(ITEM_MATERIAL, CONTENT_WOOD).checkItem(fuel_item))
-               {
-                       m_fuel_totaltime = 30/4;
-                       m_fuel_time = 0;
-                       fuel_list->decrementMaterials(1);
-                       changed = true;
-               }
-               else if(ItemSpec(ITEM_MATERIAL, CONTENT_BOOKSHELF).checkItem(fuel_item))
-               {
-                       m_fuel_totaltime = 30/4;
-                       m_fuel_time = 0;
-                       fuel_list->decrementMaterials(1);
-                       changed = true;
-               }
-               else if(ItemSpec(ITEM_MATERIAL, CONTENT_LEAVES).checkItem(fuel_item))
-               {
-                       m_fuel_totaltime = 30/16;
-                       m_fuel_time = 0;
-                       fuel_list->decrementMaterials(1);
-                       changed = true;
-               }
-               else if(ItemSpec(ITEM_MATERIAL, CONTENT_PAPYRUS).checkItem(fuel_item))
-               {
-                       m_fuel_totaltime = 30/32;
-                       m_fuel_time = 0;
-                       fuel_list->decrementMaterials(1);
-                       changed = true;
-               }
-               else if(ItemSpec(ITEM_MATERIAL, CONTENT_JUNGLEGRASS).checkItem(fuel_item))
-               {
-                       m_fuel_totaltime = 30/32;
-                       m_fuel_time = 0;
-                       fuel_list->decrementMaterials(1);
-                       changed = true;
-               }
-               else if(ItemSpec(ITEM_MATERIAL, CONTENT_CACTUS).checkItem(fuel_item))
-               {
-                       m_fuel_totaltime = 30/4;
+               if(fuel_item && fuel_item->getBurnTime() >= 0){
+                       m_fuel_totaltime = fuel_item->getBurnTime();
                        m_fuel_time = 0;
                        fuel_list->decrementMaterials(1);
                        changed = true;
-               }
-               else if(ItemSpec(ITEM_CRAFT, "Stick").checkItem(fuel_item))
-               {
-                       m_fuel_totaltime = 30/4/4;
-                       m_fuel_time = 0;
-                       fuel_list->decrementMaterials(1);
-                       changed = true;
-               }
-               else if(ItemSpec(ITEM_CRAFT, "lump_of_coal").checkItem(fuel_item))
-               {
-                       m_fuel_totaltime = 40;
-                       m_fuel_time = 0;
-                       fuel_list->decrementMaterials(1);
-                       changed = true;
-               }
-               else
-               {
+               } else {
                        //infostream<<"No fuel found"<<std::endl;
                        // No fuel, stop loop.
                        m_step_accumulator = 0;
index 6d0a2a21440b4171f26e302558579b3fbe3de37c..98bf57738ef0edc02a42d9836361c8951d671a60 100644 (file)
@@ -171,6 +171,20 @@ InventoryItem *MaterialItem::createCookResult() const
        return InventoryItem::deSerialize(is, m_gamedef);
 }
 
+float MaterialItem::getCookTime() const
+{
+       INodeDefManager *ndef = m_gamedef->ndef();
+       const ContentFeatures &f = ndef->get(m_content);
+       return f.furnace_cooktime;
+}
+
+float MaterialItem::getBurnTime() const
+{
+       INodeDefManager *ndef = m_gamedef->ndef();
+       const ContentFeatures &f = ndef->get(m_content);
+       return f.furnace_burntime;
+}
+
 /*
        ToolItem
 */
@@ -258,6 +272,18 @@ InventoryItem *CraftItem::createCookResult() const
        return item_craft_create_cook_result(m_subname, m_gamedef);
 }
 
+float CraftItem::getCookTime() const
+{
+       return 3.0;
+}
+
+float CraftItem::getBurnTime() const
+{
+       if(m_subname == "lump_of_coal")
+               return 40;
+       return -1;
+}
+
 bool CraftItem::use(ServerEnvironment *env, ServerActiveObject *user)
 {
        if(!item_craft_is_eatable(m_subname, m_gamedef))
index 5401ff1b947f32977754a4679bea28eeabb9a63c..b9de48f9af641de8189b54ac13cf0463cc27a23b 100644 (file)
@@ -106,10 +106,12 @@ public:
 
        // Whether it can be cooked
        virtual bool isCookable() const {return false;}
-       // Time of cooking
-       virtual float getCookTime(){return 3.0;}
        // Result of cooking (can randomize)
        virtual InventoryItem *createCookResult() const {return NULL;}
+       // Time of cooking
+       virtual float getCookTime() const {return 3.0;}
+       // Whether it can be burned (<0 = cannot be burned)
+       virtual float getBurnTime() const {return -1;}
        
        // Eat, press, activate, whatever.
        // Called when item is right-clicked when lying on ground.
@@ -180,6 +182,8 @@ public:
        */
        bool isCookable() const;
        InventoryItem *createCookResult() const;
+       float getCookTime() const;
+       float getBurnTime() const;
        /*
                Special methods
        */
@@ -258,6 +262,8 @@ public:
 
        bool isCookable() const;
        InventoryItem *createCookResult() const;
+       float getCookTime() const;
+       float getBurnTime() const;
 
        bool use(ServerEnvironment *env, ServerActiveObject *user);
        
index ab2e2d2730982aeb1c335f6d6d0c47346e555cb4..5c89eafd8b9eba5343c891703e6f31e5d1270861 100644 (file)
@@ -32,6 +32,7 @@ void MaterialProperties::serialize(std::ostream &os)
        writeF1000(os, crackiness);
        writeF1000(os, crumbliness);
        writeF1000(os, cuttability);
+       writeF1000(os, flammability);
 }
 
 void MaterialProperties::deSerialize(std::istream &is)
@@ -45,6 +46,7 @@ void MaterialProperties::deSerialize(std::istream &is)
        crackiness = readF1000(is);
        crumbliness = readF1000(is);
        cuttability = readF1000(is);
+       flammability = readF1000(is);
 }
 
 DiggingProperties getDiggingProperties(u16 content, ToolDiggingProperties *tp,
index 4e067fd6674e513aacf4d7c7d768eef5ae9d7267..9db33fc638aab2eaf34f297796db787dd93969be 100644 (file)
@@ -56,15 +56,16 @@ struct MaterialProperties
        // Sword is best for cuttable light stuff.
        float cuttability;
        // If high, ignites easily
-       //float flammability;
+       float flammability;
 
        MaterialProperties():
                diggability(DIGGABLE_NOT),
                constant_time(0.5),
-               weight(1),
-               crackiness(1),
-               crumbliness(1),
-               cuttability(1)
+               weight(0),
+               crackiness(0),
+               crumbliness(0),
+               cuttability(0),
+               flammability(0)
        {}
 
        void serialize(std::ostream &os);
index 2e0c6fad67f71e6e9d7d8aa955355b00b76a530f..210e466d2dfadbc2f14e654443c2fe48734f2fb8 100644 (file)
@@ -151,7 +151,9 @@ void ContentFeatures::reset()
        damage_per_second = 0;
        selection_box = NodeBox();
        material = MaterialProperties();
-       cookresult_item = "";
+       cookresult_item = ""; // Cannot be cooked
+       furnace_cooktime = 3.0;
+       furnace_burntime = -1.0; // Cannot be burned
 }
 
 void ContentFeatures::serialize(std::ostream &os)
@@ -202,6 +204,8 @@ void ContentFeatures::serialize(std::ostream &os)
        selection_box.serialize(os);
        material.serialize(os);
        os<<serializeString(cookresult_item);
+       writeF1000(os, furnace_cooktime);
+       writeF1000(os, furnace_burntime);
 }
 
 void ContentFeatures::deSerialize(std::istream &is, IGameDef *gamedef)
@@ -255,6 +259,8 @@ void ContentFeatures::deSerialize(std::istream &is, IGameDef *gamedef)
        selection_box.deSerialize(is);
        material.deSerialize(is);
        cookresult_item = deSerializeString(is);
+       furnace_cooktime = readF1000(is);
+       furnace_burntime = readF1000(is);
 }
 
 void ContentFeatures::setTexture(u16 i, std::string name)
index fe7c454d27040099211190b312bad39abd479602..b29f2173411765264afcb91af7e7af8660334c00 100644 (file)
@@ -207,6 +207,8 @@ struct ContentFeatures
        NodeBox selection_box;
        MaterialProperties material;
        std::string cookresult_item;
+       float furnace_cooktime;
+       float furnace_burntime;
 
        /*
                Methods
index f15b6cd45111a991502ececa49d2f05bad7979e8..64c6859327b0b411f8dee2d661b5cedb07828f82 100644 (file)
@@ -40,7 +40,8 @@ extern "C" {
 /*
 TODO:
 - Node definition
-- Random node triggers
+- Random node triggers (like grass growth)
+- Deterministic node triggers (like falling sand)
 - Object visual client-side stuff
        - Blink effect
        - Spritesheets and animation
@@ -52,7 +53,7 @@ TODO:
        blockdef.on_inventory_modified
        meta.set("owner", playername)
        meta.get("owner")
-- Item definition
+- Item definition (actually, only CraftItem)
 */
 
 static void stackDump(lua_State *L, std::ostream &o)