Can't extend rope into protected area

This commit is contained in:
Wuzzy 2024-03-08 14:05:02 +01:00
parent 992616a3f0
commit 3a896b4a90

View File

@ -7,6 +7,8 @@ local ropesounds = default.node_sound_leaves_defaults()
-- Code by Mirko K. (modified by Temperest, Wulfsdad, kilbith and Wuzzy) (License: GPL). -- Code by Mirko K. (modified by Temperest, Wulfsdad, kilbith and Wuzzy) (License: GPL).
function rope.place(itemstack, placer, pointed_thing) function rope.place(itemstack, placer, pointed_thing)
local creative = minetest.is_creative_enabled(placer:get_player_name()) local creative = minetest.is_creative_enabled(placer:get_player_name())
local protection_bypass = minetest.check_player_privs(placer, "protection_bypass")
local pname = placer:get_player_name()
if pointed_thing.type == "node" then if pointed_thing.type == "node" then
-- Use pointed node's on_rightclick function first, if present -- Use pointed node's on_rightclick function first, if present
if placer and not placer:get_player_control().sneak then if placer and not placer:get_player_control().sneak then
@ -17,9 +19,8 @@ function rope.place(itemstack, placer, pointed_thing)
end end
local pos = pointed_thing.above local pos = pointed_thing.above
-- Check protection -- Check protection
if minetest.is_protected(pos, placer:get_player_name()) and if minetest.is_protected(pos, pname) and not protection_bypass then
not minetest.check_player_privs(placer, "protection_bypass") then minetest.record_protection_violation(pos, pname)
minetest.record_protection_violation(pos, placer:get_player_name())
return itemstack return itemstack
end end
@ -29,12 +30,17 @@ function rope.place(itemstack, placer, pointed_thing)
-- Prevents the rope to extend infinitely in Creative Mode. -- Prevents the rope to extend infinitely in Creative Mode.
local max_ropes = math.min(itemstack:get_stack_max(), MAX_ROPES) local max_ropes = math.min(itemstack:get_stack_max(), MAX_ROPES)
-- Start placing ropes and extend it downwards until we run out of ropes -- Start placing ropes and extend it downwards until we hit an obstacle,
-- or hit the maximum -- run out of ropes or hit the maximum rope length.
local start_pos = table.copy(pos) local start_pos = table.copy(pos)
local ropes_to_place = 0 local ropes_to_place = 0
local new_rope_nodes = {} local new_rope_nodes = {}
while oldnode.name == "air" and (creative or (ropes_to_place < itemstack:get_size())) and ropes_to_place < max_ropes do while oldnode.name == "air" and (creative or (ropes_to_place < itemstack:get_size())) and ropes_to_place < max_ropes do
-- Stop extending rope into protected area
if minetest.is_protected(pos, pname) and not protection_bypass then
break
end
table.insert(new_rope_nodes, table.copy(pos)) table.insert(new_rope_nodes, table.copy(pos))
pos.y = pos.y - 1 pos.y = pos.y - 1
oldnode = minetest.get_node(pos) oldnode = minetest.get_node(pos)