RealBadAngel
2012-12-13 b8d77627a4d28c624e63423eef317dd09c68e533
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'},
d5a7ad 14         {'default:steel_ingot','default:chest_locked','default:steel_ingot'},
eabde4 15         {'default:steel_ingot','default:steel_ingot','default:steel_ingot'},
MK 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,
57     can_dig = function(pos,player)
58         local meta = minetest.env:get_meta(pos);
59         local inv = meta:get_inventory()
60         return inv:is_empty("main")
61     end,
62     on_metadata_inventory_move = function(pos, from_list, from_index,
63             to_list, to_index, count, player)
64         minetest.log("action", player:get_player_name()..
65                 " moves stuff in chest at "..minetest.pos_to_string(pos))
66         return minetest.node_metadata_inventory_move_allow_all(
67                 pos, from_list, from_index, to_list, to_index, count, player)
68     end,
69     on_metadata_inventory_offer = function(pos, listname, index, stack, player)
70         minetest.log("action", player:get_player_name()..
71                 " moves stuff to chest at "..minetest.pos_to_string(pos))
72         return minetest.node_metadata_inventory_offer_allow_all(
73                 pos, listname, index, stack, player)
74     end,
75       on_metadata_inventory_take = function(pos, listname, index, stack, player)
76         minetest.log("action", player:get_player_name()..
77                 " takes stuff from chest at "..minetest.pos_to_string(pos))
78     end,
79 })
80
81 local function has_locked_chest_privilege(meta, player)
82     if player:get_player_name() ~= meta:get_string("owner") then
83         return false
84     end
85     return true
86 end
87
88 minetest.register_node("technic:iron_locked_chest", {
89     description = "Iron Locked Chest",
90     tiles = {"technic_iron_chest_top.png", "technic_iron_chest_top.png", "technic_iron_chest_side.png",
91         "technic_iron_chest_side.png", "technic_iron_chest_side.png", "technic_iron_chest_locked.png"},
92     paramtype2 = "facedir",
93     groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
94     legacy_facedir_simple = true,
95     sounds = default.node_sound_wood_defaults(),
96     after_place_node = function(pos, placer)
97         local meta = minetest.env:get_meta(pos)
98         meta:set_string("owner", placer:get_player_name() or "")
99         meta:set_string("infotext", "Locked Iron Chest (owned by "..
100                 meta:get_string("owner")..")")
101     end,
102 on_construct = function(pos)
103         local meta = minetest.env:get_meta(pos)
104         meta:set_string("formspec",
105                 "invsize[9,9;]"..
106                 "list[current_name;main;0,0;9,4;]"..
107                 "list[current_player;main;0,5;8,4;]")
108         meta:set_string("infotext", "Iron Locked Chest")
109         meta:set_string("owner", "")
110         local inv = meta:get_inventory()
111         inv:set_size("main", 9*4)
112     end,
113     can_dig = function(pos,player)
114         local meta = minetest.env:get_meta(pos);
115         local inv = meta:get_inventory()
116         return inv:is_empty("main")
117     end,
118     allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
119         local meta = minetest.env:get_meta(pos)
120         if not has_locked_chest_privilege(meta, player) then
121             minetest.log("action", player:get_player_name()..
122                     " tried to access a locked chest belonging to "..
123                     meta:get_string("owner").." at "..
124                     minetest.pos_to_string(pos))
125             return 0
126         end
127         return count
128     end,
129     allow_metadata_inventory_put = function(pos, listname, index, stack, player)
130         local meta = minetest.env:get_meta(pos)
131         if not has_locked_chest_privilege(meta, player) then
132             minetest.log("action", player:get_player_name()..
133                     " tried to access a locked chest belonging to "..
134                     meta:get_string("owner").." at "..
135                     minetest.pos_to_string(pos))
136             return 0
137         end
138         return stack:get_count()
139     end,
140     allow_metadata_inventory_take = function(pos, listname, index, stack, player)
141         local meta = minetest.env:get_meta(pos)
142         if not has_locked_chest_privilege(meta, player) then
143             minetest.log("action", player:get_player_name()..
144                     " tried to access a locked chest belonging to "..
145                     meta:get_string("owner").." at "..
146                     minetest.pos_to_string(pos))
147             return 0
148         end
149         return stack:get_count()
150     end,
151     on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
152         minetest.log("action", player:get_player_name()..
153                 " moves stuff in locked chest at "..minetest.pos_to_string(pos))
154     end,
155     on_metadata_inventory_put = function(pos, listname, index, stack, player)
156         minetest.log("action", player:get_player_name()..
157                 " moves stuff to locked chest at "..minetest.pos_to_string(pos))
158     end,
159     on_metadata_inventory_take = function(pos, listname, index, stack, player)
160         minetest.log("action", player:get_player_name()..
161                 " takes stuff from locked chest at "..minetest.pos_to_string(pos))
162     end,
163 })