3 By AndromedaKerova (AKA; RommieKerova, Rommie, Andromeda) (rommiekerova@gmail.com)
5 Version: 1.2 - is a reduced version only with colored chests.. code deleted by Glunggi :D
8 local chest_formspec
= default
.chest_formspec
9 local get_locked_chest_formspec
= default
.get_locked_chest_formspec
11 local function has_locked_chest_privilege(meta
, player
)
12 if player
:get_player_name() ~= meta
:get_string("owner") then
19 { "white", "White Chest", "White Locked Chest" },
20 { "grey", "Grey Chest", "Grey Locked Chest" },
21 { "dark_grey", "Dark Grey Chest", "Dark Grey Locked Chest" },
22 { "black", "Black Chest", "Black Locked Chest" },
23 { "blue", "Blue Chest", "Blue Locked Chest" },
24 { "cyan", "Cyan Chest", "Cyan Locked Chest" },
25 { "dark_green", "Dark Green Chest", "Dark Green Locked Chest" },
26 { "green", "Green Chest", "Green Locked Chest" },
27 { "magenta", "Magenta Chest", "Magenta Locked Chest" },
28 { "orange", "Orange Chest", "Orange Locked Chest" },
29 { "pink", "Pink Chest", "Pink Locked Chest" },
30 { "red", "Red Chest", "Red Locked Chest" },
31 { "violet", "Violet Chest", "Violet Locked Chest" },
32 { "yellow", "Yellow Chest", "Yellow Locked Chest" },
38 local sub
= chests
[c
][1]
39 local desc_unlocked
= chests
[c
][2]
40 local desc_locked
= chests
[c
][3]
42 minetest
.register_node("kerova:chest_"..sub
, {
43 description
= desc_unlocked
,
44 tiles
= {"kerova_chest_top_"..sub
..".png", "kerova_chest_top_"..sub
..".png", "kerova_chest_"..sub
..".png",
45 "kerova_chest_"..sub
..".png", "kerova_chest_"..sub
..".png", "kerova_chest_front_"..sub
..".png"},
46 paramtype2
= "facedir",
47 groups
= {choppy
=2,oddly_breakable_by_hand
=2, chest
=1},
48 legacy_facedir_simple
= true,
49 sounds
= default
.node_sound_wood_defaults(),
50 on_construct
= function(pos
)
51 local meta
= minetest
.get_meta(pos
)
52 meta
:set_string("formspec", chest_formspec
)
53 meta
:set_string("infotext", desc_unlocked
)
54 local inv
= meta
:get_inventory()
55 inv
:set_size("main", 8*4)
57 can_dig
= function(pos
,player
)
58 local meta
= minetest
.get_meta(pos
);
59 local inv
= meta
:get_inventory()
60 return inv
:is_empty("main")
62 on_metadata_inventory_move
= function(pos
, from_list
, from_index
, to_list
, to_index
, count
, player
)
63 minetest
.log("action", player
:get_player_name()..
64 " moves stuff in chest at "..minetest
.pos_to_string(pos
))
66 on_metadata_inventory_put
= function(pos
, listname
, index
, stack
, player
)
67 minetest
.log("action", player
:get_player_name()..
68 " moves stuff to chest at "..minetest
.pos_to_string(pos
))
70 on_metadata_inventory_take
= function(pos
, listname
, index
, stack
, player
)
71 minetest
.log("action", player
:get_player_name()..
72 " takes stuff from chest at "..minetest
.pos_to_string(pos
))
75 minetest
.register_node("kerova:chest_"..sub
.."_locked", {
76 description
= desc_locked
,
77 tiles
= {"kerova_chest_top_"..sub
..".png", "kerova_chest_top_"..sub
..".png", "kerova_chest_"..sub
..".png",
78 "kerova_chest_"..sub
..".png", "kerova_chest_"..sub
..".png", "kerova_chest_lock_"..sub
..".png"},
79 paramtype2
= "facedir",
80 groups
= {choppy
=2,oddly_breakable_by_hand
=2, locked_chest
=1},
81 legacy_facedir_simple
= true,
82 is_ground_content
= false,
83 sounds
= default
.node_sound_wood_defaults(),
85 after_place_node
= function(pos
, placer
)
86 local meta
= minetest
.get_meta(pos
)
87 meta
:set_string("owner", placer
:get_player_name() or "")
88 meta
:set_string("infotext", desc_locked
.." (owned by "..
89 meta
:get_string("owner")..")")
91 on_construct
= function(pos
)
92 local meta
= minetest
.get_meta(pos
)
93 meta
:set_string("infotext", desc_locked
)
94 meta
:set_string("owner", "")
95 local inv
= meta
:get_inventory()
96 inv
:set_size("main", 8*4)
98 can_dig
= function(pos
,player
)
99 local meta
= minetest
.get_meta(pos
);
100 local inv
= meta
:get_inventory()
101 return inv
:is_empty("main") and has_locked_chest_privilege(meta
, player
)
103 allow_metadata_inventory_move
= function(pos
, from_list
, from_index
, to_list
, to_index
, count
, player
)
104 local meta
= minetest
.get_meta(pos
)
105 if not has_locked_chest_privilege(meta
, player
) then
110 allow_metadata_inventory_put
= function(pos
, listname
, index
, stack
, player
)
111 local meta
= minetest
.get_meta(pos
)
112 if not has_locked_chest_privilege(meta
, player
) then
115 return stack
:get_count()
117 allow_metadata_inventory_take
= function(pos
, listname
, index
, stack
, player
)
118 local meta
= minetest
.get_meta(pos
)
119 if not has_locked_chest_privilege(meta
, player
) then
122 return stack
:get_count()
124 on_metadata_inventory_put
= function(pos
, listname
, index
, stack
, player
)
125 minetest
.log("action", player
:get_player_name()..
126 " moves stuff to locked chest at "..minetest
.pos_to_string(pos
))
128 on_metadata_inventory_take
= function(pos
, listname
, index
, stack
, player
)
129 minetest
.log("action", player
:get_player_name()..
130 " takes stuff from locked chest at "..minetest
.pos_to_string(pos
))
132 on_rightclick
= function(pos
, node
, clicker
)
133 local meta
= minetest
.get_meta(pos
)
134 if has_locked_chest_privilege(meta
, clicker
) then
135 minetest
.show_formspec(
136 clicker
:get_player_name(),
137 "default:chest_locked",
138 get_locked_chest_formspec(pos
)
144 minetest
.register_craft({
145 output
= "kerova:chest_"..sub
,
151 minetest
.register_craft({
152 output
= "kerova:chest_"..sub
.."_locked",
155 {"group:locked_chest"},