#include "nodedef.h"
#include "tooldef.h"
#include "gamedef.h"
+#include "strfnd.h"
/*
InventoryItem
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;
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);
}
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
*/
class MaterialItem : public InventoryItem
{
public:
- MaterialItem(IGameDef *gamedef, content_t content, u16 count):
- InventoryItem(gamedef, count)
- {
- m_content = content;
- }
+ MaterialItem(IGameDef *gamedef, std::string nodename, u16 count);
+ // Legacy constructor
+ MaterialItem(IGameDef *gamedef, content_t content, u16 count);
/*
Implementation interface
*/
}
virtual void serialize(std::ostream &os) const
{
- //os.imbue(std::locale("C"));
- os<<"MaterialItem2";
+ std::string nodename = m_nodename;
+ if(nodename == "")
+ nodename = "unknown_block";
+
+ os<<"MaterialItem3";
+ os<<" \"";
+ os<<nodename;
+ os<<"\" ";
+ os<<m_count;
+
+ // Old
+ /*os<<"MaterialItem2";
os<<" ";
os<<(unsigned int)m_content;
os<<" ";
- os<<m_count;
+ os<<m_count;*/
}
virtual InventoryItem* clone()
{
- return new MaterialItem(m_gamedef, m_content, m_count);
+ return new MaterialItem(m_gamedef, m_nodename, m_count);
}
#ifndef SERVER
video::ITexture * getImage(ITextureSource *tsrc) const;
if(std::string(other->getName()) != "MaterialItem")
return false;
MaterialItem *m = (MaterialItem*)other;
- if(m->getMaterial() != m_content)
+ if(m->m_nodename != m_nodename)
return false;
return true;
}
float getCookTime() const;
float getBurnTime() const;
/*
- Special methods
+ Special properties (not part of virtual interface)
*/
- content_t getMaterial()
- {
- return m_content;
- }
+ std::string getNodeName() const
+ { return m_nodename; }
+ content_t getMaterial() const;
private:
- content_t m_content;
+ std::string m_nodename;
};
/*
virtual const ContentFeatures& get(content_t c) const=0;
virtual const ContentFeatures& get(const MapNode &n) const=0;
virtual bool getId(const std::string &name, content_t &result) const=0;
+ virtual const ContentFeatures& get(const std::string &name) const=0;
virtual void serialize(std::ostream &os)=0;
};
virtual const ContentFeatures& get(content_t c) const=0;
virtual const ContentFeatures& get(const MapNode &n) const=0;
virtual bool getId(const std::string &name, content_t &result) const=0;
+ // If not found, returns the features of CONTENT_IGNORE
+ virtual const ContentFeatures& get(const std::string &name) const=0;
// Register node definition
virtual void set(content_t c, const ContentFeatures &def)=0;