ShadowNinja
2013-12-17 5cf765b2f19ef9bf443178e26787fe16233b3f4c
commit | author | age
82cba9 1
354ee6 2 local S = technic.getter
S 3
82cba9 4 minetest.register_craft({
R 5     type = "shapeless",
6     output = 'technic:constructor_mk1_off 1',
7     recipe = {'technic:nodebreaker_off', 'technic:deployer_off'},
8
9 })
10 minetest.register_craft({
11     type = "shapeless",
12     output = 'technic:constructor_mk2_off 1',
13     recipe = {'technic:constructor_mk1_off', 'technic:constructor_mk1_off'},
14
15 })
16
17 minetest.register_craft({
18     type = "shapeless",
19     output = 'technic:constructor_mk3_off 1',
20     recipe = {'technic:constructor_mk2_off', 'technic:constructor_mk2_off'},
21
22 })
23
5cf765 24 local function mk1_on(pos, node)
ee0765 25     local meta = minetest.get_meta(pos)
82cba9 26     local inv = meta:get_inventory()
R 27     local pos1={}
28     pos1.x=pos.x
29     pos1.y=pos.y
30     pos1.z=pos.z
31     if node.param2==3 then pos1.x=pos1.x+1 end
32     if node.param2==2 then pos1.z=pos1.z+1 end
33     if node.param2==1 then pos1.x=pos1.x-1 end
34     if node.param2==0 then pos1.z=pos1.z-1 end
35
36     if node.name == "technic:constructor_mk1_off" then
f3d8b4 37         technic.swap_node(pos,"technic:constructor_mk1_on")
82cba9 38         nodeupdate(pos)
ee0765 39         local node1=minetest.get_node(pos1)
82cba9 40         deploy_node (inv,"slot1",pos1,node1,node)
R 41     end
42 end
43
5cf765 44 local function mk1_off(pos, node)
82cba9 45     if node.name == "technic:constructor_mk1_on" then
f3d8b4 46         technic.swap_node(pos,"technic:constructor_mk1_off")
82cba9 47         nodeupdate(pos)
R 48     end
49 end
50
51
52 minetest.register_node("technic:constructor_mk1_off", {
354ee6 53     description = S("Constructor Mk%d"):format(1),
82cba9 54     tile_images = {"technic_constructor_mk1_top_off.png","technic_constructor_mk1_bottom_off.png","technic_constructor_mk1_side2_off.png","technic_constructor_mk1_side1_off.png",
R 55             "technic_constructor_back.png","technic_constructor_front_off.png"},
56     is_ground_content = true,
57     paramtype2 = "facedir",
58     groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2, mesecon_receptor_off = 1, mesecon_effector_off = 1, mesecon = 2},
59     mesecons= {effector={action_on=mk1_on}},
60     sounds = default.node_sound_stone_defaults(),
61     on_construct = function(pos)
ee0765 62     local meta = minetest.get_meta(pos)
82cba9 63     meta:set_string("formspec",
R 64                 "invsize[8,9;]"..
354ee6 65                 "label[0,0;"..S("Constructor Mk%d"):format(1).."]"..
82cba9 66                 "label[5,0;Slot 1]"..
R 67                 "list[current_name;slot1;6,0;1,1;]"..
68                 "list[current_player;main;0,5;8,4;]")
354ee6 69         meta:set_string("infotext", S("Constructor Mk%d"):format(1))
82cba9 70         local inv = meta:get_inventory()
R 71         inv:set_size("slot1", 1)
72     end,
73
74     can_dig = function(pos,player)
ee0765 75         local meta = minetest.get_meta(pos)
82cba9 76         local inv = meta:get_inventory()
R 77         return inv:is_empty("slot1")
78     end,    
0809dd 79     allow_metadata_inventory_put = technic.machine_inventory_put,
S 80     allow_metadata_inventory_take = technic.machine_inventory_take,
81     allow_metadata_inventory_move = technic.machine_inventory_move,
82cba9 82 })
R 83
84 minetest.register_node("technic:constructor_mk1_on", {
354ee6 85     description = S("Constructor Mk%d"):format(3),
82cba9 86     tile_images = {"technic_constructor_mk1_top_on.png","technic_constructor_mk1_bottom_on.png","technic_constructor_mk1_side2_on.png","technic_constructor_mk1_side1_on.png",
R 87             "technic_constructor_back.png","technic_constructor_front_on.png"},
88     paramtype2 = "facedir",
89     groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,mesecon = 2,not_in_creative_inventory=1},
90     mesecons= {effector={action_off=mk1_off}},
91     sounds = default.node_sound_stone_defaults(),
0809dd 92     allow_metadata_inventory_put = technic.machine_inventory_put,
S 93     allow_metadata_inventory_take = technic.machine_inventory_take,
94     allow_metadata_inventory_move = technic.machine_inventory_move,
82cba9 95 })
R 96
97
354ee6 98 --Constructor Mk2
82cba9 99
5cf765 100 local function mk2_on(pos, node)
ee0765 101     local meta = minetest.get_meta(pos)
82cba9 102     local inv = meta:get_inventory()
R 103     local pos1={}
104     local pos2={}
105     pos1.x=pos.x
106     pos1.y=pos.y
107     pos1.z=pos.z
108     pos2.x=pos.x
109     pos2.y=pos.y
110     pos2.z=pos.z
111     if node.param2==3 then pos1.x=pos1.x+1 pos2.x=pos2.x+2 end
112     if node.param2==2 then pos1.z=pos1.z+1 pos2.z=pos2.z+2 end
113     if node.param2==1 then pos1.x=pos1.x-1 pos2.x=pos2.x-2 end
114     if node.param2==0 then pos1.z=pos1.z-1 pos2.z=pos2.z-2 end
115
116     if node.name == "technic:constructor_mk2_off" then
f3d8b4 117         technic.swap_node(pos,"technic:constructor_mk2_on")
82cba9 118         nodeupdate(pos)
ee0765 119         local node1=minetest.get_node(pos1)
82cba9 120         deploy_node (inv,"slot1",pos1,node1,node)
ee0765 121         local node1=minetest.get_node(pos2)    
82cba9 122         deploy_node (inv,"slot2",pos2,node1,node)
R 123     end
124 end
125
5cf765 126 local function mk2_off(pos, node)
82cba9 127     if node.name == "technic:constructor_mk2_on" then
f3d8b4 128         technic.swap_node(pos,"technic:constructor_mk2_off")
82cba9 129         nodeupdate(pos)
R 130     end
131 end
132
133 minetest.register_node("technic:constructor_mk2_off", {
354ee6 134     description = S("Constructor Mk%d"):format(2),
82cba9 135     tile_images = {"technic_constructor_mk2_top_off.png","technic_constructor_mk2_bottom_off.png","technic_constructor_mk2_side2_off.png","technic_constructor_mk2_side1_off.png",
R 136             "technic_constructor_back.png","technic_constructor_front_off.png"},
137     is_ground_content = true,
138     paramtype2 = "facedir",
139     groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2, mesecon = 2},
140     mesecons= {effector={action_on=mk2_on}},
141     sounds = default.node_sound_stone_defaults(),
142     on_construct = function(pos)
ee0765 143     local meta = minetest.get_meta(pos)
82cba9 144     meta:set_string("formspec",
R 145                 "invsize[8,9;]"..
354ee6 146                 "label[0,0;"..S("Constructor Mk%d"):format(2).."]"..
82cba9 147                 "label[5,0;Slot 1]"..
R 148                 "list[current_name;slot1;6,0;1,1;]"..
149                 "label[5,1;Slot 2]"..
150                 "list[current_name;slot2;6,1;1,1;]"..
151                 "list[current_player;main;0,5;8,4;]")
354ee6 152         meta:set_string("infotext", S("Constructor Mk%d"):format(2))
82cba9 153         local inv = meta:get_inventory()
R 154         inv:set_size("slot1", 1)
155         inv:set_size("slot2", 1)
156     end,
157     can_dig = function(pos,player)
ee0765 158         local meta = minetest.get_meta(pos)
82cba9 159         local inv = meta:get_inventory()
R 160         if inv:is_empty("slot1")==false or inv:is_empty("slot2")==false then return false end
161         return true
0809dd 162     end,
S 163     allow_metadata_inventory_put = technic.machine_inventory_put,
164     allow_metadata_inventory_take = technic.machine_inventory_take,
165     allow_metadata_inventory_move = technic.machine_inventory_move,
82cba9 166 })
R 167
168 minetest.register_node("technic:constructor_mk2_on", {
354ee6 169     description = S("Constructor Mk%d"):format(2),
82cba9 170     tile_images = {"technic_constructor_mk2_top_on.png","technic_constructor_mk2_bottom_on.png","technic_constructor_mk2_side2_on.png","technic_constructor_mk2_side1_on.png",
R 171             "technic_constructor_back.png","technic_constructor_front_on.png"},
172     is_ground_content = true,
173     paramtype2 = "facedir",
174     groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2, mesecon = 2, not_in_creative_inventory=1},
0809dd 175     mesecons = {effector={action_off=mk2_off}},
82cba9 176     sounds = default.node_sound_stone_defaults(),
0809dd 177     allow_metadata_inventory_put = technic.machine_inventory_put,
S 178     allow_metadata_inventory_take = technic.machine_inventory_take,
179     allow_metadata_inventory_move = technic.machine_inventory_move,
82cba9 180 })
R 181
182
354ee6 183 -- Constructor Mk3
5cf765 184 local function mk3_on(pos, node)
ee0765 185     local meta = minetest.get_meta(pos)
82cba9 186     local inv = meta:get_inventory()
R 187     
188     local pos1={}
189     local pos2={}
190     local pos3={}
191     local pos4={}
192     
193     pos1.x=pos.x
194     pos1.y=pos.y
195     pos1.z=pos.z
196     
197     pos2.x=pos.x
198     pos2.y=pos.y
199     pos2.z=pos.z
200     
201     pos3.x=pos.x
202     pos3.y=pos.y
203     pos3.z=pos.z
204
205     pos4.x=pos.x
206     pos4.y=pos.y
207     pos4.z=pos.z
208
209     if node.param2==3 then pos1.x=pos1.x+1 pos2.x=pos2.x+2 pos3.x=pos3.x+3 pos4.x=pos4.x+4 end
210     if node.param2==2 then pos1.z=pos1.z+1 pos2.z=pos2.z+2 pos3.z=pos3.z+3 pos4.z=pos4.z+4 end
211     if node.param2==1 then pos1.x=pos1.x-1 pos2.x=pos2.x-2 pos3.x=pos3.x-3 pos4.x=pos4.x-4 end
212     if node.param2==0 then pos1.z=pos1.z-1 pos2.z=pos2.z-2 pos3.z=pos3.z-3 pos4.z=pos4.z-4 end
213
214     if node.name == "technic:constructor_mk3_off" then
f3d8b4 215         technic.swap_node(pos,"technic:constructor_mk3_on")
82cba9 216         nodeupdate(pos)
ee0765 217         local node1=minetest.get_node(pos1)
82cba9 218         deploy_node (inv,"slot1",pos1,node1,node)
ee0765 219         local node1=minetest.get_node(pos2)    
82cba9 220         deploy_node (inv,"slot2",pos2,node1,node)
ee0765 221         local node1=minetest.get_node(pos3)    
82cba9 222         deploy_node (inv,"slot3",pos3,node1,node)
ee0765 223         local node1=minetest.get_node(pos4)    
82cba9 224         deploy_node (inv,"slot4",pos4,node1,node)
R 225     end
226 end
227
5cf765 228 local function mk3_off(pos, node)
82cba9 229     if node.name == "technic:constructor_mk3_on" then
f3d8b4 230         technic.swap_node(pos,"technic:constructor_mk3_off")
82cba9 231         nodeupdate(pos)
R 232     end
233 end
234
235 minetest.register_node("technic:constructor_mk3_off", {
354ee6 236     description = S("Constructor Mk%d"):format(3),
82cba9 237     tile_images = {"technic_constructor_mk3_top_off.png","technic_constructor_mk3_bottom_off.png","technic_constructor_mk3_side2_off.png","technic_constructor_mk3_side1_off.png",
R 238             "technic_constructor_back.png","technic_constructor_front_off.png"},
239     paramtype2 = "facedir",
240     groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2, mesecon = 2},
0809dd 241     mesecons = {effector={action_on=mk3_on}},
82cba9 242     sounds = default.node_sound_stone_defaults(),
R 243     on_construct = function(pos)
ee0765 244     local meta = minetest.get_meta(pos)
82cba9 245     meta:set_string("formspec",
R 246                 "invsize[8,9;]"..
354ee6 247                 "label[0,0;"..S("Constructor Mk%d"):format(3).."]"..
82cba9 248                 "label[5,0;Slot 1]"..
R 249                 "list[current_name;slot1;6,0;1,1;]"..
250                 "label[5,1;Slot 2]"..
251                 "list[current_name;slot2;6,1;1,1;]"..
252                 "label[5,2;Slot 3]"..
253                 "list[current_name;slot3;6,2;1,1;]"..
254                 "label[5,3;Slot 4]"..
255                 "list[current_name;slot4;6,3;1,1;]"..
256                 "list[current_player;main;0,5;8,4;]")
354ee6 257         meta:set_string("infotext", S("Constructor Mk%d"):format(3))
82cba9 258         local inv = meta:get_inventory()
R 259         inv:set_size("slot1", 1)
260         inv:set_size("slot2", 1)
261         inv:set_size("slot3", 1)
262         inv:set_size("slot4", 1)
263
264     end,
265
266     can_dig = function(pos,player)
ee0765 267         local meta = minetest.get_meta(pos)
82cba9 268         local inv = meta:get_inventory()
R 269         if inv:is_empty("slot1")==false or inv:is_empty("slot2")==false or inv:is_empty("slot3")==false or inv:is_empty("slot4")==false then return false end
270         return true
271     end,    
0809dd 272     allow_metadata_inventory_put = technic.machine_inventory_put,
S 273     allow_metadata_inventory_take = technic.machine_inventory_take,
274     allow_metadata_inventory_move = technic.machine_inventory_move,
82cba9 275 })
R 276
277 minetest.register_node("technic:constructor_mk3_on", {
354ee6 278     description = S("Constructor Mk%d"):format(3),
82cba9 279     tile_images = {"technic_constructor_mk3_top_on.png","technic_constructor_mk3_bottom_on.png","technic_constructor_mk3_side2_on.png","technic_constructor_mk3_side1_on.png",
R 280             "technic_constructor_back.png","technic_constructor_front_on.png"},
281     is_ground_content = true,
282     paramtype2 = "facedir",
283     groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2, mesecon = 2,not_in_creative_inventory=1},
0809dd 284     mesecons = {effector={action_off=mk3_off}},
82cba9 285     sounds = default.node_sound_stone_defaults(),
0809dd 286     allow_metadata_inventory_put = technic.machine_inventory_put,
S 287     allow_metadata_inventory_take = technic.machine_inventory_take,
288     allow_metadata_inventory_move = technic.machine_inventory_move,
82cba9 289 })
R 290
291
5cf765 292 local function deploy_node(inv, slot_name, pos1, node1, node)
a1da74 293     if node1.name == "air" then 
DM 294         if not inv:is_empty(slot_name) then
82cba9 295             stack1=inv:get_list(slot_name)
a1da74 296             local def = stack1[1]:get_definition()
DM 297             if def.type == "node" then
298                 node_to_be_placed={name=stack1[1]:get_name(), param1=0, param2=node.param2}
ee0765 299                 minetest.set_node(pos1,node_to_be_placed)
a1da74 300                 stack1[1]:take_item()
DM 301                 inv:set_stack(slot_name, 1, stack1[1])
302             elseif def.type == "craft" then
0039f3 303                 if def.on_place then
DM 304                     -- print("deploy_node: item has on_place. trying...")
305                     local ok, stk = pcall(def.on_place, stack1[1], nil, {
306                         -- Fake pointed_thing
307                         type = "node",
308                         above = pos1,
309                         under = { x=pos1.x, y=pos1.y-1, z=pos1.z },
310                     })
311                     if ok then
312                         -- print("deploy_node: on_place succeeded!")
313                         inv:set_stack(slot_name, 1, stk or stack1[1])
314                         return
315                     -- else
316                         -- print("deploy_node: WARNING: error while running on_place: "..tostring(stk))
317                     end
318                 end
a1da74 319                 minetest.item_place_object(stack1[1], nil, {
DM 320                     -- Fake pointed_thing
321                     type = "node",
322                     above = pos1,
323                     under = pos1,
324                 })
325                 inv:set_stack(slot_name, 1, nil)
82cba9 326             end
R 327         end
a1da74 328         return 
DM 329     end
330     if node1.name == "ignore" or
331        node1.name == "default:lava_source" or
332        node1.name == "default:lava_flowing" or
333        node1.name == "default:water_source" or
334        node1.name == "default:water_flowing" 
335        then return end
336     if inv:room_for_item(slot_name,node1) then
337         local def = minetest.registered_nodes[node1.name]
338         if not def then return end
339         local drop = def.drop or node1.name
340         if type(drop) == "table" then
341             local pr = PseudoRandom(math.random())
342             local c = 0
343             local loop = 0 -- Prevent infinite loop
344             while (c < (drop.max_items or 1)) and (loop < 1000) do
345                 local i = math.floor(pr:next(1, #drop.items))
346                 if pr:next(1, drop.items[i].rarity or 1) == 1 then
347                     for _,item in ipairs(drop.items[i].items) do
348                         inv:add_item(slot_name,item)
349                     end
350                     c = c + 1
351                 end
352                 loop = loop + 1
353             end
ee0765 354             minetest.remove_node(pos1)
a1da74 355         elseif type(drop) == "string" then
DM 356             inv:add_item(slot_name,drop)
ee0765 357             minetest.remove_node(pos1)
82cba9 358         end
a1da74 359     end
82cba9 360
R 361 end