Fix rope protection handling and get rid of a global callback.

This commit is contained in:
Tim 2016-09-03 17:32:08 +02:00
parent 0bba88c7f4
commit 480e55ed89

View File

@ -1,12 +1,6 @@
local rope = {}
-- Code by Mirko K. (modified by Temperest, Wulfsdad and kilbith) (License: GPL).
minetest.register_on_punchnode(function(pos, oldnode, digger)
if oldnode.name == "xdecor:rope" then
rope:remove(pos, oldnode, digger, "xdecor:rope")
end
end)
function rope.place(itemstack, placer, pointed_thing)
if pointed_thing.type == "node" then
local pos = pointed_thing.above
@ -27,7 +21,7 @@ function rope.place(itemstack, placer, pointed_thing)
return itemstack
end
function rope:remove(pos, oldnode, digger, rope_name)
function rope.remove(pos, oldnode, digger, rope_name)
local num = 0
local below = {x=pos.x, y=pos.y, z=pos.z}
local digger_inv = digger:get_inventory()
@ -52,5 +46,12 @@ xdecor.register("rope", {
inventory_image = "xdecor_rope_inv.png",
wield_image = "xdecor_rope_inv.png",
selection_box = xdecor.pixelbox(8, {{3, 0, 3, 2, 8, 2}}),
on_place = rope.place
on_place = rope.place,
on_punch = function(pos, node, puncher, pointed_thing)
local player_name = puncher:get_player_name()
if not minetest.is_protected(pos, player_name) or
minetest.get_player_privs(player_name).protection_bypass then
rope.remove(pos, node, puncher, "xdecor:rope")
end
end
})