aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/craftitemdef.cpp15
-rw-r--r--src/craftitemdef.h1
-rw-r--r--src/inventory.cpp9
-rw-r--r--src/inventory.h6
4 files changed, 20 insertions, 11 deletions
diff --git a/src/craftitemdef.cpp b/src/craftitemdef.cpp
index 8d4cbea3c..4461e38a7 100644
--- a/src/craftitemdef.cpp
+++ b/src/craftitemdef.cpp
@@ -88,12 +88,7 @@ public:
virtual const CraftItemDefinition* getCraftItemDefinition(const std::string &itemname_) const
{
// Convert name according to possible alias
- std::string itemname = itemname_;
- std::map<std::string, std::string>::const_iterator i;
- i = m_aliases.find(itemname);
- if(i != m_aliases.end()){
- itemname = i->second;
- }
+ std::string itemname = getAlias(itemname_);
// Get the definition
core::map<std::string, CraftItemDefinition*>::Node *n;
n = m_item_definitions.find(itemname);
@@ -108,6 +103,14 @@ public:
return "";
return def->imagename;
}
+ 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;
+ }
virtual bool registerCraftItem(std::string itemname, const CraftItemDefinition &def)
{
infostream<<"registerCraftItem: registering CraftItem \""<<itemname<<"\""<<std::endl;
diff --git a/src/craftitemdef.h b/src/craftitemdef.h
index ee3d97aec..b5d4b9348 100644
--- a/src/craftitemdef.h
+++ b/src/craftitemdef.h
@@ -49,6 +49,7 @@ public:
virtual ~ICraftItemDefManager(){}
virtual const CraftItemDefinition* getCraftItemDefinition(const std::string &itemname) const=0;
virtual std::string getImagename(const std::string &itemname) const =0;
+ virtual std::string getAlias(const std::string &name) const =0;
virtual void serialize(std::ostream &os)=0;
};
diff --git a/src/inventory.cpp b/src/inventory.cpp
index a913430e6..e9600ece5 100644
--- a/src/inventory.cpp
+++ b/src/inventory.cpp
@@ -354,6 +354,15 @@ bool ToolItem::isKnown() const
CraftItem
*/
+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
+ m_subname = gamedef->cidef()->getAlias(subname);
+}
+
#ifndef SERVER
video::ITexture * CraftItem::getImage() const
{
diff --git a/src/inventory.h b/src/inventory.h
index 3f3c5435b..57af37650 100644
--- a/src/inventory.h
+++ b/src/inventory.h
@@ -238,11 +238,7 @@ private:
class CraftItem : public InventoryItem
{
public:
- CraftItem(IGameDef *gamedef, std::string subname, u16 count):
- InventoryItem(gamedef, count)
- {
- m_subname = subname;
- }
+ CraftItem(IGameDef *gamedef, std::string subname, u16 count);
/*
Implementation interface
*/