From cb70c37765118897426e16669c9805d4d1e48882 Mon Sep 17 00:00:00 2001 From: Jean-Patrick Guerrero Date: Tue, 8 Mar 2016 16:50:15 +0100 Subject: [PATCH] Cobblewalls : cleaning up --- xwall.lua | 70 ++++++++++++++++++++++--------------------------------- 1 file changed, 28 insertions(+), 42 deletions(-) diff --git a/xwall.lua b/xwall.lua index f150b2f..01d6d08 100644 --- a/xwall.lua +++ b/xwall.lua @@ -5,7 +5,6 @@ local xwall = {} screwdriver = screwdriver or {} -xwall.get_candidate = {} local profiles = { {0, "_c0", 0}, {1, "_c1", 1}, {2, "_c1", 0}, {4, "_c1", 3}, {8, "_c1", 2}, {5, "_ln", 1}, {10, "_ln", 0}, {3, "_c2", 0}, @@ -13,13 +12,13 @@ local profiles = { {11, "_c3", 0}, {13, "_c3", 1}, {14, "_c3", 2}, {15, "_c4", 1} } +xwall.get_candidate = {} for _, p in pairs(profiles) do xwall.get_candidate[p[1]] = {p[2], p[3]} end -local directions = { - {x=1, y=0, z=0}, {x=0, y=0, z=1}, - {x=-1, y=0, z=0}, {x=0, y=0, z=-1} +local dirs = { + {x=1, y=0, z=0}, {x=0, y=0, z=1}, {x=-1, y=0, z=0}, {x=0, y=0, z=-1} } function xwall.update_one_node(pos, name, digged) @@ -28,7 +27,7 @@ function xwall.update_one_node(pos, name, digged) local pow2 = {1, 2, 4, 8} local id = 0 - for i, dir in pairs(directions) do + for i, dir in pairs(dirs) do local node = minetest.get_node(vector.add(pos, dir)) local ndef = minetest.registered_nodes[node.name] @@ -57,11 +56,11 @@ function xwall.update_one_node(pos, name, digged) return candidates end -function xwall.update(pos, name, active, has_been_digged) +function xwall.update(pos, name, active, digged) if not pos or not name or not minetest.registered_nodes[name] then return end - local c = xwall.update_one_node(pos, name, has_been_digged) - for j, dir2 in pairs(directions) do + local c = xwall.update_one_node(pos, name, digged) + for j, dir2 in pairs(dirs) do if c[j] ~= 0 and c[j] ~= "ignore" then xwall.update_one_node(vector.add(pos, dir2), c[j], false) end @@ -72,12 +71,10 @@ function xwall.construct_nodebox(nodebox_list, center_nodebox_list, nodebox_line local res = {} res.c0, res.c1, res.c2, res.c3, res.c4 = {}, {}, {}, {}, {} - for _, v in pairs(nodebox_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 + res.c1[#res.c1+1] = unpack(nodebox_list) + res.c2[#res.c2+1] = unpack(nodebox_list) + res.c3[#res.c3+1] = unpack(nodebox_list) + res.c4[#res.c4+1] = unpack(nodebox_list) for _, v in pairs(nodebox_list) do res.c2[#res.c2+1] = {v[3], v[2], v[1], v[6], v[5], v[4]} @@ -94,40 +91,29 @@ function xwall.construct_nodebox(nodebox_list, center_nodebox_list, nodebox_line res.c4[#res.c4+1] = {v[3]-0.5, v[2], v[4], v[6]-0.5, v[5], v[1]} end - for _, v in pairs(center_nodebox_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 + res.c0[#res.c0+1] = unpack(center_nodebox_list) + res.c1[#res.c1+1] = unpack(center_nodebox_list) + res.c2[#res.c2+1] = unpack(center_nodebox_list) + res.c3[#res.c3+1] = unpack(center_nodebox_list) + res.c4[#res.c4+1] = unpack(center_nodebox_list) + if #res.c0 < 1 then res.c0 = nil end res.ln = nodebox_line return res end +local nodebox_data = xwall.construct_nodebox( + {{-.1875,-.6875,0,.1875,.3125,.5}}, + {{-.25,-.6875,-.25,.25,.5,.25}}, + {{-.1875,-.6875,-.5,.1875,.3125,.5}} +) + function xwall.register_wall(name, tiles) - local groups, def = {}, {} - local nodebox_data = xwall.construct_nodebox( - {{-.1875,-.6875,0,.1875,.3125,.5}}, - {{-.25,-.6875,-.25,.25,.5,.25}}, - {{-.1875,-.6875,-.5,.1875,.3125,.5}} - ) - - local function group(k) - groups = {xwall=1, cracky=3} - if k ~= "ln" then - groups.not_in_creative_inventory=1 - end - return groups - end - for k, v in pairs(nodebox_data) do - def = { + local groups = {xwall=1, cracky=3} + if k ~= "ln" then groups.not_in_creative_inventory = 1 end + + local def = { description = name:gsub("^%l", string.upper).." Wall", drawtype = "nodebox", paramtype = "light", @@ -136,7 +122,7 @@ function xwall.register_wall(name, tiles) drop = "xdecor:"..name.."_wall_ln", node_box = {type = "fixed", fixed = nodebox_data[k]}, sounds = default.node_sound_stone_defaults(), - groups = group(k), + groups = groups, sunlight_propagates = true, on_rotate = screwdriver.disallow, collision_box = {