Skip to content

Commit

Permalink
Keys: Update default.can_interact_with_node to new item meta
Browse files Browse the repository at this point in the history
Completes a forgotten update in 9d3a526
  • Loading branch information
SmallJoker authored and sofar committed Mar 12, 2017
1 parent 07a5fca commit b87ef5c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
24 changes: 13 additions & 11 deletions mods/default/functions.lua
Expand Up @@ -551,21 +551,23 @@ function default.can_interact_with_node(player, pos)

local meta = minetest.get_meta(pos)

if player:get_player_name() == meta:get_string("owner") then
-- Owner can access the node to any time
return true
end

-- is player wielding the right key?
local item = player:get_wielded_item()
if item:get_name() == "default:key" then
local key_meta = minetest.parse_json(item:get_metadata())
local secret = meta:get_string("key_lock_secret")
if secret ~= key_meta.secret then
return false
end
local key_meta = item:get_meta()

return true
end
if key_meta:get_string("secret") == "" then
key_meta:set_string("secret", minetest.parse_json(item:get_metadata()).secret)
item:set_metadata("")
end

if player:get_player_name() ~= meta:get_string("owner") then
return false
return meta:get_string("key_lock_secret") == key_meta:get_string("secret")
end

return true
end
return false
end
1 change: 1 addition & 0 deletions mods/default/nodes.lua
Expand Up @@ -1805,6 +1805,7 @@ minetest.register_node("default:chest_locked", {
if key_meta:get_string("secret") == "" then
key_meta:set_string("secret", minetest.parse_json(itemstack:get_metadata()).secret)
itemstack:set_metadata("")
end
if secret ~= key_meta:get_string("secret") then
Expand Down
1 change: 1 addition & 0 deletions mods/doors/init.lua
Expand Up @@ -149,6 +149,7 @@ function _doors.door_toggle(pos, node, clicker)

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
Expand Down

5 comments on commit b87ef5c

@Thomas--S
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that parts of this were included in #1580

@SmallJoker
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry, I didn't notice that you had the same fix in your doors pull. However, this here is just a quick fix, thus rebasing shouldn't be much a problem for #1580.

@Thomas--S
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's ok. I hope #1580 will be merged soon, as I don't want to rebase it a third time 😉

@Fixer-007
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget about steel trapdoor!

@Thomas--S
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Fixer-007 Steel doors will use the default.can_interact_with_node() function after #1580 gets merged.

Please sign in to comment.