diff options
author | Zefram <zefram@fysh.org> | 2014-04-30 00:11:10 +0100 |
---|---|---|
committer | Zefram <zefram@fysh.org> | 2014-04-30 00:11:10 +0100 |
commit | 580a832fdac823a4649f53edd0ba90fb6cd8bc5f (patch) | |
tree | 8cd864ad6dbfc75e049afff7e7aa4c6de83394a8 /api.lua | |
parent | 48d28b1e5d40c11769f189301af91eb9ebfbe6e5 (diff) |
Use appropriate grid shape for each craft type
New system of registration of craft types, recording for each a display
description and the appropriate grid shape. Recipes of a registered type
are shown in the correct grid. Recipes of unregistered craft types are
still displayed as before, using the default 3x3 grid.
Diffstat (limited to 'api.lua')
-rw-r--r-- | api.lua | 43 |
1 files changed, 43 insertions, 0 deletions
@@ -98,12 +98,55 @@ function unified_inventory.register_craft(options) if itemstack:is_empty() then return end + 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()] = {} end table.insert(unified_inventory.crafts_table[itemstack:get_name()],options) end +local craft_type_defaults = { + width = 3, + height = 3, + uses_crafting_grid = false, +} +function unified_inventory.canonicalise_craft_type(name, options) + if not options.description then options.description = name end + setmetatable(options, {__index = craft_type_defaults}) + return options +end +function unified_inventory.register_craft_type(name, options) + unified_inventory.registered_craft_types[name] = unified_inventory.canonicalise_craft_type(name, options) +end + +unified_inventory.register_craft_type("normal", { + description = "Crafting", + width = 3, + height = 3, + uses_crafting_grid = true, +}) + +unified_inventory.register_craft_type("shapeless", { + description = "Mixing", + width = 3, + height = 3, + uses_crafting_grid = true, +}) + +unified_inventory.register_craft_type("cooking", { + description = "Cooking", + width = 1, + height = 1, +}) + +unified_inventory.register_craft_type("digging", { + description = "Digging", + width = 1, + height = 1, +}) + function unified_inventory.register_page(name, def) unified_inventory.pages[name] = def end |