1
0
mirror of https://github.com/minetest/minetest_game.git synced 2024-12-23 15:20:19 +01:00

Change doors to default.can_interact_with_node()

This commit is contained in:
Thomas--S 2017-02-21 19:43:34 +01:00 committed by Auke Kok
parent bd4d2dff1c
commit 73e4666f28

View File

@ -6,6 +6,15 @@ local _doors = {}
_doors.registered_doors = {} _doors.registered_doors = {}
_doors.registered_trapdoors = {} _doors.registered_trapdoors = {}
local function replace_old_owner_information(pos)
local meta = minetest.get_meta(pos)
local owner = meta:get_string("doors_owner")
if owner and owner ~= "" then
meta:set_string("owner", owner)
meta:set_string("doors_owner", "")
end
end
-- returns an object to a door object or nil -- returns an object to a door object or nil
function doors.get(pos) function doors.get(pos)
local node_name = minetest.get_node(pos).name local node_name = minetest.get_node(pos).name
@ -139,30 +148,12 @@ function _doors.door_toggle(pos, node, clicker)
state = tonumber(state) state = tonumber(state)
end end
if clicker and not minetest.check_player_privs(clicker, "protection_bypass") then replace_old_owner_information(pos)
-- is player wielding the right key?
local item = clicker:get_wielded_item()
local owner = meta:get_string("doors_owner")
if item:get_name() == "default:key" then
local key_meta = item:get_meta()
local secret = meta:get_string("key_lock_secret")
if key_meta:get_string("secret") == "" then if not default.can_interact_with_node(clicker, pos) then
key_meta:set_string("secret", minetest.parse_json(item:get_metadata()).secret)
item:set_metadata("")
end
if secret ~= key_meta:get_string("secret") then
return false return false
end end
elseif owner ~= "" then
if clicker:get_player_name() ~= owner then
return false
end
end
end
-- until Lua-5.2 we have no bitwise operators :( -- until Lua-5.2 we have no bitwise operators :(
if state % 2 == 1 then if state % 2 == 1 then
state = state - 1 state = state - 1
@ -211,11 +202,8 @@ local function on_place_node(place_to, newnode,
end end
local function can_dig_door(pos, digger) local function can_dig_door(pos, digger)
local digger_name = digger and digger:get_player_name() replace_old_owner_information(pos)
if digger_name and minetest.get_player_privs(digger_name).protection_bypass then return default.can_interact_with_node(digger, pos)
return true
end
return minetest.get_meta(pos):get_string("doors_owner") == digger_name
end end
function doors.register(name, def) function doors.register(name, def)
@ -330,7 +318,7 @@ function doors.register(name, def)
meta:set_int("state", state) meta:set_int("state", state)
if def.protected then if def.protected then
meta:set_string("doors_owner", pn) meta:set_string("owner", pn)
meta:set_string("infotext", "Owned by " .. pn) meta:set_string("infotext", "Owned by " .. pn)
end end
@ -394,8 +382,9 @@ function doors.register(name, def)
door:toggle(player) door:toggle(player)
end end
def.on_skeleton_key_use = function(pos, player, newsecret) def.on_skeleton_key_use = function(pos, player, newsecret)
replace_old_owner_information(pos)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local owner = meta:get_string("doors_owner") local owner = meta:get_string("owner")
local pname = player:get_player_name() local pname = player:get_player_name()
-- verify placer is owner of lockable door -- verify placer is owner of lockable door
@ -532,30 +521,13 @@ end
function _doors.trapdoor_toggle(pos, node, clicker) function _doors.trapdoor_toggle(pos, node, clicker)
node = node or minetest.get_node(pos) node = node or minetest.get_node(pos)
if clicker and not minetest.check_player_privs(clicker, "protection_bypass") then
-- is player wielding the right key?
local item = clicker:get_wielded_item()
local meta = minetest.get_meta(pos)
local owner = meta:get_string("doors_owner")
if item:get_name() == "default:key" then
local key_meta = item:get_meta()
local secret = meta:get_string("key_lock_secret")
if key_meta:get_string("secret") == "" then replace_old_owner_information(pos)
key_meta:set_string("secret", minetest.parse_json(item:get_metadata()).secret)
end
if secret ~= key_meta:get_string("secret") then if not default.can_interact_with_node(clicker, pos) then
return false return false
end end
elseif owner ~= "" then
if clicker:get_player_name() ~= owner then
return false
end
end
end
local def = minetest.registered_nodes[node.name] local def = minetest.registered_nodes[node.name]
if string.sub(node.name, -5) == "_open" then if string.sub(node.name, -5) == "_open" then
@ -595,7 +567,7 @@ function doors.register_trapdoor(name, def)
def.after_place_node = function(pos, placer, itemstack, pointed_thing) def.after_place_node = function(pos, placer, itemstack, pointed_thing)
local pn = placer:get_player_name() local pn = placer:get_player_name()
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
meta:set_string("doors_owner", pn) meta:set_string("owner", pn)
meta:set_string("infotext", "Owned by "..pn) meta:set_string("infotext", "Owned by "..pn)
return minetest.setting_getbool("creative_mode") return minetest.setting_getbool("creative_mode")
@ -607,8 +579,9 @@ function doors.register_trapdoor(name, def)
door:toggle(player) door:toggle(player)
end end
def.on_skeleton_key_use = function(pos, player, newsecret) def.on_skeleton_key_use = function(pos, player, newsecret)
replace_old_owner_information(pos)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local owner = meta:get_string("doors_owner") local owner = meta:get_string("owner")
local pname = player:get_player_name() local pname = player:get_player_name()
-- verify placer is owner of lockable door -- verify placer is owner of lockable door