From 9d31ec93e6df7028ecfa6cc2d6a331ee7fd18733 Mon Sep 17 00:00:00 2001 From: jp Date: Wed, 5 Aug 2015 17:18:40 +0200 Subject: [PATCH] Tweak xwall code --- xwall.lua | 50 ++++++++++++++++++++++++-------------------------- 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/xwall.lua b/xwall.lua index c8a573b..6292a86 100644 --- a/xwall.lua +++ b/xwall.lua @@ -2,7 +2,9 @@ -- License : GPLv3 -- Optimized by kilbith -local xwall_get_candidate = {} +local xwall = {} + +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}, @@ -12,7 +14,7 @@ local profiles = { for _, p in pairs(profiles) do local p1, p2, p3 = p[1], p[2], p[3] - xwall_get_candidate[p1] = {p2, p3} + xwall.get_candidate[p1] = {p2, p3} end local directions = { @@ -20,10 +22,10 @@ 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 +-- 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 + if type(table) ~= "table" then return table end -- No need to copy. local newtable = {} for idx, item in pairs(table) do @@ -37,7 +39,7 @@ local function clone_table(table) return newtable end -local xwall_update_one_node = function(pos, name, digged) +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} local pow2 = {1, 2, 4, 8} @@ -62,7 +64,7 @@ local xwall_update_one_node = function(pos, name, digged) if digged then return candidates end - local newnode = xwall_get_candidate[id] + local newnode = xwall.get_candidate[id] if newnode and newnode[1] then local newname = string.sub(name, 1, string.len(name) -3)..newnode[1] if newname and minetest.registered_nodes[newname] then @@ -75,28 +77,25 @@ local xwall_update_one_node = function(pos, name, digged) return candidates end -local xwall_update = function(pos, name, active, has_been_digged) +function xwall.update(pos, name, active, has_been_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) + local c = xwall.update_one_node(pos, name, has_been_digged) for j = 1, #directions do local dir2 = directions[j] if c[j] ~= 0 and c[j] ~= "ignore" then - xwall_update_one_node({x=pos.x + dir2.x, y=pos.y, z=pos.z + dir2.z}, c[j], false) + xwall.update_one_node({x=pos.x + dir2.x, y=pos.y, z=pos.z + dir2.z}, c[j], false) end end end -local xwall_register = function(name, def, node_box_data) +function xwall.register(name, def, node_box_data) for k, v in pairs(node_box_data) do def.drawtype = "nodebox" def.paramtype = "light" def.paramtype2 = "facedir" def.drop = name.."_ln" - def.node_box = { - type = "fixed", - fixed = node_box_data[k] - } + def.node_box = {type = "fixed", fixed = node_box_data[k]} if not def.tiles then def.tiles = def.textures @@ -110,20 +109,20 @@ local xwall_register = function(name, def, node_box_data) local newdef = clone_table(def) if k == "ln" then newdef.on_construct = function(pos) - return xwall_update(pos, name.."_ln", true, nil) + return xwall.update(pos, name.."_ln", true, nil) end else newdef.groups.not_in_creative_inventory = 1 end newdef.after_dig_node = function(pos, oldnode, oldmetadata, digger) - return xwall_update(pos, name.."_ln", true, true) + return xwall.update(pos, name.."_ln", true, true) end - minetest.register_node(name.."_"..k, newdef) + minetest.register_node("xdecor:"..name.."_"..k, newdef) end end -local xwall_construct_node_box_data = function(node_box_list, center_node_box_list, node_box_line) +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 @@ -181,8 +180,8 @@ local xwall_construct_node_box_data = function(node_box_list, center_node_box_li return res end -local xwall_register_wall = function(name, tiles, def) - local node_box_data = xwall_construct_node_box_data( +function xwall.register_wall(name, tiles, def) + local node_box_data = xwall.construct_node_box_data( {{ -3/16, -0.5, 0, 3/16, 5/16, 0.5 }}, {{ -4/16, -0.5, -4/16, 4/16, 0.5, 4/16 }}, {{ -3/16, -0.5, -0.5, 3/16, 5/16, 0.5 }} @@ -190,8 +189,7 @@ local xwall_register_wall = function(name, tiles, def) if def then return end def = { - description = string.upper(string.sub(name, 8, 8))..string.sub(name, 9, -6).." ".. - string.upper(string.sub(name, -4, -4))..string.sub(name, -3), + description = string.sub(string.gsub(name, "%l", string.upper, 1), 1, -6).." Wall", textures = {tiles, tiles, tiles, tiles}, sounds = xdecor.stone, groups = {cracky=3, stone=1, pane=1}, @@ -200,8 +198,8 @@ local xwall_register_wall = function(name, tiles, def) fixed = {-0.5, -0.5, -0.25, 0.5, 1, 0.25} } } - xwall_register(name, def, node_box_data) + xwall.register(name, def, node_box_data) end -xwall_register_wall("xdecor:cobble_wall", "default_cobble.png") -xwall_register_wall("xdecor:mossycobble_wall", "default_mossycobble.png") +xwall.register_wall("cobble_wall", "default_cobble.png") +xwall.register_wall("mossycobble_wall", "default_mossycobble.png")