summaryrefslogtreecommitdiff
path: root/src/craftdef.cpp
diff options
context:
space:
mode:
authorPerttu Ahola <celeron55@gmail.com>2012-06-06 23:39:17 +0300
committerPerttu Ahola <celeron55@gmail.com>2012-06-06 23:39:17 +0300
commita435cfcd82ccb138cbb05facdf3408335c638720 (patch)
treed376fd8316f45fc93bbeb86f4cd4a2f38efa2815 /src/craftdef.cpp
parent7631918a12068124fafbe7d78bb60b563a1824dd (diff)
downloadminetest-a435cfcd82ccb138cbb05facdf3408335c638720.tar.gz
minetest-a435cfcd82ccb138cbb05facdf3408335c638720.tar.bz2
minetest-a435cfcd82ccb138cbb05facdf3408335c638720.zip
Allow groups in crafting recipes
Diffstat (limited to 'src/craftdef.cpp')
-rw-r--r--src/craftdef.cpp26
1 files changed, 23 insertions, 3 deletions
diff --git a/src/craftdef.cpp b/src/craftdef.cpp
index 57a1851af..37fa63a00 100644
--- a/src/craftdef.cpp
+++ b/src/craftdef.cpp
@@ -27,6 +27,26 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "gamedef.h"
#include "inventory.h"
+// Check if input matches recipe
+// Takes recipe groups into account
+static bool inputItemMatchesRecipe(const std::string &inp_name,
+ const std::string &rec_name, IItemDefManager *idef)
+{
+ // Exact name
+ if(inp_name == rec_name)
+ return true;
+
+ // Group
+ if(rec_name.substr(0,6) == "group:" && idef->isKnown(inp_name)){
+ std::string rec_group = rec_name.substr(6);
+ const struct ItemDefinition &def = idef->get(inp_name);
+ if(itemgroup_get(def.groups, rec_group) != 0)
+ return true;
+ }
+
+ // Didn't match
+ return false;
+}
// Deserialize an itemstring then return the name of the item
static std::string craftGetItemName(const std::string &itemstring, IGameDef *gamedef)
@@ -403,9 +423,9 @@ bool CraftDefinitionShaped::check(const CraftInput &input, IGameDef *gamedef) co
unsigned int rec_x = rec_min_x + x;
unsigned int rec_y = rec_min_y + y;
- if(
- inp_names[inp_y * inp_width + inp_x] !=
- rec_names[rec_y * rec_width + rec_x]
+ if(!inputItemMatchesRecipe(
+ inp_names[inp_y * inp_width + inp_x],
+ rec_names[rec_y * rec_width + rec_x], gamedef->idef())
){
return false;
}