Fix metadata loss after using a locked door

This commit is contained in:
Sys Quatre 2020-08-04 20:15:39 +02:00
parent bd6909326c
commit 4d3a7e51df

View File

@ -22,14 +22,15 @@ end
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
pos = {x = pos.x, y = pos.y - 1, z = pos.z}
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 p2 = 0
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})
end
local olddata = locks:get_lockdata( pos );
minetest.add_node(pos, {name = "locks:door_bottom_"..t, param2 = p2})
minetest.add_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 );
-- No need to remember who owns the door, what passwords are set etc.
-- because minetest.swap_node() keeps metadata at pos
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})
end
@ -79,17 +77,16 @@ for i = 1, 2 do
on_construct = function(pos)
locks:lock_init( pos,
"size[8,2]"..
locks.uniform_background..
"button_exit[6.3,1.2;1.7,1;locks_sent_input;Proceed]" );
"size[8,2]"..locks.uniform_background..
"button_exit[6.3,1.2;1.7,1;locks_sent_input;Proceed]" )
end,
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,
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
})
minetest.register_node("locks:door_bottom_"..i, {
@ -112,17 +109,16 @@ for i = 1, 2 do
on_construct = function(pos)
locks:lock_init( pos,
"size[8,2]"..
locks.uniform_background..
"button_exit[6.3,1.2;1.7,1;locks_sent_input;Proceed]" );
"size[8,2]"..locks.uniform_background..
"button_exit[6.3,1.2;1.7,1;locks_sent_input;Proceed]" )
end,
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,
can_dig = function(pos,player)
return locks:lock_allow_dig( pos, player );
return locks:lock_allow_dig( pos, player )
end
})
end
@ -142,11 +138,12 @@ minetest.register_node("locks:door", {
stack_max = 1,
sunlight_propogates = true,
on_place = function(itemstack, placer, pointed_thing)
local pname = placer:get_player_name()
local above = pointed_thing.above
local above1 = {x = above.x, y = above.y + 1, z = above.z};
if (minetest.is_protected(above, placer:get_player_name())
or minetest.is_protected(above1, placer:get_player_name())) then
minetest.chat_send_player(placer:get_player_name(), "This area is protected!")
local above1 = {x = above.x, y = above.y + 1, z = above.z}
if (minetest.is_protected(above, pname)
or minetest.is_protected(above1, pname)) then
minetest.chat_send_player(pname, "This area is protected!")
return itemstack
else
-- there should be 2 empty nodes
@ -172,18 +169,17 @@ minetest.register_node("locks:door", {
end
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
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");
locks:lock_set_owner( above, pname or "", "Shared locked door")
locks:lock_set_owner( above1, pname or "", "Shared locked door")
return ItemStack("")
end
end
})
-- if xdoors2 is installed
if( minetest.get_modpath("xdoors2") ~= nil ) then
minetest.register_craft({
@ -191,7 +187,7 @@ if( minetest.get_modpath("xdoors2") ~= nil ) then
recipe = {
{ 'xdoors2:door', 'locks:lock', '' },
},
});
})
-- if the normal doors are installed
elseif( minetest.get_modpath("doors") ~= nil ) then
@ -212,10 +208,7 @@ else
{ 'default:wood', 'default:wood', 'locks:lock' },
{ 'default:wood', 'default:wood', '' },
},
});
})
end
end -- of previous else
print( "[Mod] locks: loading locks:door");
print( "[Mod] locks: loading locks:door")