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