summaryrefslogtreecommitdiff
path: root/group.lua
diff options
context:
space:
mode:
authorZefram <zefram@fysh.org>2014-06-13 15:04:20 +0100
committerDiego Martinez <kaeza@users.sf.net>2014-06-13 11:30:09 -0300
commit87f502a2592bbd41e99df9009a966111156f0181 (patch)
treea142488895cf47cc39aa072697f701cbde3cb34c /group.lua
parentc33efe86316342c491267c5f5d8b8fa2cdc58747 (diff)
Show item usages in craft guide
When the craft guide is showing a craft, the output slot is now a button, which causes the craft guide to show ways in which that output can be used. This mirrors the way input slots are buttons that show recipes for the selected ingredient. Usages of an item can be iterated through in the same way as recipes for the item. This incidentally offers some ability to retrace one's steps through a crafting chain, without storing actual history.
Diffstat (limited to 'group.lua')
-rw-r--r--group.lua22
1 files changed, 22 insertions, 0 deletions
diff --git a/group.lua b/group.lua
index e509006..9bf6895 100644
--- a/group.lua
+++ b/group.lua
@@ -1,3 +1,25 @@
+function unified_inventory.canonical_item_spec_matcher(spec)
+ local specname = ItemStack(spec):get_name()
+ if specname:sub(1, 6) == "group:" then
+ local group_names = specname:sub(7):split(",")
+ return function (itemname)
+ local itemdef = minetest.registered_items[itemname]
+ for _, group_name in ipairs(group_names) do
+ if (itemdef.groups[group_name] or 0) == 0 then
+ return false
+ end
+ end
+ return true
+ end
+ else
+ return function (itemname) return itemname == specname end
+ end
+end
+
+function unified_inventory.item_matches_spec(item, spec)
+ local itemname = ItemStack(item):get_name()
+ return unified_inventory.canonical_item_spec_matcher(spec)(itemname)
+end
unified_inventory.registered_group_items = {
mesecon_conductor_craftable = "mesecons:wire_00000000_off",