]> git.lizzy.rs Git - xdecor.git/blobdiff - src/workbench.lua
Workbench: Fix special case of unknown items output (#90)
[xdecor.git] / src / workbench.lua
index 41c797d1eeb47e3e958a6400296307f86d96bcf6..ad69361fe27ba4058a932122545017888ee1687c 100644 (file)
@@ -8,23 +8,7 @@ local registered_nodes = minetest.registered_nodes
 -- Only the regular, solid blocks without metas or explosivity can be cut
 local nodes = {}
 for node, def in pairs(registered_nodes) do
-       if (def.drawtype == "normal" or def.drawtype:sub(1,5) == "glass") and
-          (def.groups.cracky or def.groups.choppy) and
-          not def.on_construct and
-          not def.after_place_node and
-          not def.on_rightclick and
-          not def.on_blast and
-          not def.allow_metadata_inventory_take and
-          not (def.groups.not_in_creative_inventory == 1) and
-          not (def.groups.not_cuttable == 1) and
-          not def.groups.wool and
-          (def.tiles and type(def.tiles[1]) == "string" and not
-               def.tiles[1]:find("default_mineral")) and
-          not def.mesecons and
-          def.description and
-          def.description ~= "" and
-          def.light_source == 0
-       then
+       if xdecor.stairs_valid_def(def) then
                nodes[#nodes+1] = node
        end
 end
@@ -86,6 +70,7 @@ function workbench:get_output(inv, input, name)
                item = nbox[3] and item or "stairs:"..nbox[1].."_"..name:match(":(.*)")
                output[#output+1] = item.." "..count
        end
+
        inv:set_list("forms", output)
 end
 
@@ -104,7 +89,15 @@ local formspecs = {
           list[context;input;2,1;1,1;]
           list[context;tool;2,2;1,1;]
           list[context;hammer;3,2;1,1;]
-          list[context;forms;4,0;4,3;] ]],
+          list[context;forms;4,0;4,3;]
+          listring[current_player;main]
+          listring[context;tool]
+          listring[current_player;main]
+          listring[context;hammer]
+          listring[current_player;main]
+          listring[context;forms]
+          listring[current_player;main]
+          listring[context;input] ]],
        -- Crafting formspec
        [[ image[5,1;1,1;gui_furnace_arrow_bg.png^[transformR270]
           button[0,0;1.5,1;back;< Back]
@@ -142,9 +135,11 @@ end
 function workbench.fields(pos, _, fields)
        if fields.quit then return end
        local meta = minetest.get_meta(pos)
-       workbench:set_formspec(meta, fields.back    and 1 or
-                                    fields.craft   and 2 or
-                                    fields.storage and 3)
+       local id = fields.back and 1 or
+                  fields.craft and 2 or
+                  fields.storage and 3
+       if not id then return end
+       workbench:set_formspec(meta, id)
 end
 
 function workbench.dig(pos)
@@ -207,7 +202,7 @@ function workbench.on_take(pos, listname, index, stack, player)
        local stackname = stack:get_name()
 
        if listname == "input" then
-               if stackname == inputname then
+               if stackname == inputname and registered_nodes[inputname.."_cube"] then
                        workbench:get_output(inv, input, stackname)
                else
                        inv:set_list("forms", {})
@@ -293,3 +288,30 @@ for i=1, #nodes do
        end
 end
 end
+
+-- Craft items
+
+minetest.register_tool("xdecor:hammer", {
+       description = "Hammer",
+       inventory_image = "xdecor_hammer.png",
+       wield_image = "xdecor_hammer.png",
+       on_use = function() do return end end
+})
+
+-- Recipes
+
+minetest.register_craft({
+       output = "xdecor:hammer",
+       recipe = {
+               {"default:steel_ingot", "group:stick", "default:steel_ingot"},
+               {"", "group:stick", ""}
+       }
+})
+
+minetest.register_craft({
+       output = "xdecor:workbench",
+       recipe = {
+               {"group:wood", "group:wood"},
+               {"group:wood", "group:wood"}
+       }
+})