diff options
author | Perttu Ahola <celeron55@gmail.com> | 2011-11-16 14:36:33 +0200 |
---|---|---|
committer | Perttu Ahola <celeron55@gmail.com> | 2011-11-29 19:13:47 +0200 |
commit | 7a29b14a20b16b97fd0d97d9f305fe0d53c160bf (patch) | |
tree | 95076f5b5c1718b03584225ee67e4d0630c27a99 /src/inventory.cpp | |
parent | df8346ef4d70ba7c717c4c7b9c783df876378ca8 (diff) | |
download | minetest-7a29b14a20b16b97fd0d97d9f305fe0d53c160bf.tar.gz minetest-7a29b14a20b16b97fd0d97d9f305fe0d53c160bf.tar.bz2 minetest-7a29b14a20b16b97fd0d97d9f305fe0d53c160bf.zip |
Improved MaterialItem (stores nodename)
Diffstat (limited to 'src/inventory.cpp')
-rw-r--r-- | src/inventory.cpp | 47 |
1 files changed, 42 insertions, 5 deletions
diff --git a/src/inventory.cpp b/src/inventory.cpp index 98bf57738..b0b128418 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -32,6 +32,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "nodedef.h" #include "tooldef.h" #include "gamedef.h" +#include "strfnd.h" /* InventoryItem @@ -95,6 +96,16 @@ InventoryItem* InventoryItem::deSerialize(std::istream &is, IGameDef *gamedef) throw SerializationError("Too large material number"); return new MaterialItem(gamedef, material, count); } + else if(name == "MaterialItem3") + { + std::string all; + std::getline(is, all, '\n'); + Strfnd fnd(all); + fnd.next("\""); + std::string nodename = fnd.next("\""); + u16 count = stoi(trim(fnd.next(""))); + return new MaterialItem(gamedef, nodename, count); + } else if(name == "MBOItem") { std::string inventorystring; @@ -149,24 +160,42 @@ ServerActiveObject* InventoryItem::createSAO(ServerEnvironment *env, u16 id, v3f MaterialItem */ +MaterialItem::MaterialItem(IGameDef *gamedef, std::string nodename, u16 count): + InventoryItem(gamedef, count) +{ + if(nodename == "") + nodename = "unknown_block"; + m_nodename = nodename; +} +// Legacy constructor +MaterialItem::MaterialItem(IGameDef *gamedef, content_t content, u16 count): + InventoryItem(gamedef, count) +{ + INodeDefManager *ndef = m_gamedef->ndef(); + std::string nodename = ndef->get(content).name; + if(nodename == "") + nodename = "unknown_block"; + m_nodename = nodename; +} + #ifndef SERVER video::ITexture * MaterialItem::getImage(ITextureSource *tsrc) const { - return m_gamedef->getNodeDefManager()->get(m_content).inventory_texture; + return m_gamedef->getNodeDefManager()->get(m_nodename).inventory_texture; } #endif bool MaterialItem::isCookable() const { INodeDefManager *ndef = m_gamedef->ndef(); - const ContentFeatures &f = ndef->get(m_content); + const ContentFeatures &f = ndef->get(m_nodename); return (f.cookresult_item != ""); } InventoryItem *MaterialItem::createCookResult() const { INodeDefManager *ndef = m_gamedef->ndef(); - const ContentFeatures &f = ndef->get(m_content); + const ContentFeatures &f = ndef->get(m_nodename); std::istringstream is(f.cookresult_item, std::ios::binary); return InventoryItem::deSerialize(is, m_gamedef); } @@ -174,17 +203,25 @@ InventoryItem *MaterialItem::createCookResult() const float MaterialItem::getCookTime() const { INodeDefManager *ndef = m_gamedef->ndef(); - const ContentFeatures &f = ndef->get(m_content); + const ContentFeatures &f = ndef->get(m_nodename); return f.furnace_cooktime; } float MaterialItem::getBurnTime() const { INodeDefManager *ndef = m_gamedef->ndef(); - const ContentFeatures &f = ndef->get(m_content); + const ContentFeatures &f = ndef->get(m_nodename); return f.furnace_burntime; } +content_t MaterialItem::getMaterial() const +{ + INodeDefManager *ndef = m_gamedef->ndef(); + content_t id = CONTENT_IGNORE; + ndef->getId(m_nodename, id); + return id; +} + /* ToolItem */ |