Handle rightclick on unlocked container.
parent
a11f49d2f4
commit
7eb839d325
|
@ -1,3 +1,65 @@
|
|||
-- Chest formspec
|
||||
local function get_chest_formspec(pos)
|
||||
local spos = pos.x .. "," .. pos.y .. "," ..pos.z
|
||||
local formspec =
|
||||
"size[8,9]"..
|
||||
default.gui_bg..
|
||||
default.gui_bg_img..
|
||||
default.gui_slots..
|
||||
"list[nodemeta:".. spos .. ";main;0,0.3;8,4;]"..
|
||||
"list[current_player;main;0,4.85;8,1;]"..
|
||||
"list[current_player;main;0,6.08;8,3;8]"..
|
||||
default.get_hotbar_bg(0,4.85)
|
||||
return formspec
|
||||
end
|
||||
|
||||
local function handle_unlocked_container(pos, node, clicker, wield_item)
|
||||
if wield_item:get_name() == "real_locks:lock" then
|
||||
-- Change unlocked container to locked,
|
||||
-- keeping all it's metadata (infotext, inventory etc.)
|
||||
node.name = node.name .. "_locked"
|
||||
minetest.swap_node(pos, node)
|
||||
|
||||
-- Changing brand new locked containter infotext
|
||||
-- back to it's normal value
|
||||
-- (not this one from unlocked container)
|
||||
minetest.registered_nodes[node.name].on_construct(pos)
|
||||
|
||||
-- Now set's the password (lock)
|
||||
minetest.get_meta(pos):set_string("lock_pass", wield_item:get_metadata())
|
||||
|
||||
-- And take used lock
|
||||
wield_item:take_item()
|
||||
else
|
||||
minetest.show_formspec(
|
||||
clicker:get_player_name(),
|
||||
node.name,
|
||||
get_chest_formspec(pos)
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
local function handle_locked_container(pos, node, clicker, wield_item)
|
||||
minetest.show_formspec(
|
||||
clicker:get_player_name(),
|
||||
node.name,
|
||||
get_chest_formspec(pos)
|
||||
)
|
||||
|
||||
if wield_item:get_name() == "real_locks:key" then
|
||||
-- TODO
|
||||
--node.name = node.name .. "_locked"
|
||||
--minetest.swap_node(pos, node)
|
||||
--minetest.get_meta(pos):set_string("lock_pass", wield_item:get_metadata())
|
||||
|
||||
--minetest.show_formspec(
|
||||
-- clicker:get_player_name(),
|
||||
-- node.name,
|
||||
-- get_chest_formspec(pos)
|
||||
--)
|
||||
end
|
||||
end
|
||||
|
||||
--{{{ Chest
|
||||
minetest.register_node("containers:chest", {
|
||||
description = "Chest",
|
||||
|
@ -11,22 +73,9 @@ minetest.register_node("containers:chest", {
|
|||
legacy_facedir_simple = true,
|
||||
is_ground_content = false,
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
|
||||
-- Chest formspec
|
||||
meta:set_string("formspec",
|
||||
"size[8,9]"..
|
||||
default.gui_bg..
|
||||
default.gui_bg_img..
|
||||
default.gui_slots..
|
||||
[[
|
||||
list[current_name;main;0,0.3;8,4;]
|
||||
list[current_player;main;0,4.85;8,1;]
|
||||
list[current_player;main;0,6.08;8,3;8]
|
||||
]]..
|
||||
default.get_hotbar_bg(0,4.85)
|
||||
)
|
||||
meta:set_string("infotext", "Chest")
|
||||
local inv = meta:get_inventory()
|
||||
inv:set_size("main", 8*4)
|
||||
|
@ -36,6 +85,7 @@ minetest.register_node("containers:chest", {
|
|||
local inv = meta:get_inventory()
|
||||
return inv:is_empty("main")
|
||||
end,
|
||||
--{{{ Logging
|
||||
on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
||||
minetest.log("action", player:get_player_name()..
|
||||
" moves stuff in chest at "..minetest.pos_to_string(pos))
|
||||
|
@ -48,6 +98,47 @@ minetest.register_node("containers:chest", {
|
|||
minetest.log("action", player:get_player_name()..
|
||||
" takes stuff from chest at "..minetest.pos_to_string(pos))
|
||||
end,
|
||||
--}}}
|
||||
on_rightclick = handle_unlocked_container,
|
||||
})
|
||||
|
||||
minetest.register_node("containers:chest_locked", {
|
||||
description = "Locked chest",
|
||||
tiles = {
|
||||
"default_chest_top.png", "default_chest_top.png",
|
||||
"default_chest_side.png", "default_chest_side.png",
|
||||
"default_chest_side.png", "default_chest_front.png"
|
||||
},
|
||||
paramtype2 = "facedir",
|
||||
groups = {choppy=2,oddly_breakable_by_hand=2},
|
||||
legacy_facedir_simple = true,
|
||||
is_ground_content = false,
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("infotext", "Locked chest")
|
||||
end,
|
||||
can_dig = function(pos,player)
|
||||
local meta = minetest.get_meta(pos);
|
||||
local inv = meta:get_inventory()
|
||||
return inv:is_empty("main")
|
||||
end,
|
||||
--{{{ Logging
|
||||
on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
||||
minetest.log("action", player:get_player_name()..
|
||||
" moves stuff in chest at "..minetest.pos_to_string(pos))
|
||||
end,
|
||||
on_metadata_inventory_put = function(pos, listname, index, stack, player)
|
||||
minetest.log("action", player:get_player_name()..
|
||||
" moves stuff to chest at "..minetest.pos_to_string(pos))
|
||||
end,
|
||||
on_metadata_inventory_take = function(pos, listname, index, stack, player)
|
||||
minetest.log("action", player:get_player_name()..
|
||||
" takes stuff from chest at "..minetest.pos_to_string(pos))
|
||||
end,
|
||||
--}}}
|
||||
on_rightclick = handle_locked_container,
|
||||
})
|
||||
--}}}
|
||||
|
||||
|
|
Loading…
Reference in New Issue