avoid duplicating get_nodedef_field() function

(both doors/gates and desk need it)

moved to init.lua and into homedecor.* namespace.
This commit is contained in:
Vanessa Ezekowitz 2014-06-29 10:47:25 -04:00
parent f8efeee4d7
commit ba3abaa6a6
3 changed files with 12 additions and 18 deletions

View File

@ -412,13 +412,6 @@ minetest.register_alias("homedecor:fence_picket_gate_white_closed", "homedecor:g
----- helper functions ----- 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) function homedecor.place_door(itemstack, placer, pointed_thing, name, forceright)
local pointed = pointed_thing.under local pointed = pointed_thing.under
@ -459,8 +452,8 @@ function homedecor.place_door(itemstack, placer, pointed_thing, name, forceright
return return
end end
if not get_nodedef_field(node_bottom.name, "buildable_to") if not homedecor.get_nodedef_field(node_bottom.name, "buildable_to")
or not get_nodedef_field(node_top.name, "buildable_to") then 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!') ) minetest.chat_send_player( placer:get_player_name(), S('Not enough space above that spot to place a door!') )
else else
local fdir = minetest.dir_to_facedir(placer:get_look_dir()) local fdir = minetest.dir_to_facedir(placer:get_look_dir())

View File

@ -54,6 +54,14 @@ function homedecor.table_copy(t)
return nt return nt
end 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 -- load various other components

View File

@ -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 = { local fdir_to_right = {
{ 1, 0 }, { 1, 0 },
{ 0, -1 }, { 0, -1 },
@ -546,8 +539,8 @@ minetest.register_node("homedecor:desk", {
local tnode = minetest.get_node(pos) local tnode = minetest.get_node(pos)
local tnode2 = minetest.get_node(pos2) local tnode2 = minetest.get_node(pos2)
if get_nodedef_field(tnode.name, "buildable_to") if homedecor.get_nodedef_field(tnode.name, "buildable_to")
and get_nodedef_field(tnode2.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(pos, placer:get_player_name())
and not minetest.is_protected(pos2, placer:get_player_name()) then and not minetest.is_protected(pos2, placer:get_player_name()) then
minetest.add_node(pos, { name = "homedecor:desk", param2 = fdir }) minetest.add_node(pos, { name = "homedecor:desk", param2 = fdir })