From 53b62463fc8acb80a6eac92d3838454d54ef243c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Mart=C3=ADnez?= Date: Thu, 23 May 2013 06:19:07 -0300 Subject: [PATCH] Fix wrong check for ownership on fence placement, respect pointed_thing on_rightclick callback, and support placing fences in buildable_to nodes --- fences.lua | 10 ---------- signs_lib.lua | 20 ++++++++++++++++---- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/fences.lua b/fences.lua index 14b273c..7752f5b 100644 --- a/fences.lua +++ b/fences.lua @@ -23,16 +23,6 @@ minetest.register_node("homedecor:fence_brass", { groups = {snappy=3}, sounds = default.node_sound_wood_defaults(), walkable = true, - - on_place = function(itemstack, placer, pointed_thing) - if not homedecor_node_is_owned(pointed_thing.under, placer) then - local fdir = minetest.dir_to_facedir(placer:get_look_dir()) - minetest.env:add_node(pointed_thing.above, {name = "homedecor:fence_brass", param2 = fdir}) - itemstack:take_item() - placer:set_wielded_item(itemstack) - return itemstack - end - end }) minetest.register_node("homedecor:fence_wrought_iron", { diff --git a/signs_lib.lua b/signs_lib.lua index 17590a4..bd900b4 100644 --- a/signs_lib.lua +++ b/signs_lib.lua @@ -417,11 +417,23 @@ function homedecor_register_fence_with_sign(fencename, fencewithsignname) def = copy(def) def_sign = copy(def_sign) fences_with_sign[fencename] = fencewithsignname + def.on_place = function(itemstack, placer, pointed_thing, ...) - local def = minetest.registered_nodes[minetest.env:get_node(pointed_thing.above).name] - if (not homedecor_node_is_owned(pointed_thing.under, placer)) - and def.buildable_to then - local fdir = minetest.dir_to_facedir(placer:get_look_dir()) + local node_above = minetest.env:get_node(pointed_thing.above) + local node_under = minetest.env:get_node(pointed_thing.under) + local def_above = minetest.registered_nodes[node_above.name] + local def_under = minetest.registered_nodes[node_under.name] + local fdir = minetest.dir_to_facedir(placer:get_look_dir()) + if def_under and def_under.on_rightclick then + return def_under.on_rightclick(pointed_thing.under, node_under, placer, itemstack) or itemstack + elseif (not homedecor_node_is_owned(pointed_thing.under, placer)) + and def_under.buildable_to then + minetest.env:add_node(pointed_thing.under, {name = fencename, param2 = fdir}) + itemstack:take_item() + placer:set_wielded_item(itemstack) + return itemstack + elseif (not homedecor_node_is_owned(pointed_thing.above, placer)) + and def_above.buildable_to then minetest.env:add_node(pointed_thing.above, {name = fencename, param2 = fdir}) itemstack:take_item() placer:set_wielded_item(itemstack)