Skip to content
Permalink
Browse files

Keys: Show owner in description

Utilizes several new features allowing the description of an item to be changed using the `description` meta key. This also moves keys from using the old single-value itemstack metadata system to the new node-like metadata system.
  • Loading branch information...
octacian authored and sofar committed Feb 26, 2017
1 parent bb18eec commit 9d3a5263244e7cd001a4ad9c2875c4068193392c
Showing with 24 additions and 9 deletions.
  1. +6 −2 mods/default/nodes.lua
  2. +4 −3 mods/default/tools.lua
  3. +14 −4 mods/doors/init.lua
@@ -1727,9 +1727,13 @@ minetest.register_node("default:chest_locked", {
on_key_use = function(pos, player)
local secret = minetest.get_meta(pos):get_string("key_lock_secret")
local itemstack = player:get_wielded_item()
local key_meta = minetest.parse_json(itemstack:get_metadata())
local key_meta = itemstack:get_meta()

if secret ~= key_meta.secret then
if key_meta:get_string("secret") == "" then
key_meta:set_string("secret", minetest.parse_json(itemstack:get_metadata()).secret)
end

if secret ~= key_meta:get_string("secret") then
return
end

@@ -410,9 +410,10 @@ minetest.register_tool("default:skeleton_key", {
-- finish and return the new key
itemstack:take_item()
itemstack:add_item("default:key")
itemstack:set_metadata(minetest.write_json({
secret = secret
}))
local meta = itemstack:get_meta()
meta:set_string("secret", secret)
meta:set_string("description", "Key to "..placer:get_player_name().."'s "
..minetest.registered_nodes[node.name].description)
return itemstack
end
end
@@ -144,9 +144,14 @@ function _doors.door_toggle(pos, node, clicker)
local item = clicker:get_wielded_item()
local owner = meta:get_string("doors_owner")
if item:get_name() == "default:key" then
local key_meta = minetest.parse_json(item:get_metadata())
local key_meta = item:get_meta()
local secret = meta:get_string("key_lock_secret")
if secret ~= key_meta.secret then

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

if secret ~= key_meta:get_string("secret") then
return false
end

@@ -532,9 +537,14 @@ function _doors.trapdoor_toggle(pos, node, clicker)
local meta = minetest.get_meta(pos)
local owner = meta:get_string("doors_owner")
if item:get_name() == "default:key" then
local key_meta = minetest.parse_json(item:get_metadata())
local key_meta = item:get_meta()
local secret = meta:get_string("key_lock_secret")
if secret ~= key_meta.secret then

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

if secret ~= key_meta:get_string("secret") then
return false
end

0 comments on commit 9d3a526

Please sign in to comment.
You can’t perform that action at this time.