diff options
author | Zefram <zefram@fysh.org> | 2014-06-13 15:04:20 +0100 |
---|---|---|
committer | Diego Martinez <kaeza@users.sf.net> | 2014-06-13 11:30:09 -0300 |
commit | 87f502a2592bbd41e99df9009a966111156f0181 (patch) | |
tree | a142488895cf47cc39aa072697f701cbde3cb34c /api.lua | |
parent | c33efe86316342c491267c5f5d8b8fa2cdc58747 (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 'api.lua')
-rw-r--r-- | api.lua | 25 |
1 files changed, 22 insertions, 3 deletions
@@ -42,6 +42,25 @@ minetest.after(0.01, function() end end end + for _, recipes in pairs(unified_inventory.crafts_for.recipe) do + for _, recipe in ipairs(recipes) do + local ingredient_items = {} + for _, spec in ipairs(recipe.items) do + local matches_spec = unified_inventory.canonical_item_spec_matcher(spec) + for _, name in ipairs(unified_inventory.items_list) do + if matches_spec(name) then + ingredient_items[name] = true + end + end + end + for name, _ in pairs(ingredient_items) do + if unified_inventory.crafts_for.usage[name] == nil then + unified_inventory.crafts_for.usage[name] = {} + end + table.insert(unified_inventory.crafts_for.usage[name], recipe) + end + end + end end) @@ -101,10 +120,10 @@ function unified_inventory.register_craft(options) if options.type == "normal" and options.width == 0 then options = { type = "shapeless", items = options.items, output = options.output, width = 0 } end - if unified_inventory.crafts_table[itemstack:get_name()] == nil then - unified_inventory.crafts_table[itemstack:get_name()] = {} + if unified_inventory.crafts_for.recipe[itemstack:get_name()] == nil then + unified_inventory.crafts_for.recipe[itemstack:get_name()] = {} end - table.insert(unified_inventory.crafts_table[itemstack:get_name()],options) + table.insert(unified_inventory.crafts_for.recipe[itemstack:get_name()],options) end |