]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/craftdef.cpp
Added method to get all registered recipes for item(node)
[dragonfireclient.git] / src / craftdef.cpp
index b15443607e81e949c1f112f1f2246a84e8386d68..c79408f9986b177aa0933f7aa777e6ef38aea78f 100644 (file)
@@ -1,6 +1,6 @@
 /*
-Minetest-c55
-Copyright (C) 2011 celeron55, Perttu Ahola <celeron55@gmail.com>
+Minetest
+Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
 
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU Lesser General Public License as published by
@@ -987,6 +987,43 @@ class CCraftDefManager: public IWritableCraftDefManager
                }
                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);