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_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,28 +148,10 @@ 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)
|
return false
|
||||||
item:set_metadata("")
|
|
||||||
end
|
|
||||||
|
|
||||||
if secret ~= key_meta:get_string("secret") then
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
elseif owner ~= "" then
|
|
||||||
if clicker:get_player_name() ~= owner then
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- until Lua-5.2 we have no bitwise operators :(
|
-- until Lua-5.2 we have no bitwise operators :(
|
||||||
@ -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,28 +521,11 @@ 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
|
|
||||||
|
|
||||||
elseif owner ~= "" then
|
|
||||||
if clicker:get_player_name() ~= owner then
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local def = minetest.registered_nodes[node.name]
|
local def = minetest.registered_nodes[node.name]
|
||||||
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user