1
0
mirror of https://github.com/Sokomine/locks.git synced 2024-11-04 17:20:35 +01:00

Merge pull request #15 from CloudyProton/patch-3

Fix issue where locked doors can be placed in protected areas
This commit is contained in:
Sokomine 2018-07-30 18:59:11 +02:00 committed by GitHub
commit 9a8c272eb4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -142,38 +142,42 @@ minetest.register_node("locks:door", {
sunlight_propogates = true, sunlight_propogates = true,
on_place = function(itemstack, placer, pointed_thing) on_place = function(itemstack, placer, pointed_thing)
local above = pointed_thing.above local above = pointed_thing.above
if minetest.is_protected(above, placer:get_player_name()) then
minetest.chat_send_player(placer:get_player_name(), "This area is protected!")
return itemstack
else
-- there should be 2 empty nodes
if minetest.env:get_node({x = above.x, y = above.y + 1, z = above.z}).name ~= "air" then
return itemstack
end
-- there should be 2 empty nodes local fdir = 0
if minetest.env:get_node({x = above.x, y = above.y + 1, z = above.z}).name ~= "air" then local placer_pos = placer:getpos()
return itemstack if placer_pos then
end dir = {
x = above.x - placer_pos.x,
y = above.y - placer_pos.y,
z = above.z - placer_pos.z
}
fdir = minetest.dir_to_facedir(dir)
end
local fdir = 0 local t = 1
local placer_pos = placer:getpos() local another_door = minetest.env:get_node({x = above.x + delta[fdir + 1].x, y = above.y, z = above.z + delta[fdir + 1].z})
if placer_pos then if (another_door.name:sub(-1) == "1" and another_door.param2 == fdir)
dir = { or (another_door.name:sub(-1) == "2" and another_door.param2 == (fdir + 1) % 4) then
x = above.x - placer_pos.x, t = 2
y = above.y - placer_pos.y, end
z = above.z - placer_pos.z
}
fdir = minetest.dir_to_facedir(dir)
end
local t = 1 minetest.env:add_node(above, {name = "locks:door_bottom_"..t, param2 = fdir})
local another_door = minetest.env:get_node({x = above.x + delta[fdir + 1].x, y = above.y, z = above.z + delta[fdir + 1].z}) minetest.env:add_node({x = above.x, y = above.y + 1, z = above.z}, {name = "locks:door_top_"..t, param2 = fdir})
if (another_door.name:sub(-1) == "1" and another_door.param2 == fdir)
or (another_door.name:sub(-1) == "2" and another_door.param2 == (fdir + 1) % 4) then
t = 2
end
minetest.env:add_node(above, {name = "locks:door_bottom_"..t, param2 = fdir}) -- store who owns the door; the other data can be default for now
minetest.env:add_node({x = above.x, y = above.y + 1, z = above.z}, {name = "locks:door_top_"..t, param2 = fdir}) locks:lock_set_owner( above, placer:get_player_name() or "", "Shared locked door");
locks:lock_set_owner( {x = above.x, y = above.y + 1, z = above.z}, placer:get_player_name() or "", "Shared locked door");
-- store who owns the door; the other data can be default for now return ItemStack("")
locks:lock_set_owner( above, placer:get_player_name() or "", "Shared locked door"); end
locks:lock_set_owner( {x = above.x, y = above.y + 1, z = above.z}, placer:get_player_name() or "", "Shared locked door");
return ItemStack("")
end end
}) })