X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Fcraftdef.cpp;h=9cd1d8c7ef12f2823c1e6622ce1bf787638c260d;hb=58e6d25e033c76dc91aaac18fdeda92ac23fe0e1;hp=99e3fcc3d93c2d22581962e471c13e673e0b067d;hpb=6d0ea26c2d62c3774ff384cf1bfc2a3372b49a3b;p=oweals%2Fminetest.git diff --git a/src/craftdef.cpp b/src/craftdef.cpp index 99e3fcc3d..9cd1d8c7e 100644 --- a/src/craftdef.cpp +++ b/src/craftdef.cpp @@ -28,6 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "inventory.h" #include "util/serialize.h" #include "strfnd.h" +#include "exceptions.h" // Check if input matches recipe // Takes recipe groups into account @@ -150,23 +151,6 @@ static bool craftGetBounds(const std::vector &items, unsigned int w return success; } -#if 0 -// This became useless when group support was added to shapeless recipes -// Convert a list of item names to a multiset -static std::multiset craftMakeMultiset(const std::vector &names) -{ - std::multiset set; - for(std::vector::const_iterator - i = names.begin(); - i != names.end(); i++) - { - if(*i != "") - set.insert(*i); - } - return set; -} -#endif - // Removes 1 from each item stack static void craftDecrementInput(CraftInput &input, IGameDef *gamedef) { @@ -541,7 +525,7 @@ bool CraftDefinitionShapeless::check(const CraftInput &input, IGameDef *gamedef) } // Try with all permutations of the recipe - std::vector recipe_copy = recipe; + std::vector recipe_copy = craftGetItemNames(recipe, gamedef); // Start from the lexicographically first permutation (=sorted) std::sort(recipe_copy.begin(), recipe_copy.end()); //while(std::prev_permutation(recipe_copy.begin(), recipe_copy.end())){} @@ -987,6 +971,43 @@ public: } return false; } + virtual std::vector getCraftRecipes(CraftOutput &output, + IGameDef *gamedef) const + { + std::vector recipes_list; + CraftInput input; + CraftOutput tmpout; + tmpout.item = ""; + tmpout.time = 0; + + for(std::vector::const_reverse_iterator + i = m_craft_definitions.rbegin(); + i != m_craft_definitions.rend(); i++) + { + CraftDefinition *def = *i; + + /*infostream<<"Checking "<dump()<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 " + <dump()<