forked from mtcontrib/locks
Fix metadata loss after using a locked door
This commit is contained in:
parent
bd6909326c
commit
4d3a7e51df
@ -22,14 +22,15 @@ end
|
|||||||
|
|
||||||
local xdoors2_transform = function(pos, node, puncher)
|
local xdoors2_transform = function(pos, node, puncher)
|
||||||
|
|
||||||
if( not( locks:lock_allow_use( pos, puncher ))) then
|
|
||||||
minetest.chat_send_player( puncher:get_player_name(), "This door is locked. It can only be opened by its owner or people with a key that fits.");
|
|
||||||
return;
|
|
||||||
end
|
|
||||||
|
|
||||||
if is_top(node.name) then
|
if is_top(node.name) then
|
||||||
pos = {x = pos.x, y = pos.y - 1, z = pos.z}
|
pos = {x = pos.x, y = pos.y - 1, z = pos.z}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if( not( locks:lock_allow_use( pos, puncher ))) then
|
||||||
|
minetest.chat_send_player( puncher:get_player_name(), "This door is locked. It can only be opened by its owner or people with a key that fits.")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local t = 3 - node.name:sub(-1)
|
local t = 3 - node.name:sub(-1)
|
||||||
local p2 = 0
|
local p2 = 0
|
||||||
if t == 2 then
|
if t == 2 then
|
||||||
@ -40,13 +41,10 @@ local xdoors2_transform = function(pos, node, puncher)
|
|||||||
minetest.sound_play("doors_door_close", { pos = pos, gain = 0.3, max_hear_distance = 10})
|
minetest.sound_play("doors_door_close", { pos = pos, gain = 0.3, max_hear_distance = 10})
|
||||||
end
|
end
|
||||||
|
|
||||||
local olddata = locks:get_lockdata( pos );
|
-- No need to remember who owns the door, what passwords are set etc.
|
||||||
minetest.add_node(pos, {name = "locks:door_bottom_"..t, param2 = p2})
|
-- because minetest.swap_node() keeps metadata at pos
|
||||||
minetest.add_node({x = pos.x, y = pos.y + 1, z = pos.z}, {name = "locks:door_top_"..t, param2 = p2})
|
minetest.swap_node(pos, {name = "locks:door_bottom_"..t, param2 = p2})
|
||||||
|
minetest.swap_node({x = pos.x, y = pos.y + 1, z = pos.z}, {name = "locks:door_top_"..t, param2 = p2})
|
||||||
-- remember who owns the door, what passwords are set etc.
|
|
||||||
locks:set_lockdata( pos, olddata );
|
|
||||||
locks:set_lockdata( {x = pos.x, y = pos.y + 1, z = pos.z}, olddata );
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -79,17 +77,16 @@ for i = 1, 2 do
|
|||||||
|
|
||||||
on_construct = function(pos)
|
on_construct = function(pos)
|
||||||
locks:lock_init( pos,
|
locks:lock_init( pos,
|
||||||
"size[8,2]"..
|
"size[8,2]"..locks.uniform_background..
|
||||||
locks.uniform_background..
|
"button_exit[6.3,1.2;1.7,1;locks_sent_input;Proceed]" )
|
||||||
"button_exit[6.3,1.2;1.7,1;locks_sent_input;Proceed]" );
|
|
||||||
end,
|
end,
|
||||||
|
|
||||||
on_receive_fields = function(pos, formname, fields, sender)
|
on_receive_fields = function(pos, formname, fields, sender)
|
||||||
locks:lock_handle_input( pos, formname, fields, sender );
|
locks:lock_handle_input( {x=pos.x, y=pos.y-1, z=pos.z}, formname, fields, sender )
|
||||||
end,
|
end,
|
||||||
|
|
||||||
can_dig = function(pos,player)
|
can_dig = function(pos,player)
|
||||||
return locks:lock_allow_dig( pos, player );
|
return locks:lock_allow_dig( {x=pos.x, y=pos.y-1, z=pos.z}, player )
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
minetest.register_node("locks:door_bottom_"..i, {
|
minetest.register_node("locks:door_bottom_"..i, {
|
||||||
@ -112,17 +109,16 @@ for i = 1, 2 do
|
|||||||
|
|
||||||
on_construct = function(pos)
|
on_construct = function(pos)
|
||||||
locks:lock_init( pos,
|
locks:lock_init( pos,
|
||||||
"size[8,2]"..
|
"size[8,2]"..locks.uniform_background..
|
||||||
locks.uniform_background..
|
"button_exit[6.3,1.2;1.7,1;locks_sent_input;Proceed]" )
|
||||||
"button_exit[6.3,1.2;1.7,1;locks_sent_input;Proceed]" );
|
|
||||||
end,
|
end,
|
||||||
|
|
||||||
on_receive_fields = function(pos, formname, fields, sender)
|
on_receive_fields = function(pos, formname, fields, sender)
|
||||||
locks:lock_handle_input( pos, formname, fields, sender );
|
locks:lock_handle_input( pos, formname, fields, sender )
|
||||||
end,
|
end,
|
||||||
|
|
||||||
can_dig = function(pos,player)
|
can_dig = function(pos,player)
|
||||||
return locks:lock_allow_dig( pos, player );
|
return locks:lock_allow_dig( pos, player )
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
@ -142,11 +138,12 @@ minetest.register_node("locks:door", {
|
|||||||
stack_max = 1,
|
stack_max = 1,
|
||||||
sunlight_propogates = true,
|
sunlight_propogates = true,
|
||||||
on_place = function(itemstack, placer, pointed_thing)
|
on_place = function(itemstack, placer, pointed_thing)
|
||||||
|
local pname = placer:get_player_name()
|
||||||
local above = pointed_thing.above
|
local above = pointed_thing.above
|
||||||
local above1 = {x = above.x, y = above.y + 1, z = above.z};
|
local above1 = {x = above.x, y = above.y + 1, z = above.z}
|
||||||
if (minetest.is_protected(above, placer:get_player_name())
|
if (minetest.is_protected(above, pname)
|
||||||
or minetest.is_protected(above1, placer:get_player_name())) then
|
or minetest.is_protected(above1, pname)) then
|
||||||
minetest.chat_send_player(placer:get_player_name(), "This area is protected!")
|
minetest.chat_send_player(pname, "This area is protected!")
|
||||||
return itemstack
|
return itemstack
|
||||||
else
|
else
|
||||||
-- there should be 2 empty nodes
|
-- there should be 2 empty nodes
|
||||||
@ -172,18 +169,17 @@ minetest.register_node("locks:door", {
|
|||||||
end
|
end
|
||||||
|
|
||||||
minetest.add_node(above, {name = "locks:door_bottom_"..t, param2 = fdir})
|
minetest.add_node(above, {name = "locks:door_bottom_"..t, param2 = fdir})
|
||||||
minetest.add_node({x = above.x, y = above.y + 1, z = above.z}, {name = "locks:door_top_"..t, param2 = fdir})
|
minetest.add_node(above1, {name = "locks:door_top_"..t, param2 = fdir})
|
||||||
|
|
||||||
-- store who owns the door; the other data can be default for now
|
-- store who owns the door; the other data can be default for now
|
||||||
locks:lock_set_owner( above, placer:get_player_name() or "", "Shared locked door");
|
locks:lock_set_owner( above, pname 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");
|
locks:lock_set_owner( above1, pname or "", "Shared locked door")
|
||||||
|
|
||||||
return ItemStack("")
|
return ItemStack("")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
-- if xdoors2 is installed
|
-- if xdoors2 is installed
|
||||||
if( minetest.get_modpath("xdoors2") ~= nil ) then
|
if( minetest.get_modpath("xdoors2") ~= nil ) then
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
@ -191,7 +187,7 @@ if( minetest.get_modpath("xdoors2") ~= nil ) then
|
|||||||
recipe = {
|
recipe = {
|
||||||
{ 'xdoors2:door', 'locks:lock', '' },
|
{ 'xdoors2:door', 'locks:lock', '' },
|
||||||
},
|
},
|
||||||
});
|
})
|
||||||
|
|
||||||
-- if the normal doors are installed
|
-- if the normal doors are installed
|
||||||
elseif( minetest.get_modpath("doors") ~= nil ) then
|
elseif( minetest.get_modpath("doors") ~= nil ) then
|
||||||
@ -212,10 +208,7 @@ else
|
|||||||
{ 'default:wood', 'default:wood', 'locks:lock' },
|
{ 'default:wood', 'default:wood', 'locks:lock' },
|
||||||
{ 'default:wood', 'default:wood', '' },
|
{ 'default:wood', 'default:wood', '' },
|
||||||
},
|
},
|
||||||
});
|
})
|
||||||
end
|
end
|
||||||
end -- of previous else
|
|
||||||
|
|
||||||
|
print( "[Mod] locks: loading locks:door")
|
||||||
|
|
||||||
print( "[Mod] locks: loading locks:door");
|
|
||||||
|
Loading…
Reference in New Issue
Block a user