RealBadAngel
2012-12-13 b8d77627a4d28c624e63423eef317dd09c68e533
commit | author | age
b8d776 1 -- List of devices that should participate in the autoplace algorithm
R 2
3 pipes_devicelist = {
4     "pump",
5     "valve",
6     "storage_tank_0",
7     "storage_tank_1",
8     "storage_tank_2",
9     "storage_tank_3",
10     "storage_tank_4",
11     "storage_tank_5",
12     "storage_tank_6",
13     "storage_tank_7",
14     "storage_tank_8",
15     "storage_tank_9",
16     "storage_tank_10"
17 }
18
19 -- tables
20
21 minetest.register_alias("pipeworks:pump", "pipeworks:pump_off_x")
22 minetest.register_alias("pipeworks:valve", "pipeworks:valve_off_x")
23 minetest.register_alias("pipeworks:storage_tank", "pipeworks:storage_tank_0_x")
24
25 pipe_pumpbody_x = {
26     { -6/16, -8/16, -6/16, 6/16, 8/16, 6/16 }
27 }
28
29 pipe_pumpbody_z = {
30     { -6/16, -8/16, -6/16, 6/16, 8/16, 6/16 }
31 }
32
33 pipe_valvebody_x = {
34     { -4/16, -4/16, -4/16, 4/16, 4/16, 4/16 }
35 }
36
37 pipe_valvebody_z = {
38     { -4/16, -4/16, -4/16, 4/16, 4/16, 4/16 }
39 }
40
41 pipe_valvehandle_on_x = {
42     { -5/16, 4/16, -1/16, 0, 5/16, 1/16 }
43 }
44
45 pipe_valvehandle_on_z = {
46     { -1/16, 4/16, -5/16, 1/16, 5/16, 0 }
47 }
48
49 pipe_valvehandle_off_x = {
50     { -1/16, 4/16, -5/16, 1/16, 5/16, 0 }
51 }
52
53 pipe_valvehandle_off_z = {
54     { -5/16, 4/16, -1/16, 0, 5/16, 1/16 }
55 }
56
57 -- Now define the nodes.
58
59 local states = { "on", "off" }
60 local dgroups = ""
61
62 for s in ipairs(states) do
63
64     if states[s] == "off" then
65         dgroups = {snappy=3, pipe=1}
66     else
67         dgroups = {snappy=3, pipe=1, not_in_creative_inventory=1}
68     end
69
70     local pumpboxes = {}
71     pipe_addbox(pumpboxes, pipe_leftstub)
72     pipe_addbox(pumpboxes, pipe_pumpbody_x)
73     pipe_addbox(pumpboxes, pipe_rightstub)
74     local tilex = "pipeworks_pump_ends.png"
75     local tilez = "pipeworks_pump_"..states[s]..".png"
76
77     minetest.register_node("pipeworks:pump_"..states[s].."_x", {
78         description = "Pump Module ("..states[s]..")",
79         drawtype = "nodebox",
80         tiles = {
81             "pipeworks_pump_top_x.png",
82             "pipeworks_pump_sides.png",
83             tilex,
84             tilex,
85             "pipeworks_pump_sides.png",
86             tilez
87         },
88         paramtype = "light",
89         selection_box = {
90                      type = "fixed",
91             fixed = { -0.5, -0.5, -0.5, 0.5, 0.5, 0.5 }
92         },
93         node_box = {
94             type = "fixed",
95             fixed = pumpboxes
96         },
97         groups = dgroups,
98         sounds = default.node_sound_wood_defaults(),
99         walkable = true,
100         stack_max = 99,
101         after_place_node = function(pos)
102             pipe_device_autorotate(pos, states[s], "pipeworks:pump")
103             pipe_scanforobjects(pos)
104         end,
105         after_dig_node = function(pos)
106             pipe_scanforobjects(pos)
107         end,
108         drop = "pipeworks:pump_off_x"
109     })
110     
111     local pumpboxes = {}
112     pipe_addbox(pumpboxes, pipe_frontstub)
113     pipe_addbox(pumpboxes, pipe_pumpbody_z)
114     pipe_addbox(pumpboxes, pipe_backstub)
115
116     minetest.register_node("pipeworks:pump_"..states[s].."_z", {
117         description = "Pump Module ("..states[s]..", Z-axis)",
118         drawtype = "nodebox",
119         tiles = {
120             "pipeworks_pump_top_z.png",
121             "pipeworks_pump_sides.png",
122             tilez,
123             tilez,
124             "pipeworks_pump_sides.png",
125             tilex
126         },
127         paramtype = "light",
128         selection_box = {
129                      type = "fixed",
130             fixed = { -0.5, -0.5, -0.5, 0.5, 0.5, 0.5 }
131         },
132         node_box = {
133             type = "fixed",
134             fixed = pumpboxes
135         },
136         groups = {snappy=3, pipe=1, not_in_creative_inventory=1},
137         sounds = default.node_sound_wood_defaults(),
138         walkable = true,
139         stack_max = 99,
140         after_place_node = function(pos)
141             pipe_device_autorotate(pos, states[s], "pipeworks:pump")
142             pipe_scanforobjects(pos)
143         end,
144         after_dig_node = function(pos)
145             pipe_scanforobjects(pos)
146         end,
147         drop = "pipeworks:pump_off_x"
148     })
149
150     local valveboxes = {}
151     pipe_addbox(valveboxes, pipe_leftstub)
152     pipe_addbox(valveboxes, pipe_valvebody_x)
153     if states[s] == "off" then 
154         pipe_addbox(valveboxes, pipe_valvehandle_off_x)
155     else
156         pipe_addbox(valveboxes, pipe_valvehandle_on_x)
157     end
158     pipe_addbox(valveboxes, pipe_rightstub)
159     local tilex = "pipeworks_valvebody_ends.png"
160     local tilez = "pipeworks_valvebody_sides.png"
161
162     minetest.register_node("pipeworks:valve_"..states[s].."_x", {
163         description = "Valve ("..states[s]..")",
164         drawtype = "nodebox",
165         tiles = {
166             "pipeworks_valvebody_top_"..states[s].."_x.png",
167             "pipeworks_valvebody_bottom.png",
168             tilex,
169             tilex,
170             tilez,
171             tilez,
172         },
173         paramtype = "light",
174         selection_box = {
175                      type = "fixed",
176             fixed = { -8/16, -4/16, -5/16, 8/16, 5/16, 5/16 }
177         },
178         node_box = {
179             type = "fixed",
180             fixed = valveboxes
181         },
182         groups = dgroups,
183         sounds = default.node_sound_wood_defaults(),
184         walkable = true,
185         stack_max = 99,
186         after_place_node = function(pos)
187             pipe_device_autorotate(pos, states[s], "pipeworks:valve")
188             pipe_scanforobjects(pos)
189         end,
190         after_dig_node = function(pos)
191             pipe_scanforobjects(pos)
192         end,
193         drop = "pipeworks:valve_off_x",
194         pipelike=1,
195         on_construct = function(pos)
196         local meta = minetest.env:get_meta(pos)
197         meta:set_int("pipelike",1)
198         end,
199     })
200
201     local valveboxes = {}
202     pipe_addbox(valveboxes, pipe_frontstub)
203     pipe_addbox(valveboxes, pipe_valvebody_z)
204     if states[s] == "off" then 
205         pipe_addbox(valveboxes, pipe_valvehandle_off_z)
206     else
207         pipe_addbox(valveboxes, pipe_valvehandle_on_z)
208     end
209     pipe_addbox(valveboxes, pipe_backstub)
210
211     minetest.register_node("pipeworks:valve_"..states[s].."_z", {
212         description = "Valve ("..states[s]..", Z-axis)",
213         drawtype = "nodebox",
214         tiles = {
215             "pipeworks_valvebody_top_"..states[s].."_z.png",
216             "pipeworks_valvebody_bottom.png",
217             tilez,
218             tilez,
219             tilex,
220             tilex,
221         },
222         paramtype = "light",
223         selection_box = {
224                      type = "fixed",
225             fixed = { -5/16, -4/16, -8/16, 5/16, 5/16, 8/16 }
226         },
227         node_box = {
228             type = "fixed",
229             fixed = valveboxes
230         },
231         groups = {snappy=3, pipe=1, not_in_creative_inventory=1},
232         sounds = default.node_sound_wood_defaults(),
233         walkable = true,
234         stack_max = 99,
235         after_place_node = function(pos)
236             pipe_device_autorotate(pos, states[s], "pipeworks:valve")
237             pipe_scanforobjects(pos)
238
239         end,
240         after_dig_node = function(pos)
241             pipe_scanforobjects(pos)
242         end,
243         drop = "pipeworks:valve_off_x",
244         pipelike=1,
245         on_construct = function(pos)
246         local meta = minetest.env:get_meta(pos)
247         meta:set_int("pipelike",1)
248         end,
249     })
250 end
251
252 -- intake grate
253
254 minetest.register_node("pipeworks:intake", {
255     description = "Intake grate",
256     drawtype = "nodebox",
257     tiles = {
258         "pipeworks_intake_top.png",
259         "pipeworks_intake_sides.png",
260         "pipeworks_intake_sides.png",
261         "pipeworks_intake_sides.png",
262         "pipeworks_intake_sides.png",
263         "pipeworks_intake_sides.png"
264     },
265     selection_box = {
266                  type = "fixed",
267         fixed = { -0.5, -0.5, -0.5, 0.5, 0.5, 0.5 }
268     },
269     node_box = {
270         type = "fixed",
271         fixed = { -0.5, -0.5, -0.5, 0.5, 0.5, 0.5 }
272     },
273     paramtype = "light",
274     groups = {snappy=3, pipe=1},
275     sounds = default.node_sound_wood_defaults(),
276     walkable = true,
277     stack_max = 99,
278     after_place_node = function(pos)
279         pipe_scanforobjects(pos)
280     end,
281     after_dig_node = function(pos)
282         pipe_scanforobjects(pos)
283     end,
284     pipelike=1,
285     on_construct = function(pos)
286     local meta = minetest.env:get_meta(pos)
287     meta:set_int("pipelike",1)
288     end,
289 })
290
291 -- outlet grate
292
293 minetest.register_node("pipeworks:outlet", {
294     description = "Outlet grate",
295     drawtype = "nodebox",
296     tiles = {
297         "pipeworks_outlet_top.png",
298         "pipeworks_outlet_sides.png",
299         "pipeworks_outlet_sides.png",
300         "pipeworks_outlet_sides.png",
301         "pipeworks_outlet_sides.png",
302         "pipeworks_outlet_sides.png"
303     },
304     selection_box = {
305                  type = "fixed",
306         fixed = { -0.5, -0.5, -0.5, 0.5, 0.5, 0.5 }
307     },
308     node_box = {
309         type = "fixed",
310         fixed = { -0.5, -0.5, -0.5, 0.5, 0.5, 0.5 }
311     },
312     paramtype = "light",
313     groups = {snappy=3, pipe=1},
314     sounds = default.node_sound_wood_defaults(),
315     walkable = true,
316     stack_max = 99,
317     after_place_node = function(pos)
318         pipe_scanforobjects(pos)
319     end,
320     after_dig_node = function(pos)
321         pipe_scanforobjects(pos)
322     end,
323     pipelike=1,
324     on_construct = function(pos)
325     local meta = minetest.env:get_meta(pos)
326     meta:set_int("pipelike",1)
327     end,
328 })
329
330 -- tanks
331
332 for fill = 0, 10 do
333     if fill == 0 then 
334         filldesc="empty"
335         sgroups = {snappy=3, pipe=1, tankfill=fill+1}
336     else
337         filldesc=fill.."0% full"
338         sgroups = {snappy=3, pipe=1, tankfill=fill+1, not_in_creative_inventory=1}
339     end
340
341     minetest.register_node("pipeworks:expansion_tank_"..fill, {
342         description = "Expansion Tank ("..filldesc..")... You hacker, you.",
343         tiles = {
344             "pipeworks_storage_tank_fittings.png",
345             "pipeworks_storage_tank_fittings.png",
346             "pipeworks_storage_tank_back.png",
347             "pipeworks_storage_tank_back.png",
348             "pipeworks_storage_tank_back.png",
349             "pipeworks_storage_tank_front_"..fill..".png"
350         },
351         paramtype = "light",
352         paramtype2 = "facedir",
353         groups = {snappy=3, pipe=1, tankfill=fill+1, not_in_creative_inventory=1},
354         sounds = default.node_sound_wood_defaults(),
355         walkable = true,
356         stack_max = 99,
357         drop = "pipeworks:storage_tank_"..fill.."_x",
358         after_place_node = function(pos)
359             pipe_look_for_stackable_tanks(pos)
360             pipe_scanforobjects(pos)
361         end,
362         after_dig_node = function(pos)
363             pipe_scanforobjects(pos)
364         end,
365         pipelike=0,
366         on_construct = function(pos)
367         local meta = minetest.env:get_meta(pos)
368         meta:set_int("pipelike",0)
369         end,
370     })
371
372     minetest.register_node("pipeworks:storage_tank_"..fill.."_x", {
373         description = "Fluid Storage Tank ("..filldesc..")",
374         tiles = {
375             "pipeworks_storage_tank_fittings.png",
376             "pipeworks_storage_tank_back.png",
377             "pipeworks_storage_tank_fittings.png",
378             "pipeworks_storage_tank_fittings.png",
379             "pipeworks_storage_tank_back.png",
380             "pipeworks_storage_tank_front_"..fill..".png"
381         },
382         paramtype = "light",
383         groups = sgroups,
384         sounds = default.node_sound_wood_defaults(),
385         walkable = true,
386         stack_max = 99,
387         after_place_node = function(pos)
388             pipe_look_for_stackable_tanks(pos)
389             if string.find(minetest.env:get_node(pos).name, "pipeworks:storage_tank_") ~= nil then
390                 pipe_device_autorotate(pos, nil, "pipeworks:storage_tank_"..fill)
391             end
392             pipe_scanforobjects(pos)
393         end,
394         after_dig_node = function(pos)
395             pipe_scanforobjects(pos)
396         end,
397         pipelike=1,
398         on_construct = function(pos)
399         local meta = minetest.env:get_meta(pos)
400         meta:set_int("pipelike",1)
401         end,
402     })
403     
404     minetest.register_node("pipeworks:storage_tank_"..fill.."_z", {
405         description = "Fluid Storage Tank (Z axis, "..filldesc..")... You hacker, you.",
406         tiles = {
407             "pipeworks_storage_tank_fittings.png",
408             "pipeworks_storage_tank_back.png",
409             "pipeworks_storage_tank_front_"..fill..".png",
410             "pipeworks_storage_tank_back.png",
411             "pipeworks_storage_tank_fittings.png",
412             "pipeworks_storage_tank_fittings.png"
413         },
414         paramtype = "light",
415         groups = {snappy=3, pipe=1, tankfill=fill+1, not_in_creative_inventory=1},
416         sounds = default.node_sound_wood_defaults(),
417         walkable = true,
418         stack_max = 99,
419         drop = "pipeworks:storage_tank_"..fill.."_x",
420         after_place_node = function(pos)
421             pipe_look_for_stackable_tanks(pos)
422             if string.find(minetest.env:get_node(pos).name, "pipeworks:storage_tank_") ~= nil then
423                 pipe_device_autorotate(pos, nil, "pipeworks:storage_tank_"..fill)
424             end
425             pipe_scanforobjects(pos)
426         end,
427         after_dig_node = function(pos)
428             pipe_scanforobjects(pos)
429         end,
430         pipelike=1,
431         on_construct = function(pos)
432         local meta = minetest.env:get_meta(pos)
433         meta:set_int("pipelike",1)
434         end,
435     })
436 end
437
438 -- various actions
439
440 local axes = { "x", "z" }
441
442 for a in ipairs(axes) do
443     minetest.register_on_punchnode(function (pos, node)
444         if node.name=="pipeworks:valve_on_"..axes[a] then 
445             minetest.env:add_node(pos, { name = "pipeworks:valve_off_"..axes[a] })
446             local meta = minetest.env:get_meta(pos)
447             meta:set_int("pipelike",0)
448         end
449     end)
450
451     minetest.register_on_punchnode(function (pos, node)
452         if node.name=="pipeworks:valve_off_"..axes[a] then 
453             minetest.env:add_node(pos, { name = "pipeworks:valve_on_"..axes[a] })
454             local meta = minetest.env:get_meta(pos)
455             meta:set_int("pipelike",1)
456         end
457     end)
458
459     minetest.register_on_punchnode(function (pos, node)
460         if node.name=="pipeworks:pump_on_"..axes[a] then 
461             minetest.env:add_node(pos, { name = "pipeworks:pump_off_"..axes[a] })
462         end
463     end)
464
465     minetest.register_on_punchnode(function (pos, node)
466         if node.name=="pipeworks:pump_off_"..axes[a] then 
467             minetest.env:add_node(pos, { name = "pipeworks:pump_on_"..axes[a] })
468         end
469     end)
470 end
471