{
if(nodename == "")
nodename = "unknown_block";
- m_nodename = nodename;
+
+ // Convert directly to the correct name through aliases
+ m_nodename = gamedef->ndef()->getAlias(nodename);
}
// Legacy constructor
MaterialItem::MaterialItem(IGameDef *gamedef, content_t content, u16 count):
ToolItem
*/
+ToolItem::ToolItem(IGameDef *gamedef, std::string toolname, u16 wear):
+ InventoryItem(gamedef, 1)
+{
+ // Convert directly to the correct name through aliases
+ m_toolname = gamedef->tdef()->getAlias(toolname);
+
+ m_wear = wear;
+}
+
std::string ToolItem::getImageBasename() const
{
return m_gamedef->getToolDefManager()->getImagename(m_toolname);
CraftItem::CraftItem(IGameDef *gamedef, std::string subname, u16 count):
InventoryItem(gamedef, count)
{
- // Convert directly to the correct name through aliases.
- // This is necessary because CraftItem callbacks are stored in
- // Lua refenced by their correct name
+ // Convert directly to the correct name through aliases
m_subname = gamedef->cidef()->getAlias(subname);
}
class ToolItem : public InventoryItem
{
public:
- ToolItem(IGameDef *gamedef, std::string toolname, u16 wear):
- InventoryItem(gamedef, 1)
- {
- m_toolname = toolname;
- m_wear = wear;
- }
+ ToolItem(IGameDef *gamedef, std::string toolname, u16 wear);
/*
Implementation interface
*/
}
virtual bool getId(const std::string &name_, content_t &result) const
{
- std::string name = name_;
// Convert name according to possible alias
- std::map<std::string, std::string>::const_iterator i;
- i = m_aliases.find(name);
- if(i != m_aliases.end()){
- /*infostream<<"ndef: alias active: "<<name<<" -> "<<i->second
- <<std::endl;*/
- name = i->second;
- }
+ std::string name = getAlias(name_);
// Get id
return m_name_id_mapping.getId(name, result);
}
getId(name, id);
return get(id);
}
+ virtual std::string getAlias(const std::string &name) const
+ {
+ std::map<std::string, std::string>::const_iterator i;
+ i = m_aliases.find(name);
+ if(i != m_aliases.end())
+ return i->second;
+ return name;
+ }
// IWritableNodeDefManager
virtual void set(content_t c, const ContentFeatures &def)
{
virtual bool getId(const std::string &name, content_t &result) const=0;
virtual content_t getId(const std::string &name) const=0;
virtual const ContentFeatures& get(const std::string &name) const=0;
+ virtual std::string getAlias(const std::string &name) const =0;
virtual void serialize(std::ostream &os)=0;
};
virtual content_t getId(const std::string &name) const=0;
// If not found, returns the features of CONTENT_IGNORE
virtual const ContentFeatures& get(const std::string &name) const=0;
+ virtual std::string getAlias(const std::string &name) const =0;
// Register node definition
virtual void set(content_t c, const ContentFeatures &def)=0;
virtual const ToolDefinition* getToolDefinition(const std::string &toolname_) const
{
// Convert name according to possible alias
- std::string toolname = toolname_;
- std::map<std::string, std::string>::const_iterator i;
- i = m_aliases.find(toolname);
- if(i != m_aliases.end()){
- toolname = i->second;
- }
+ std::string toolname = getAlias(toolname_);
// Get the definition
core::map<std::string, ToolDefinition*>::Node *n;
n = m_tool_definitions.find(toolname);
}
return def->properties;
}
+ virtual std::string getAlias(const std::string &name) const
+ {
+ std::map<std::string, std::string>::const_iterator i;
+ i = m_aliases.find(name);
+ if(i != m_aliases.end())
+ return i->second;
+ return name;
+ }
+ // IWritableToolDefManager
virtual bool registerTool(std::string toolname, const ToolDefinition &def)
{
infostream<<"registerTool: registering tool \""<<toolname<<"\""<<std::endl;
virtual std::string getImagename(const std::string &toolname) const =0;
virtual ToolDiggingProperties getDiggingProperties(
const std::string &toolname) const =0;
+ virtual std::string getAlias(const std::string &name) const =0;
virtual void serialize(std::ostream &os)=0;
};
virtual std::string getImagename(const std::string &toolname) const =0;
virtual ToolDiggingProperties getDiggingProperties(
const std::string &toolname) const =0;
+ virtual std::string getAlias(const std::string &name) const =0;
virtual bool registerTool(std::string toolname, const ToolDefinition &def)=0;
virtual void clear()=0;