Skip to content


Skeleton key: Change to use left-click (tool on_use)
Browse files Browse the repository at this point in the history
Instead of right click, the skeleton key is now a true `tool`
in the sense that it's default left-click action is to create
a key for the locked object.

This is far better than the outcome of the patches we've done
where the only way to create a key for a locked item was to
use sneak+rightclick. Now keys are perhaps a bit more sensible,
left for making keys, right for opening stuff with keys.

Fixes #1625
  • Loading branch information
sofar authored and paramat committed Mar 15, 2017
1 parent 780f991 commit 61d7c43
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions mods/default/tools.lua
Original file line number Diff line number Diff line change
Expand Up @@ -383,22 +383,13 @@ minetest.register_tool("default:skeleton_key", {
description = "Skeleton Key",
inventory_image = "default_key_skeleton.png",
groups = {key = 1},
on_place = function(itemstack, placer, pointed_thing)
local under = pointed_thing.under
local node = minetest.get_node(under)
local def = minetest.registered_nodes[]
if def and def.on_rightclick and
not (placer and placer:get_player_control().sneak) then
return def.on_rightclick(under, node, placer, itemstack,
pointed_thing) or itemstack

on_use = function(itemstack, user, pointed_thing)
if pointed_thing.type ~= "node" then
return itemstack

local pos = pointed_thing.under
node = minetest.get_node(pos)
local node = minetest.get_node(pos)

if not node then
return itemstack
Expand All @@ -413,15 +404,15 @@ minetest.register_tool("default:skeleton_key", {
random(2^16) - 1, random(2^16) - 1,
random(2^16) - 1, random(2^16) - 1)

local secret, _, _ = on_skeleton_key_use(pos, placer, newsecret)
local secret, _, _ = on_skeleton_key_use(pos, user, newsecret)

if secret then
-- finish and return the new key
local meta = itemstack:get_meta()
meta:set_string("secret", secret)
meta:set_string("description", "Key to "..placer:get_player_name().."'s "
meta:set_string("description", "Key to "..user:get_player_name().."'s "
return itemstack
Expand Down

0 comments on commit 61d7c43

Please sign in to comment.