From 7862875f85fcc080c38d672fe4a08616db665457 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Fri, 6 May 2022 12:33:24 +0200 Subject: [PATCH] Improve rightclick handler of doors --- mods/rp_door/init.lua | 20 +++++++++++++------- mods/rp_door/mod.conf | 2 +- mods/rp_util/init.lua | 2 +- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/mods/rp_door/init.lua b/mods/rp_door/init.lua index d692428..221a5e3 100644 --- a/mods/rp_door/init.lua +++ b/mods/rp_door/init.lua @@ -41,15 +41,21 @@ function door.register_door(name, def) groups = def.groups, on_place = function(itemstack, placer, pointed_thing) - if not pointed_thing.type == "node" then - return itemstack + -- Handle pointed node handlers first + local handled, handled_itemstack = util.on_place_pointed_node_handler(itemstack, placer, pointed_thing) + if handled then + return handled_itemstack end - local ptu = pointed_thing.under - local nu = minetest.get_node(ptu) - if minetest.registered_nodes[nu.name].on_rightclick then - return minetest.registered_nodes[nu.name].on_rightclick( - ptu, nu, placer, itemstack) + -- Check protection + local pos_protected = minetest.get_pointed_thing_position(pointed_thing, true) + for i=0, 1 do + local protpos = vector.add(pos_protected, vector.new(0, i, 0)) + if minetest.is_protected(protpos, placer:get_player_name()) and + not minetest.check_player_privs(placer, "protection_bypass") then + minetest.record_protection_violation(protpos, placer:get_player_name()) + return itemstack + end end local pt = pointed_thing.above diff --git a/mods/rp_door/mod.conf b/mods/rp_door/mod.conf index bd4d094..89c8519 100644 --- a/mods/rp_door/mod.conf +++ b/mods/rp_door/mod.conf @@ -1,2 +1,2 @@ name = rp_door -depends = rp_sounds, rp_crafting, rp_achievements +depends = rp_util, rp_sounds, rp_crafting, rp_achievements diff --git a/mods/rp_util/init.lua b/mods/rp_util/init.lua index c5eb704..892bff3 100644 --- a/mods/rp_util/init.lua +++ b/mods/rp_util/init.lua @@ -264,7 +264,7 @@ end -- on_place handler -- Recommended usage is by putting this boilerplate code at the beginning of your function: --[[ - local handled, handled_itemstack = on_place_pointed_node_handler(itemstack, placer, pointed_thing) + local handled, handled_itemstack = util.on_place_pointed_node_handler(itemstack, placer, pointed_thing) if handled then return handled_itemstack end