Maciej Kasatkin
2012-09-02 d455791cfb2d93e3625c1db103f069fa11c3d566
commit | author | age
167434 1 minetest.register_craft({
MK 2     output = 'technic:iron_chest 1',
3     recipe = {
4         {'default:steel_ingot','default:steel_ingot','default:steel_ingot'},
5         {'default:steel_ingot','default:chest','default:steel_ingot'},
6         {'default:steel_ingot','default:steel_ingot','default:steel_ingot'},
7     }
8 })
9 minetest.register_craft({
10     output = 'technic:iron_locked_chest 1',
11     recipe = {
12         {'default:steel_ingot'},
13         {'technic:iron_chest'},
14     }
15 })
16
17
18 minetest.register_craftitem("technic:iron_chest", {
19     description = "Iron Chest",
20     stack_max = 99,
21 })
22 minetest.register_craftitem("technic:iron_locked_chest", {
23     description = "Iron Locked Chest",
24     stack_max = 99,
25 })
26
27 minetest.register_node("technic:iron_chest", {
28     description = "Iron Chest",
29     tiles = {"technic_iron_chest_top.png", "technic_iron_chest_top.png", "technic_iron_chest_side.png",
30         "technic_iron_chest_side.png", "technic_iron_chest_side.png", "technic_iron_chest_front.png"},
31     paramtype2 = "facedir",
32     groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
33     legacy_facedir_simple = true,
34     sounds = default.node_sound_wood_defaults(),
35     on_construct = function(pos)
36         local meta = minetest.env:get_meta(pos)
37         meta:set_string("formspec",
38                 "invsize[9,9;]"..
39                 "list[current_name;main;0,0;9,4;]"..
40                 "list[current_player;main;0,5;8,4;]")
41         meta:set_string("infotext", "Iron Chest")
42         local inv = meta:get_inventory()
43         inv:set_size("main", 9*4)
44     end,
45     can_dig = function(pos,player)
46         local meta = minetest.env:get_meta(pos);
47         local inv = meta:get_inventory()
48         return inv:is_empty("main")
49     end,
50     on_metadata_inventory_move = function(pos, from_list, from_index,
51             to_list, to_index, count, player)
52         minetest.log("action", player:get_player_name()..
53                 " moves stuff in chest at "..minetest.pos_to_string(pos))
54         return minetest.node_metadata_inventory_move_allow_all(
55                 pos, from_list, from_index, to_list, to_index, count, player)
56     end,
57     on_metadata_inventory_offer = function(pos, listname, index, stack, player)
58         minetest.log("action", player:get_player_name()..
59                 " moves stuff to chest at "..minetest.pos_to_string(pos))
60         return minetest.node_metadata_inventory_offer_allow_all(
61                 pos, listname, index, stack, player)
62     end,
63       on_metadata_inventory_take = function(pos, listname, index, stack, player)
64         minetest.log("action", player:get_player_name()..
65                 " takes stuff from chest at "..minetest.pos_to_string(pos))
66     end,
67 })
68
69 local function has_locked_chest_privilege(meta, player)
70     if player:get_player_name() ~= meta:get_string("owner") then
71         return false
72     end
73     return true
74 end
75
76 minetest.register_node("technic:iron_locked_chest", {
77     description = "Iron Locked Chest",
78     tiles = {"technic_iron_chest_top.png", "technic_iron_chest_top.png", "technic_iron_chest_side.png",
79         "technic_iron_chest_side.png", "technic_iron_chest_side.png", "technic_iron_chest_locked.png"},
80     paramtype2 = "facedir",
81     groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
82     legacy_facedir_simple = true,
83     sounds = default.node_sound_wood_defaults(),
84     after_place_node = function(pos, placer)
85         local meta = minetest.env:get_meta(pos)
86         meta:set_string("owner", placer:get_player_name() or "")
87         meta:set_string("infotext", "Locked Iron Chest (owned by "..
88                 meta:get_string("owner")..")")
89     end,
90 on_construct = function(pos)
91         local meta = minetest.env:get_meta(pos)
92         meta:set_string("formspec",
93                 "invsize[9,9;]"..
94                 "list[current_name;main;0,0;9,4;]"..
95                 "list[current_player;main;0,5;8,4;]")
96         meta:set_string("infotext", "Iron Locked Chest")
97         meta:set_string("owner", "")
98         local inv = meta:get_inventory()
99         inv:set_size("main", 9*4)
100     end,
101     can_dig = function(pos,player)
102         local meta = minetest.env:get_meta(pos);
103         local inv = meta:get_inventory()
104         return inv:is_empty("main")
105     end,
106     allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
107         local meta = minetest.env:get_meta(pos)
108         if not has_locked_chest_privilege(meta, player) then
109             minetest.log("action", player:get_player_name()..
110                     " tried to access a locked chest belonging to "..
111                     meta:get_string("owner").." at "..
112                     minetest.pos_to_string(pos))
113             return 0
114         end
115         return count
116     end,
117     allow_metadata_inventory_put = function(pos, listname, index, stack, player)
118         local meta = minetest.env:get_meta(pos)
119         if not has_locked_chest_privilege(meta, player) then
120             minetest.log("action", player:get_player_name()..
121                     " tried to access a locked chest belonging to "..
122                     meta:get_string("owner").." at "..
123                     minetest.pos_to_string(pos))
124             return 0
125         end
126         return stack:get_count()
127     end,
128     allow_metadata_inventory_take = function(pos, listname, index, stack, player)
129         local meta = minetest.env:get_meta(pos)
130         if not has_locked_chest_privilege(meta, player) then
131             minetest.log("action", player:get_player_name()..
132                     " tried to access a locked chest belonging to "..
133                     meta:get_string("owner").." at "..
134                     minetest.pos_to_string(pos))
135             return 0
136         end
137         return stack:get_count()
138     end,
139     on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
140         minetest.log("action", player:get_player_name()..
141                 " moves stuff in locked chest at "..minetest.pos_to_string(pos))
142     end,
143     on_metadata_inventory_put = function(pos, listname, index, stack, player)
144         minetest.log("action", player:get_player_name()..
145                 " moves stuff to locked chest at "..minetest.pos_to_string(pos))
146     end,
147     on_metadata_inventory_take = function(pos, listname, index, stack, player)
148         minetest.log("action", player:get_player_name()..
149                 " takes stuff from locked chest at "..minetest.pos_to_string(pos))
150     end,
151 })