mirror of
https://github.com/minetest/minetest_game.git
synced 2024-11-05 23:33:51 +01:00
Change doors to default.can_interact_with_node()
This commit is contained in:
parent
bd4d2dff1c
commit
73e4666f28
@ -6,6 +6,15 @@ local _doors = {}
|
||||
_doors.registered_doors = {}
|
||||
_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
|
||||
function doors.get(pos)
|
||||
local node_name = minetest.get_node(pos).name
|
||||
@ -139,30 +148,12 @@ function _doors.door_toggle(pos, node, clicker)
|
||||
state = tonumber(state)
|
||||
end
|
||||
|
||||
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 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")
|
||||
replace_old_owner_information(pos)
|
||||
|
||||
if key_meta:get_string("secret") == "" 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
|
||||
if not default.can_interact_with_node(clicker, pos) then
|
||||
return false
|
||||
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 :(
|
||||
if state % 2 == 1 then
|
||||
state = state - 1
|
||||
@ -211,11 +202,8 @@ local function on_place_node(place_to, newnode,
|
||||
end
|
||||
|
||||
local function can_dig_door(pos, digger)
|
||||
local digger_name = digger and digger:get_player_name()
|
||||
if digger_name and minetest.get_player_privs(digger_name).protection_bypass then
|
||||
return true
|
||||
end
|
||||
return minetest.get_meta(pos):get_string("doors_owner") == digger_name
|
||||
replace_old_owner_information(pos)
|
||||
return default.can_interact_with_node(digger, pos)
|
||||
end
|
||||
|
||||
function doors.register(name, def)
|
||||
@ -330,7 +318,7 @@ function doors.register(name, def)
|
||||
meta:set_int("state", state)
|
||||
|
||||
if def.protected then
|
||||
meta:set_string("doors_owner", pn)
|
||||
meta:set_string("owner", pn)
|
||||
meta:set_string("infotext", "Owned by " .. pn)
|
||||
end
|
||||
|
||||
@ -394,8 +382,9 @@ function doors.register(name, def)
|
||||
door:toggle(player)
|
||||
end
|
||||
def.on_skeleton_key_use = function(pos, player, newsecret)
|
||||
replace_old_owner_information(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()
|
||||
|
||||
-- verify placer is owner of lockable door
|
||||
@ -532,30 +521,13 @@ end
|
||||
|
||||
function _doors.trapdoor_toggle(pos, node, clicker)
|
||||
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
|
||||
key_meta:set_string("secret", minetest.parse_json(item:get_metadata()).secret)
|
||||
end
|
||||
replace_old_owner_information(pos)
|
||||
|
||||
if secret ~= key_meta:get_string("secret") then
|
||||
if not default.can_interact_with_node(clicker, pos) then
|
||||
return false
|
||||
end
|
||||
|
||||
elseif owner ~= "" then
|
||||
if clicker:get_player_name() ~= owner then
|
||||
return false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local def = minetest.registered_nodes[node.name]
|
||||
|
||||
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)
|
||||
local pn = placer:get_player_name()
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("doors_owner", pn)
|
||||
meta:set_string("owner", pn)
|
||||
meta:set_string("infotext", "Owned by "..pn)
|
||||
|
||||
return minetest.setting_getbool("creative_mode")
|
||||
@ -607,8 +579,9 @@ function doors.register_trapdoor(name, def)
|
||||
door:toggle(player)
|
||||
end
|
||||
def.on_skeleton_key_use = function(pos, player, newsecret)
|
||||
replace_old_owner_information(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()
|
||||
|
||||
-- verify placer is owner of lockable door
|
||||
|
Loading…
Reference in New Issue
Block a user