From 37a5f8a30bc2e267909d699faef4910a3a261555 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Wed, 16 Nov 2011 01:34:09 +0200 Subject: Move cook result properly to ContentFeatures --- src/content_inventory.cpp | 25 ++----------------------- src/content_inventory.h | 4 ---- src/content_mapnode.cpp | 3 +++ src/inventory.cpp | 9 +++++++-- src/nodedef.cpp | 5 +++++ src/nodedef.h | 2 ++ 6 files changed, 19 insertions(+), 29 deletions(-) (limited to 'src') diff --git a/src/content_inventory.cpp b/src/content_inventory.cpp index 349d47d5b..2a05b76f0 100644 --- a/src/content_inventory.cpp +++ b/src/content_inventory.cpp @@ -22,29 +22,8 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "content_mapnode.h" //#include "serverobject.h" #include "content_sao.h" - -bool item_material_is_cookable(content_t content, IGameDef *gamedef) -{ - if(content == CONTENT_TREE) - return true; - else if(content == CONTENT_COBBLE) - return true; - else if(content == CONTENT_SAND) - return true; - return false; -} - -InventoryItem* item_material_create_cook_result(content_t content, - IGameDef *gamedef) -{ - if(content == CONTENT_TREE) - return new CraftItem(gamedef, "lump_of_coal", 1); - else if(content == CONTENT_COBBLE) - return new MaterialItem(gamedef, CONTENT_STONE, 1); - else if(content == CONTENT_SAND) - return new MaterialItem(gamedef, CONTENT_GLASS, 1); - return NULL; -} +//#include "gamedef.h" +//#include "nodedef.h" std::string item_craft_get_image_name(const std::string &subname, IGameDef *gamedef) diff --git a/src/content_inventory.h b/src/content_inventory.h index 0b384f15e..40e8f545a 100644 --- a/src/content_inventory.h +++ b/src/content_inventory.h @@ -29,10 +29,6 @@ class ServerActiveObject; class ServerEnvironment; class IGameDef; -bool item_material_is_cookable(content_t content, IGameDef *gamedef); -InventoryItem* item_material_create_cook_result(content_t content, - IGameDef *gamedef); - std::string item_craft_get_image_name(const std::string &subname, IGameDef *gamedef); ServerActiveObject* item_craft_create_object(const std::string &subname, diff --git a/src/content_mapnode.cpp b/src/content_mapnode.cpp index c33d8c4a2..30a70679a 100644 --- a/src/content_mapnode.cpp +++ b/src/content_mapnode.cpp @@ -206,6 +206,7 @@ void content_mapnode_init(IWritableNodeDefManager *nodemgr) f->param_type = CPT_MINERAL; f->is_ground_content = true; f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1"; + f->cookresult_item = std::string("MaterialItem2 ")+itos(CONTENT_GLASS)+" 1"; setDirtLikeMaterialProperties(f->material, 1.0); i = CONTENT_GRAVEL; @@ -252,6 +253,7 @@ void content_mapnode_init(IWritableNodeDefManager *nodemgr) f->param_type = CPT_MINERAL; f->is_ground_content = true; f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1"; + f->cookresult_item = "CraftItem lump_of_coal 1"; setWoodLikeMaterialProperties(f->material, 1.0); i = CONTENT_JUNGLETREE; @@ -596,6 +598,7 @@ void content_mapnode_init(IWritableNodeDefManager *nodemgr) f->param_type = CPT_NONE; f->is_ground_content = true; f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1"; + f->cookresult_item = std::string("MaterialItem2 ")+itos(CONTENT_STONE)+" 1"; setStoneLikeMaterialProperties(f->material, 0.9); i = CONTENT_MOSSYCOBBLE; diff --git a/src/inventory.cpp b/src/inventory.cpp index 1929761a5..6d0a2a214 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -158,12 +158,17 @@ video::ITexture * MaterialItem::getImage(ITextureSource *tsrc) const bool MaterialItem::isCookable() const { - return item_material_is_cookable(m_content, m_gamedef); + INodeDefManager *ndef = m_gamedef->ndef(); + const ContentFeatures &f = ndef->get(m_content); + return (f.cookresult_item != ""); } InventoryItem *MaterialItem::createCookResult() const { - return item_material_create_cook_result(m_content, m_gamedef); + INodeDefManager *ndef = m_gamedef->ndef(); + const ContentFeatures &f = ndef->get(m_content); + std::istringstream is(f.cookresult_item, std::ios::binary); + return InventoryItem::deSerialize(is, m_gamedef); } /* diff --git a/src/nodedef.cpp b/src/nodedef.cpp index 4e43369b4..2e0c6fad6 100644 --- a/src/nodedef.cpp +++ b/src/nodedef.cpp @@ -140,6 +140,8 @@ void ContentFeatures::reset() air_equivalent = false; often_contains_mineral = false; dug_item = ""; + extra_dug_item = ""; + extra_dug_item_rarity = 2; initial_metadata = NULL; liquid_type = LIQUID_NONE; liquid_alternative_flowing = CONTENT_IGNORE; @@ -149,6 +151,7 @@ void ContentFeatures::reset() damage_per_second = 0; selection_box = NodeBox(); material = MaterialProperties(); + cookresult_item = ""; } void ContentFeatures::serialize(std::ostream &os) @@ -198,6 +201,7 @@ void ContentFeatures::serialize(std::ostream &os) writeU32(os, damage_per_second); selection_box.serialize(os); material.serialize(os); + os<