From e492780510fed04db04b75899bbb7c6607c40b80 Mon Sep 17 00:00:00 2001 From: Vanessa Ezekowitz Date: Tue, 21 Jul 2015 05:08:40 -0400 Subject: [PATCH] fix missing protection on sofas and coffee tables add some informative messages --- lrfurn/coffeetable.lua | 47 ++++++++++++++++++++++++++---------------- lrfurn/init.lua | 21 +++++++++++++++---- lrfurn/longsofas.lua | 9 +++++--- lrfurn/sofas.lua | 10 ++++++--- 4 files changed, 59 insertions(+), 28 deletions(-) diff --git a/lrfurn/coffeetable.lua b/lrfurn/coffeetable.lua index 4abe3ca4..db52b72d 100644 --- a/lrfurn/coffeetable.lua +++ b/lrfurn/coffeetable.lua @@ -24,27 +24,36 @@ minetest.register_node("lrfurn:coffeetable_back", { } }, - on_construct = function(pos) + after_place_node = function(pos, placer, itemstack, pointed_thing) + if minetest.is_protected(pos, placer:get_player_name()) then return true end local node = minetest.get_node(pos) local param2 = node.param2 - node.name = "lrfurn:coffeetable_front" - if param2 == 0 then - pos.z = pos.z+1 - elseif param2 == 1 then - pos.x = pos.x+1 - elseif param2 == 2 then - pos.z = pos.z-1 - elseif param2 == 3 then - pos.x = pos.x-1 - end - if( minetest.get_node({x=pos.x, y=pos.y, z=pos.z}).name == "air" ) then + + if lrfurn.check_forward(pos, fdir, false, placer) then + + node.name = "lrfurn:coffeetable_front" + if param2 == 0 then + pos.z = pos.z+1 + elseif param2 == 1 then + pos.x = pos.x+1 + elseif param2 == 2 then + pos.z = pos.z-1 + elseif param2 == 3 then + pos.x = pos.x-1 + end minetest.set_node(pos, node) + else + minetest.chat_send_player(placer:get_player_name(), "No room to place the coffee table!") + minetest.set_node(pos, {name = "air"}) + return true end + end, - on_destruct = function(pos) - local node = minetest.get_node(pos) - local param2 = node.param2 + after_dig_node = function(pos, oldnode, oldmetadata, digger) + if minetest.is_protected(pos, digger:get_player_name()) then return true end + + local param2 = oldnode.param2 if param2 == 0 then pos.z = pos.z+1 elseif param2 == 1 then @@ -54,10 +63,12 @@ minetest.register_node("lrfurn:coffeetable_back", { elseif param2 == 3 then pos.x = pos.x-1 end - if( minetest.get_node({x=pos.x, y=pos.y, z=pos.z}).name == "lrfurn:coffeetable_front" ) then - if( minetest.get_node({x=pos.x, y=pos.y, z=pos.z}).param2 == param2 ) then + + if minetest.is_protected(pos, digger:get_player_name()) then return true end + + if (minetest.get_node({x=pos.x, y=pos.y, z=pos.z}).name == "lrfurn:coffeetable_front") + and (minetest.get_node({x=pos.x, y=pos.y, z=pos.z}).param2 == param2) then minetest.remove_node(pos) - end end end, }) diff --git a/lrfurn/init.lua b/lrfurn/init.lua index 2d60dabe..7155f204 100644 --- a/lrfurn/init.lua +++ b/lrfurn/init.lua @@ -8,19 +8,32 @@ lrfurn.fdir_to_fwd = { { -1, 0 }, } -function lrfurn.check_forward(pos, fdir, long) - +function lrfurn.check_forward(pos, fdir, long, placer) if not fdir or fdir > 3 then fdir = 0 end local pos2 = { x = pos.x + lrfurn.fdir_to_fwd[fdir+1][1], y=pos.y, z = pos.z + lrfurn.fdir_to_fwd[fdir+1][2] } local pos3 = { x = pos.x + lrfurn.fdir_to_fwd[fdir+1][1] * 2, y=pos.y, z = pos.z + lrfurn.fdir_to_fwd[fdir+1][2] * 2 } local node2 = minetest.get_node(pos2) - if node2 and node2.name ~= "air" then return false end + if node2 and node2.name ~= "air" then + return false + elseif minetest.is_protected(pos2, placer:get_player_name()) then + if not long then + minetest.chat_send_player(placer:get_player_name(), "Someone else owns the spot where other end goes!") + else + minetest.chat_send_player(placer:get_player_name(), "Someone else owns the spot where the middle or far end goes!") + end + return false + end if long then local node3 = minetest.get_node(pos3) - if node3 and node3.name ~= "air" then return false end + if node3 and node3.name ~= "air" then + return false + elseif minetest.is_protected(pos3, placer:get_player_name()) then + minetest.chat_send_player(placer:get_player_name(), "Someone else owns the spot where the other end goes!") + return false + end end return true diff --git a/lrfurn/longsofas.lua b/lrfurn/longsofas.lua index 321a7ad8..71277baf 100644 --- a/lrfurn/longsofas.lua +++ b/lrfurn/longsofas.lua @@ -42,15 +42,18 @@ for i in ipairs(longsofas_list) do selection_box = longsofa_sbox, node_box = longsofa_cbox, on_rotate = screwdriver.disallow, - on_place = function(itemstack, placer, pointed_thing) - local pos = pointed_thing.above + + after_place_node = function(pos, placer, itemstack, pointed_thing) + if minetest.is_protected(pos, placer:get_player_name()) then return true end + local fdir = minetest.dir_to_facedir(placer:get_look_dir(), false) - if lrfurn.check_forward(pos, fdir, true) then + if lrfurn.check_forward(pos, fdir, true, placer) then minetest.set_node(pos, {name = "lrfurn:longsofa_"..colour, param2 = fdir}) itemstack:take_item() else minetest.chat_send_player(placer:get_player_name(), "No room to place the sofa!") + minetest.set_node(pos, { name = "air" }) end return itemstack end, diff --git a/lrfurn/sofas.lua b/lrfurn/sofas.lua index 32b03020..600ac253 100644 --- a/lrfurn/sofas.lua +++ b/lrfurn/sofas.lua @@ -42,15 +42,19 @@ for i in ipairs(sofas_list) do selection_box = sofa_sbox, node_box = sofa_cbox, on_rotate = screwdriver.disallow, - on_place = function(itemstack, placer, pointed_thing) - local pos = pointed_thing.above + + after_place_node = function(pos, placer, itemstack, pointed_thing) + if minetest.is_protected(pos, placer:get_player_name()) then return true end + local fdir = minetest.dir_to_facedir(placer:get_look_dir(), false) - if lrfurn.check_forward(pos, fdir, true) then + if lrfurn.check_forward(pos, fdir, false, placer) then minetest.set_node(pos, {name = "lrfurn:sofa_"..colour, param2 = fdir}) itemstack:take_item() else minetest.chat_send_player(placer:get_player_name(), "No room to place the sofa!") + minetest.set_node(pos, { name = "air" }) + end return itemstack end,