From ba3abaa6a68f730ee8dbd7f6147eaef2af644a1c Mon Sep 17 00:00:00 2001 From: Vanessa Ezekowitz Date: Sun, 29 Jun 2014 10:47:25 -0400 Subject: [PATCH] avoid duplicating get_nodedef_field() function (both doors/gates and desk need it) moved to init.lua and into homedecor.* namespace. --- homedecor/doors_and_gates.lua | 11 ++--------- homedecor/init.lua | 8 ++++++++ homedecor/tables.lua | 11 ++--------- 3 files changed, 12 insertions(+), 18 deletions(-) diff --git a/homedecor/doors_and_gates.lua b/homedecor/doors_and_gates.lua index df356b1c..068704a3 100644 --- a/homedecor/doors_and_gates.lua +++ b/homedecor/doors_and_gates.lua @@ -412,13 +412,6 @@ minetest.register_alias("homedecor:fence_picket_gate_white_closed", "homedecor:g ----- helper functions -local function get_nodedef_field(nodename, fieldname) - if not minetest.registered_nodes[nodename] then - return nil - end - return minetest.registered_nodes[nodename][fieldname] -end - function homedecor.place_door(itemstack, placer, pointed_thing, name, forceright) local pointed = pointed_thing.under @@ -459,8 +452,8 @@ function homedecor.place_door(itemstack, placer, pointed_thing, name, forceright return end - if not get_nodedef_field(node_bottom.name, "buildable_to") - or not get_nodedef_field(node_top.name, "buildable_to") then + if not homedecor.get_nodedef_field(node_bottom.name, "buildable_to") + or not homedecor.get_nodedef_field(node_top.name, "buildable_to") then minetest.chat_send_player( placer:get_player_name(), S('Not enough space above that spot to place a door!') ) else local fdir = minetest.dir_to_facedir(placer:get_look_dir()) diff --git a/homedecor/init.lua b/homedecor/init.lua index fc5c4117..a59f66a7 100644 --- a/homedecor/init.lua +++ b/homedecor/init.lua @@ -54,6 +54,14 @@ function homedecor.table_copy(t) return nt end +-- + +function homedecor.get_nodedef_field(nodename, fieldname) + if not minetest.registered_nodes[nodename] then + return nil + end + return minetest.registered_nodes[nodename][fieldname] +end -- load various other components diff --git a/homedecor/tables.lua b/homedecor/tables.lua index ac90eec4..5d6fd543 100644 --- a/homedecor/tables.lua +++ b/homedecor/tables.lua @@ -489,13 +489,6 @@ minetest.register_node('homedecor:utility_table_legs', { }, }) -local function get_nodedef_field(nodename, fieldname) - if not minetest.registered_nodes[nodename] then - return nil - end - return minetest.registered_nodes[nodename][fieldname] -end - local fdir_to_right = { { 1, 0 }, { 0, -1 }, @@ -546,8 +539,8 @@ minetest.register_node("homedecor:desk", { local tnode = minetest.get_node(pos) local tnode2 = minetest.get_node(pos2) - if get_nodedef_field(tnode.name, "buildable_to") - and get_nodedef_field(tnode2.name, "buildable_to") + if homedecor.get_nodedef_field(tnode.name, "buildable_to") + and homedecor.get_nodedef_field(tnode2.name, "buildable_to") and not minetest.is_protected(pos, placer:get_player_name()) and not minetest.is_protected(pos2, placer:get_player_name()) then minetest.add_node(pos, { name = "homedecor:desk", param2 = fdir })