From 87f502a2592bbd41e99df9009a966111156f0181 Mon Sep 17 00:00:00 2001 From: Zefram Date: Fri, 13 Jun 2014 15:04:20 +0100 Subject: 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. --- group.lua | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'group.lua') 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", -- cgit v1.2.3