1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Added method to get all registered recipes for item(node)

This commit is contained in:
RealBadAngel 2013-03-04 01:55:16 +01:00 committed by kwolekr
parent ba78194636
commit 5af8acfa6e
4 changed files with 120 additions and 0 deletions

View file

@ -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);