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