Groups in crafting recipes
---------------------------
-- Not implemented yet. (TODO)
-- Will probably look like this:
+An example:
{
output = 'food:meat_soup_raw',
recipe = {
{'group:water'},
{'group:bowl'},
},
- preserve = {'group:bowl'},
+ preserve = {'group:bowl'}, -- Not implemented yet (TODO)
}
Special groups
^ default: minetest.node_metadata_inventory_take_allow_all
}
-Recipe: (register_craft)
+Recipe for register_craft: (shaped)
{
output = 'default:pick_stone',
recipe = {
{'default:cobble', 'default:cobble', 'default:cobble'},
{'', 'default:stick', ''},
- {'', 'default:stick', ''},
+ {'', 'default:stick', ''}, -- Also groups; eg. 'group:crumbly'
},
replacements = <optional list of item pairs,
replace one input item with another item on crafting>
}
-Recipe (shapeless):
+Recipe for register_craft (shapeless)
{
type = "shapeless",
output = 'mushrooms:mushroom_stew',
replace one input item with another item on crafting>
}
-Recipe (tool repair):
+Recipe for register_craft (tool repair)
{
type = "toolrepair",
additional_wear = -0.02,
}
-Recipe (cooking):
+Recipe for register_craft (cooking)
{
type = "cooking",
output = "default:glass",
cooktime = 3,
}
-Recipe (furnace fuel):
+Recipe for register_craft (furnace fuel)
{
type = "fuel",
recipe = "default:leaves",
#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)
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;
}