]> git.lizzy.rs Git - xdecor.git/blobdiff - xwall.lua
Better pattern
[xdecor.git] / xwall.lua
index 67c795498d5c4f2e34fceb2d24e55df138bf1131..89ab209ac948729a208b974e53f6862389fad696 100644 (file)
--- a/xwall.lua
+++ b/xwall.lua
@@ -3,6 +3,7 @@
 -- Optimized by kilbith
 
 local xwall = {}
+screwdriver = screwdriver or {}
 
 xwall.get_candidate = {}
 local profiles = {
@@ -23,20 +24,6 @@ local directions = {
        {x = -1, y = 0, z = 0}, {x = 0, y = 0, z = -1}
 }
 
--- Source: Mesecons (util.lua).
--- Creates a deep copy of the table.
-local function clone_table(table) 
-       if type(table) ~= "table" then return table end -- No need to copy.
-       local newtable = {}
-
-       for idx, item in pairs(table) do
-               if type(item) == "table" then newtable[idx] = clone_table(item)
-               else newtable[idx] = item end
-       end
-
-       return newtable
-end
-
 function xwall.update_one_node(pos, name, digged)
        if not pos or not name or not minetest.registered_nodes[name] then return end
        local candidates = {0, 0, 0, 0}
@@ -53,10 +40,6 @@ function xwall.update_one_node(pos, name, digged)
                                candidates[i] = node.name
                                id = id + pow2[i]
                        end
-                       if ndef.walkable ~= false and ndef.drawtype ~= "nodebox" then
-                               candidates[i] = 0
-                               id = id + pow2[i]
-                       end
                end
        end
 
@@ -73,6 +56,7 @@ function xwall.update_one_node(pos, name, digged)
                        minetest.swap_node(pos, {name=name, param2=0})
                end
        end
+
        return candidates
 end
 
@@ -96,23 +80,18 @@ function xwall.register(name, def, node_box_data)
                def.drop = name.."_ln"
                def.node_box = {type = "fixed", fixed = node_box_data[k]}
 
-               if not def.tiles then
-                       def.tiles = def.textures
-               end
+               if not def.tiles then def.tiles = def.textures end
                if not def.groups then
                        def.groups = {xwall=1, cracky=3}
-               else
-                       def.groups.xwall = 1
-               end
+               else def.groups.xwall = 1 end
 
-               local newdef = clone_table(def)
+               local newdef = table.copy(def)
                if k == "ln" then
                        newdef.on_construct = function(pos)
                                return xwall.update(pos, name.."_ln", true, nil)
                        end
-               else
-                       newdef.groups.not_in_creative_inventory = 1
-               end
+               else newdef.groups.not_in_creative_inventory = 1 end
+
                newdef.after_dig_node = function(pos, _, _, _)
                        return xwall.update(pos, name.."_ln", true, true)
                end
@@ -124,56 +103,35 @@ end
 function xwall.construct_node_box_data(node_box_list, center_node_box_list, node_box_line)
        local res = {}
        res.c0, res.c1, res.c2, res.c3, res.c4 = {}, {}, {}, {}, {}
-       local pos0, pos1, pos2, pos3, pos4 = #res.c0, #res.c1, #res.c2, #res.c3, #res.c4
-
-       for i = 1, #node_box_list do
-               local v = node_box_list[i]
-               pos1 = pos1 + 1
-               pos2 = pos2 + 1
-               pos3 = pos3 + 1
-               pos4 = pos4 + 1
-               res.c1[pos1] = v
-               res.c2[pos2] = v
-               res.c3[pos3] = v
-               res.c4[pos4] = v
+
+       for _, v in pairs(node_box_list) do
+               res.c1[#res.c1+1] = v
+               res.c2[#res.c2+1] = v
+               res.c3[#res.c3+1] = v
+               res.c4[#res.c4+1] = v
        end
 
-       for i = 1, #node_box_list do
-               local v = node_box_list[i]
-               pos2 = pos2 + 1
-               pos3 = pos3 + 1
-               pos4 = pos4 + 1
-               res.c2[pos2] = {v[3], v[2], v[1], v[6], v[5], v[4]}
-               res.c3[pos3] = {v[3], v[2], v[1], v[6], v[5], v[4]}
-               res.c4[pos4] = {v[3], v[2], v[1], v[6], v[5], v[4]}
+       for _, v in pairs(node_box_list) do
+               res.c2[#res.c2+1] = {v[3], v[2], v[1], v[6], v[5], v[4]}
+               res.c3[#res.c3+1] = {v[3], v[2], v[1], v[6], v[5], v[4]}
+               res.c4[#res.c4+1] = {v[3], v[2], v[1], v[6], v[5], v[4]}
        end
 
-       for i = 1, #node_box_list do
-               local v = node_box_list[i]
-               pos3 = pos3 + 1
-               pos4 = pos4 + 1
-               res.c3[pos3] = {v[4], v[2], v[3]-.5, v[1], v[5], v[6]-.5}
-               res.c4[pos4] = {v[4], v[2], v[3]-.5, v[1], v[5], v[6]-.5}
+       for _, v in pairs(node_box_list) do
+               res.c3[#res.c3+1] = {v[4], v[2], v[3]-0.5,  v[1], v[5], v[6]-0.5}
+               res.c4[#res.c4+1] = {v[4], v[2], v[3]-0.5,  v[1], v[5], v[6]-0.5}
        end
 
-       for i = 1, #node_box_list do
-               local v = node_box_list[i]
-               pos4 = pos4 + 1
-               res.c4[pos4] = {v[3]-.5, v[2], v[4], v[6]-.5, v[5], v[1]}
+       for _, v in pairs(node_box_list) do
+               res.c4[#res.c4+1] = {v[3]-0.5, v[2], v[4], v[6]-0.5, v[5], v[1]}
        end
 
-       for i = 1, #center_node_box_list do
-               local v = center_node_box_list[i]
-               pos0 = pos0 + 1
-               pos1 = pos1 + 1
-               pos2 = pos2 + 1
-               pos3 = pos3 + 1
-               pos4 = pos4 + 1
-               res.c0[pos0] = v
-               res.c1[pos1] = v
-               res.c2[pos2] = v
-               res.c3[pos3] = v
-               res.c4[pos4] = v
+       for _, v in pairs(center_node_box_list) do
+               res.c0[#res.c0+1] = v
+               res.c1[#res.c1+1] = v
+               res.c2[#res.c2+1] = v
+               res.c3[#res.c3+1] = v
+               res.c4[#res.c4+1] = v
        end     
 
        if #res.c0 < 1 then res.c0 = nil end
@@ -184,17 +142,18 @@ end
 
 function xwall.register_wall(name, tiles, def)
        local node_box_data = xwall.construct_node_box_data(
-               {{-.1875,-.5,0,.1875,.3125,.5}},{{-.25,-.5,-.25,.25,.5,.25}},
-               {{-.1875,-.5,-.5,.1875,.3125,.5}}
+               {{-.1875,-.6875,0,.1875,.3125,.5}},{{-.25,-.6875,-.25,.25,.5,.25}},
+               {{-.1875,-.6875,-.5,.1875,.3125,.5}}
        )
 
        if def then return end
        def = { 
                description = string.sub(name:gsub("%l", string.upper, 7), 8, -6).." Wall",
                textures = {tiles, tiles, tiles, tiles},
-               sounds = xdecor.stone,
+               sounds = default.node_sound_stone_defaults(),
                groups = {cracky=3, stone=1, pane=1},
                sunlight_propagates = true,
+               on_rotate = screwdriver.disallow,
                collision_box = {
                        type = "fixed",
                        fixed = {-.5, -.5, -.25, .5, 1, .25}