Keys: Move skeleton key to craftitems.lua
authoroctacian <enduffy2014@outlook.com>
Thu, 16 Mar 2017 05:22:09 +0000 (22:22 -0700)
committerparamat <mat.gregory@virginmedia.com>
Thu, 20 Apr 2017 18:51:51 +0000 (19:51 +0100)
Commit 73d61cbb103415c9a3970eaf2c48aeadabfff828 makes skeleton keys
craftitems rather than tools, warranting the move from tools.lua
to craftitems.lua.

mods/default/craftitems.lua
mods/default/tools.lua

index aa8f56bda616a7ea92f8f1659398278a0533875e..a0db65548fc51f059f4add673604071d93635904 100644 (file)
@@ -186,6 +186,62 @@ minetest.register_on_craft(function(itemstack, player, old_craft_grid, craft_inv
        craft_inv:set_stack("craft", index, original)
 end)
 
+minetest.register_craftitem("default:skeleton_key", {
+       description = "Skeleton Key",
+       inventory_image = "default_key_skeleton.png",
+       groups = {key = 1},
+       on_use = function(itemstack, user, pointed_thing)
+               if pointed_thing.type ~= "node" then
+                       return itemstack
+               end
+
+               local pos = pointed_thing.under
+               local node = minetest.get_node(pos)
+
+               if not node then
+                       return itemstack
+               end
+
+               local on_skeleton_key_use = minetest.registered_nodes[node.name].on_skeleton_key_use
+               if not on_skeleton_key_use then
+                       return itemstack
+               end
+
+               -- make a new key secret in case the node callback needs it
+               local random = math.random
+               local newsecret = string.format(
+                       "%04x%04x%04x%04x",
+                       random(2^16) - 1, random(2^16) - 1,
+                       random(2^16) - 1, random(2^16) - 1)
+
+               local secret, _, _ = on_skeleton_key_use(pos, user, newsecret)
+
+               if secret then
+                       local inv = minetest.get_inventory({type="player", name=user:get_player_name()})
+
+                       -- update original itemstack
+                       itemstack:take_item()
+
+                       -- finish and return the new key
+                       local new_stack = ItemStack("default:key")
+                       local meta = new_stack:get_meta()
+                       meta:set_string("secret", secret)
+                       meta:set_string("description", "Key to "..user:get_player_name().."'s "
+                               ..minetest.registered_nodes[node.name].description)
+
+                       if itemstack:get_count() == 0 then
+                               itemstack = new_stack
+                       else
+                               if inv:add_item("main", new_stack):get_count() > 0 then
+                                       minetest.add_item(user:getpos(), new_stack)
+                               end -- else: added to inventory successfully
+                       end
+
+                       return itemstack
+               end
+       end
+})
+
 minetest.register_craftitem("default:coal_lump", {
        description = "Coal Lump",
        inventory_image = "default_coal_lump.png",
index f105a8fb92b3fdde03de71849cd6c0d7982b4d23..45c779f1ca118a163b6aac7baff351a401ff8519 100644 (file)
@@ -379,60 +379,6 @@ minetest.register_tool("default:sword_diamond", {
        sound = {breaks = "default_tool_breaks"},
 })
 
-minetest.register_craftitem("default:skeleton_key", {
-       description = "Skeleton Key",
-       inventory_image = "default_key_skeleton.png",
-       groups = {key = 1},
-       on_use = function(itemstack, user, pointed_thing)
-               if pointed_thing.type ~= "node" then
-                       return itemstack
-               end
-
-               local pos = pointed_thing.under
-               local node = minetest.get_node(pos)
-
-               if not node then
-                       return itemstack
-               end
-
-               local on_skeleton_key_use = minetest.registered_nodes[node.name].on_skeleton_key_use
-               if on_skeleton_key_use then
-                       -- make a new key secret in case the node callback needs it
-                       local random = math.random
-                       local newsecret = string.format(
-                               "%04x%04x%04x%04x",
-                               random(2^16) - 1, random(2^16) - 1,
-                               random(2^16) - 1, random(2^16) - 1)
-
-                       local secret, _, _ = on_skeleton_key_use(pos, user, newsecret)
-
-                       if secret then
-                               -- update original itemstack
-                               itemstack:take_item()
-
-                               -- finish and return the new key
-                               local new_stack = ItemStack("default:key")
-                               local meta = new_stack:get_meta()
-                               local inv = minetest.get_inventory({type="player", name=user:get_player_name()})
-                               meta:set_string("secret", secret)
-                               meta:set_string("description", "Key to "..user:get_player_name().."'s "
-                                       ..minetest.registered_nodes[node.name].description)
-
-                               if itemstack:get_count() == 0 then
-                                       itemstack = new_stack
-                               else
-                                       if inv:add_item("main", new_stack):get_count() > 0 then
-                                               minetest.add_item(user:getpos(), new_stack)
-                                       end
-                               end
-
-                               return itemstack
-                       end
-               end
-               return nil
-       end
-})
-
 minetest.register_tool("default:key", {
        description = "Key",
        inventory_image = "default_key.png",