]> git.lizzy.rs Git - xdecor.git/blobdiff - src/workbench.lua
Stairs fix
[xdecor.git] / src / workbench.lua
index 0df3bf5d5d00e0546b5748ea11ef7098f76c49bb..e948c62500accfc6d3c3ef559cab098e651cb4bc 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
@@ -60,12 +44,9 @@ workbench.defs = {
                            { 0, 8,  8, 16, 8, 8  }},
        {"halfstair",   2,  { 0, 0,  0, 8,  8, 16 },
                            { 0, 8,  8, 8,  8, 8  }},
-       {"outerstair",  1,  { 0, 0,  0, 16, 8, 16 },
-                           { 0, 8,  8, 8,  8, 8  }},
+       {"stair_outer", 1,  nil                   },
        {"stair",       1,  nil                   },
-       {"innerstair",  1,  { 0, 0,  0, 16, 8, 16 },
-                           { 0, 8,  8, 16, 8, 8  },
-                           { 0, 8,  0, 8,  8, 8  }}
+       {"stair_inner", 1,  nil                   }
 }
 
 -- Tools allowed to be repaired
@@ -86,6 +67,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
 
@@ -150,9 +132,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)
@@ -215,7 +199,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", {})
@@ -256,9 +240,10 @@ xdecor.register("workbench", {
 for _, d in pairs(workbench.defs) do
 for i=1, #nodes do
        local node = nodes[i]
+       local mod_name, item_name = node:match("^(.-):(.*)")
        local def = registered_nodes[node]
 
-       if d[3] then
+       if item_name and d[3] then
                local groups = {}
                local tiles
                groups.not_in_creative_inventory = 1
@@ -279,8 +264,8 @@ for i=1, #nodes do
                        tiles = {def.tile_images[1]}
                end
 
-               if not registered_nodes["stairs:slab_"..node:match(":(.*)")] then
-                       stairs.register_stair_and_slab(node:match(":(.*)"), node,
+               if not registered_nodes["stairs:slab_"..item_name] then
+                       stairs.register_stair_and_slab(item_name, node,
                                groups, tiles, def.description.." Stair",
                                def.description.." Slab", def.sounds)
                end
@@ -298,6 +283,42 @@ for i=1, #nodes do
                        sunlight_propagates = true,
                        on_place = minetest.rotate_node
                })
+       elseif item_name and mod_name then
+               minetest.register_alias_force(
+                       ('%s:%s_innerstair'):format(mod_name, item_name),
+                       ('stairs:stair_inner_%s'):format(item_name)
+               )
+               minetest.register_alias_force(
+                       ('%s:%s_outerstair'):format(mod_name, item_name),
+                       ('stairs:stair_outer_%s'):format(item_name)
+               )
        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"}
+       }
+})