Keys: Show owner in description
authoroctacian <enduffy2014@outlook.com>
Sun, 26 Feb 2017 17:24:12 +0000 (09:24 -0800)
committerAuke Kok <sofar+github@foo-projects.org>
Tue, 28 Feb 2017 03:00:14 +0000 (19:00 -0800)
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.

mods/default/nodes.lua
mods/default/tools.lua
mods/doors/init.lua

index 3d74b772e03b0903dc7b47bfdc47ddf6a10f3d8f..9db0455993022861826105f68cfa50464f9d228a 100644 (file)
@@ -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
 
index 9147f9b36d639c74992bc1688a6d8c26dba5aa2b..c7ea161951f35cf6d88a1f9ea040379c8d42d7a2 100644 (file)
@@ -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
index 61d48c1dfb2fcd02826e7593d375be8c9dd45a92..53e27938c50456a2f4cbdee22b92dbb00985e3bb 100644 (file)
@@ -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