summaryrefslogtreecommitdiff
path: root/src/craftdef.cpp
diff options
context:
space:
mode:
authorRealBadAngel <mk@realbadangel.pl>2013-03-04 01:55:16 +0100
committerkwolekr <kwolekr@minetest.net>2013-03-05 23:32:33 -0500
commit5af8acfa6e41e258dd7e2135e8e75f03096c1d5c (patch)
treeab819388ec6be2e9ae683aeed223257b966e36f7 /src/craftdef.cpp
parentba78194636a9a498f6979cc21cd39399f23d658a (diff)
downloadminetest-5af8acfa6e41e258dd7e2135e8e75f03096c1d5c.tar.gz
minetest-5af8acfa6e41e258dd7e2135e8e75f03096c1d5c.tar.bz2
minetest-5af8acfa6e41e258dd7e2135e8e75f03096c1d5c.zip
Added method to get all registered recipes for item(node)
Diffstat (limited to 'src/craftdef.cpp')
-rw-r--r--src/craftdef.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/craftdef.cpp b/src/craftdef.cpp
index 99e3fcc3d..c79408f99 100644
--- a/src/craftdef.cpp
+++ b/src/craftdef.cpp
@@ -987,6 +987,43 @@ public:
}
return false;
}
+ virtual std::vector<CraftDefinition*> getCraftRecipes(CraftOutput &output,
+ IGameDef *gamedef) const
+ {
+ std::vector<CraftDefinition*> recipes_list;
+ CraftInput input;
+ CraftOutput tmpout;
+ tmpout.item = "";
+ tmpout.time = 0;
+
+ for(std::vector<CraftDefinition*>::const_reverse_iterator
+ i = m_craft_definitions.rbegin();
+ i != m_craft_definitions.rend(); i++)
+ {
+ CraftDefinition *def = *i;
+
+ /*infostream<<"Checking "<<input.dump()<<std::endl
+ <<" against "<<def->dump()<<std::endl;*/
+
+ try {
+ tmpout = def->getOutput(input, gamedef);
+ if(tmpout.item.substr(0,output.item.length()) == output.item)
+ {
+ // Get output, then decrement input (if requested)
+ input = def->getInput(output, gamedef);
+ recipes_list.push_back(*i);
+ }
+ }
+ catch(SerializationError &e)
+ {
+ errorstream<<"getCraftResult: ERROR: "
+ <<"Serialization error in recipe "
+ <<def->dump()<<std::endl;
+ // then go on with the next craft definition
+ }
+ }
+ return recipes_list;
+ }
virtual std::string dump() const
{
std::ostringstream os(std::ios::binary);