Skip to content

Commit 701abc2

Browse files
octacianparamat
authored andcommittedApr 20, 2017
Keys: Allow skeleton keys to be stacked
Allow skeleton keys to be stacked by converting them to craftitems and adding a few lines of code to add a new itemstack to the inventory with the new key or drop it at the player position if the inventory is full.
1 parent 9821681 commit 701abc2

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed
 

‎mods/default/tools.lua

+16-4
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ minetest.register_tool("default:sword_diamond", {
379379
sound = {breaks = "default_tool_breaks"},
380380
})
381381

382-
minetest.register_tool("default:skeleton_key", {
382+
minetest.register_craftitem("default:skeleton_key", {
383383
description = "Skeleton Key",
384384
inventory_image = "default_key_skeleton.png",
385385
groups = {key = 1},
@@ -407,13 +407,25 @@ minetest.register_tool("default:skeleton_key", {
407407
local secret, _, _ = on_skeleton_key_use(pos, user, newsecret)
408408

409409
if secret then
410-
-- finish and return the new key
410+
-- update original itemstack
411411
itemstack:take_item()
412-
itemstack:add_item("default:key")
413-
local meta = itemstack:get_meta()
412+
413+
-- finish and return the new key
414+
local new_stack = ItemStack("default:key")
415+
local meta = new_stack:get_meta()
416+
local inv = minetest.get_inventory({type="player", name=user:get_player_name()})
414417
meta:set_string("secret", secret)
415418
meta:set_string("description", "Key to "..user:get_player_name().."'s "
416419
..minetest.registered_nodes[node.name].description)
420+
421+
if itemstack:get_count() == 0 then
422+
itemstack = new_stack
423+
else
424+
if inv:add_item("main", new_stack):get_count() > 0 then
425+
minetest.add_item(user:getpos(), new_stack)
426+
end
427+
end
428+
417429
return itemstack
418430
end
419431
end

0 commit comments

Comments
 (0)
Please sign in to comment.