1 local S
= minetest
.get_translator("pipeworks")
3 -- List of devices that should participate in the autoplace algorithm
5 local pipereceptor_on
= nil
6 local pipereceptor_off
= nil
11 state
= mesecon
.state
.on
,
12 rules
= pipeworks
.mesecons_rules
18 state
= mesecon
.state
.off
,
19 rules
= pipeworks
.mesecons_rules
24 local pipes_devicelist
= {
40 -- Now define the nodes.
42 local states
= { "on", "off" }
46 for s
in ipairs(states
) do
48 if states
[s
] == "off" then
49 dgroups
= {snappy
=3, pipe
=1}
51 dgroups
= {snappy
=3, pipe
=1, not_in_creative_inventory
=1}
56 pipeworks
.add_node_box(pumpboxes
, pipeworks
.pipe_pumpbody
)
57 pipeworks
.add_node_box(pumpboxes
, pipeworks
.pipe_topstub
)
59 minetest
.register_node("pipeworks:pump_"..states
[s
], {
60 description
= S("Pump/Intake Module"),
61 _tt_help
= S("Takes in water from below").."\n"..S("Connects with pipe above").."\n"..S("Punch to activate"),
64 "pipeworks_pump_top.png",
65 "pipeworks_pump_bottom.png",
66 "pipeworks_pump_sides.png",
67 "pipeworks_pump_sides.png",
68 "pipeworks_pump_sides.png",
69 "pipeworks_pump_"..states
[s
]..".png"
72 paramtype2
= "facedir",
75 fixed
= { -0.5, -0.5, -0.5, 0.5, 0.5, 0.5 }
82 sounds
= hades_sounds
.node_sound_metal_defaults(),
84 after_place_node
= function(pos
)
85 pipeworks
.scan_for_pipe_objects(pos
)
87 after_dig_node
= function(pos
)
88 pipeworks
.scan_for_pipe_objects(pos
)
90 drop
= "pipeworks:pump_off",
91 mesecons
= {effector
= {
92 action_on
= function (pos
, node
)
93 minetest
.add_node(pos
,{name
="pipeworks:pump_on", param2
= node
.param2
})
95 action_off
= function (pos
, node
)
96 minetest
.add_node(pos
,{name
="pipeworks:pump_off", param2
= node
.param2
})
99 on_punch
= function(pos
, node
, puncher
)
100 local fdir
= minetest
.get_node(pos
).param2
101 minetest
.add_node(pos
, { name
= "pipeworks:pump_"..states
[3-s
], param2
= fdir
})
106 local valveboxes
= {}
107 pipeworks
.add_node_box(valveboxes
, pipeworks
.pipe_leftstub
)
108 pipeworks
.add_node_box(valveboxes
, pipeworks
.pipe_valvebody
)
109 if states
[s
] == "off" then
110 pipeworks
.add_node_box(valveboxes
, pipeworks
.pipe_valvehandle_off
)
112 pipeworks
.add_node_box(valveboxes
, pipeworks
.pipe_valvehandle_on
)
114 pipeworks
.add_node_box(valveboxes
, pipeworks
.pipe_rightstub
)
115 local tilex
= "pipeworks_valvebody_ends.png"
116 local tilez
= "pipeworks_valvebody_sides.png"
118 minetest
.register_node("pipeworks:valve_"..states
[s
].."_empty", {
119 description
= S("Valve"),
120 _tt_help
= S("Controls liquid flow between pipes").."\n"..S("Punch to toggle"),
121 drawtype
= "nodebox",
123 "pipeworks_valvebody_top_"..states
[s
]..".png",
124 "pipeworks_valvebody_bottom.png",
130 sunlight_propagates
= true,
132 paramtype2
= "facedir",
135 fixed
= { -8/16, -4/16, -5/16, 8/16, 5/16, 5/16 }
142 sounds
= hades_sounds
.node_sound_metal_defaults(),
144 after_place_node
= function(pos
)
145 pipeworks
.scan_for_pipe_objects(pos
)
147 after_dig_node
= function(pos
)
148 pipeworks
.scan_for_pipe_objects(pos
)
150 drop
= "pipeworks:valve_off_empty",
151 mesecons
= {effector
= {
152 action_on
= function (pos
, node
)
153 minetest
.add_node(pos
,{name
="pipeworks:valve_on_empty", param2
= node
.param2
})
155 action_off
= function (pos
, node
)
156 minetest
.add_node(pos
,{name
="pipeworks:valve_off_empty", param2
= node
.param2
})
159 on_punch
= function(pos
, node
, puncher
)
160 local fdir
= minetest
.get_node(pos
).param2
161 minetest
.add_node(pos
, { name
= "pipeworks:valve_"..states
[3-s
].."_empty", param2
= fdir
})
167 local valveboxes
= {}
168 pipeworks
.add_node_box(valveboxes
, pipeworks
.pipe_leftstub
)
169 pipeworks
.add_node_box(valveboxes
, pipeworks
.pipe_valvebody
)
170 pipeworks
.add_node_box(valveboxes
, pipeworks
.pipe_rightstub
)
171 pipeworks
.add_node_box(valveboxes
, pipeworks
.pipe_valvehandle_on
)
173 minetest
.register_node("pipeworks:valve_on_loaded", {
174 description
= S("Valve (on)"),
175 drawtype
= "nodebox",
177 "pipeworks_valvebody_top_on.png",
178 "pipeworks_valvebody_bottom.png",
179 "pipeworks_valvebody_ends.png",
180 "pipeworks_valvebody_ends.png",
181 "pipeworks_valvebody_sides.png",
182 "pipeworks_valvebody_sides.png",
184 sunlight_propagates
= true,
186 paramtype2
= "facedir",
189 fixed
= { -8/16, -4/16, -5/16, 8/16, 5/16, 5/16 }
195 groups
= {snappy
=3, pipe
=1, not_in_creative_inventory
=1},
196 sounds
= hades_sounds
.node_sound_metal_defaults(),
198 after_place_node
= function(pos
)
199 pipeworks
.scan_for_pipe_objects(pos
)
201 after_dig_node
= function(pos
)
202 pipeworks
.scan_for_pipe_objects(pos
)
204 drop
= "pipeworks:valve_off_empty",
205 mesecons
= {effector
= {
206 action_on
= function (pos
, node
)
207 minetest
.add_node(pos
,{name
="pipeworks:valve_on_empty", param2
= node
.param2
})
209 action_off
= function (pos
, node
)
210 minetest
.add_node(pos
,{name
="pipeworks:valve_off_empty", param2
= node
.param2
})
213 on_punch
= function(pos
, node
, puncher
)
214 local fdir
= minetest
.get_node(pos
).param2
215 minetest
.add_node(pos
, { name
= "pipeworks:valve_off_empty", param2
= fdir
})
222 minetest
.register_node("pipeworks:grating", {
223 description
= S("Decorative Grating"),
225 "pipeworks_grating_sides.png",
226 "pipeworks_grating_sides.png",
227 "pipeworks_grating_sides.png",
228 "pipeworks_grating_sides.png",
229 "pipeworks_grating_sides.png",
230 "pipeworks_grating_sides.png"
233 drawtype
= "glasslike",
235 sounds
= hades_sounds
.node_sound_metal_defaults(),
241 local spigotboxes
= {}
242 pipeworks
.add_node_box(spigotboxes
, pipeworks
.pipe_backstub
)
243 pipeworks
.add_node_box(spigotboxes
, pipeworks
.spigot_bottomstub
)
244 pipeworks
.add_node_box(spigotboxes
, pipeworks
.pipe_bendsphere
)
246 local spigotboxes_pouring
= {}
247 pipeworks
.add_node_box(spigotboxes_pouring
, pipeworks
.spigot_stream
)
248 pipeworks
.add_node_box(spigotboxes_pouring
, pipeworks
.pipe_backstub
)
249 pipeworks
.add_node_box(spigotboxes_pouring
, pipeworks
.spigot_bottomstub
)
250 pipeworks
.add_node_box(spigotboxes_pouring
, pipeworks
.pipe_bendsphere
)
252 minetest
.register_node("pipeworks:spigot", {
253 description
= S("Spigot Outlet"),
254 _tt_help
= S("Can pour out liquid below").."\n"..S("Connects with pipe sideways"),
255 drawtype
= "nodebox",
257 "pipeworks_spigot_sides.png",
258 "pipeworks_pipe_end_empty.png",
259 "pipeworks_spigot_sides.png",
260 "pipeworks_spigot_sides.png",
261 "pipeworks_pipe_end_empty.png",
262 "pipeworks_spigot_sides.png"
264 sunlight_propagates
= true,
266 paramtype2
= "facedir",
267 groups
= {snappy
=3, pipe
=1},
268 sounds
= hades_sounds
.node_sound_metal_defaults(),
270 after_place_node
= function(pos
)
271 pipeworks
.scan_for_pipe_objects(pos
)
273 after_dig_node
= function(pos
)
274 pipeworks
.scan_for_pipe_objects(pos
)
283 fixed
= { -2/16, -6/16, -2/16, 2/16, 2/16, 8/16 }
287 minetest
.register_node("pipeworks:spigot_pouring", {
288 description
= S("Spigot Outlet (pouring)"),
289 drawtype
= "nodebox",
291 "pipeworks_spigot_sides.png",
292 "default_water.png^pipeworks_spigot_bottom2.png",
293 { name
= "default_water_flowing_animated.png^pipeworks_spigot_sides2.png",
295 type = "vertical_frames",
301 { name
= "default_water_flowing_animated.png^pipeworks_spigot_sides2.png",
303 type = "vertical_frames",
309 { name
= "default_water_flowing_animated.png^pipeworks_spigot_sides2.png",
311 type = "vertical_frames",
317 { name
= "default_water_flowing_animated.png^pipeworks_spigot_sides2.png",
319 type = "vertical_frames",
326 sunlight_propagates
= true,
328 paramtype2
= "facedir",
329 groups
= {snappy
=3, pipe
=1, not_in_creative_inventory
=1},
330 sounds
= hades_sounds
.node_sound_metal_defaults(),
332 after_place_node
= function(pos
)
333 pipeworks
.scan_for_pipe_objects(pos
)
335 after_dig_node
= function(pos
)
336 pipeworks
.scan_for_pipe_objects(pos
)
341 fixed
= spigotboxes_pouring
,
345 fixed
= { -2/16, -6/16, -2/16, 2/16, 2/16, 8/16 }
347 drop
= "pipeworks:spigot",
350 -- sealed pipe entry/exit (horizontal pipe passing through a metal
351 -- wall, for use in places where walls should look like they're airtight)
353 local airtightboxes
= {}
354 pipeworks
.add_node_box(airtightboxes
, pipeworks
.pipe_frontstub
)
355 pipeworks
.add_node_box(airtightboxes
, pipeworks
.pipe_backstub
)
356 pipeworks
.add_node_box(airtightboxes
, pipeworks
.entry_panel
)
358 minetest
.register_node("pipeworks:entry_panel_empty", {
359 description
= S("Airtight Pipe Entry/Exit"),
360 _tt_help
= S("Transports liquids"),
361 drawtype
= "nodebox",
363 "pipeworks_plain.png",
364 "pipeworks_plain.png",
365 "pipeworks_plain.png",
366 "pipeworks_plain.png",
367 "pipeworks_pipe_end_empty.png",
368 "pipeworks_pipe_end_empty.png"
371 paramtype2
= "facedir",
372 groups
= {snappy
=3, pipe
=1},
373 sounds
= hades_sounds
.node_sound_metal_defaults(),
375 after_place_node
= function(pos
)
376 pipeworks
.scan_for_pipe_objects(pos
)
378 after_dig_node
= function(pos
)
379 pipeworks
.scan_for_pipe_objects(pos
)
384 fixed
= airtightboxes
,
389 { -2/16, -2/16, -8/16, 2/16, 2/16, 8/16 },
390 { -8/16, -8/16, -1/16, 8/16, 8/16, 1/16 }
393 on_place
= function(itemstack
, placer
, pointed_thing
)
394 if not pipeworks
.node_is_owned(pointed_thing
.under
, placer
)
395 and not pipeworks
.node_is_owned(pointed_thing
.above
, placer
) then
396 local node
= minetest
.get_node(pointed_thing
.under
)
398 if not minetest
.registered_nodes
[node
.name
]
399 or not minetest
.registered_nodes
[node
.name
].on_rightclick
then
400 local pitch
= placer
:get_look_pitch()
401 local above
= pointed_thing
.above
402 local under
= pointed_thing
.under
403 local fdir
= minetest
.dir_to_facedir(placer
:get_look_dir())
404 local undernode
= minetest
.get_node(under
)
405 local abovenode
= minetest
.get_node(above
)
406 local uname
= undernode
.name
407 local aname
= abovenode
.name
408 local isabove
= (above
.x
== under
.x
) and (above
.z
== under
.z
) and (pitch
> 0)
411 if above
.x
== under
.x
412 and above
.z
== under
.z
413 and ( string.find(uname
, "pipeworks:pipe_")
414 or string.find(uname
, "pipeworks:storage_")
415 or string.find(uname
, "pipeworks:expansion_")
416 or ( string.find(uname
, "pipeworks:grating") and not isabove
)
417 or ( string.find(uname
, "pipeworks:pump_") and not isabove
)
418 or ( string.find(uname
, "pipeworks:entry_panel")
419 and undernode
.param2
== 13 )
425 if minetest
.registered_nodes
[uname
]["buildable_to"] then
429 if not minetest
.registered_nodes
[minetest
.get_node(pos1
).name
]["buildable_to"] then return end
431 minetest
.add_node(pos1
, {name
= "pipeworks:entry_panel_empty", param2
= fdir
})
432 pipeworks
.scan_for_pipe_objects(pos1
)
434 if not pipeworks
.expect_infinite_stacks
then
435 itemstack
:take_item()
439 minetest
.registered_nodes
[node
.name
].on_rightclick(pointed_thing
.under
, node
, placer
, itemstack
)
446 minetest
.register_node("pipeworks:entry_panel_loaded", {
447 description
= S("Airtight Pipe Entry/Exit (loaded)"),
448 drawtype
= "nodebox",
450 "pipeworks_plain.png",
451 "pipeworks_plain.png",
452 "pipeworks_plain.png",
453 "pipeworks_plain.png",
454 "pipeworks_pipe_end_empty.png",
455 "pipeworks_pipe_end_empty.png"
458 paramtype2
= "facedir",
459 groups
= {snappy
=3, pipe
=1, not_in_creative_inventory
=1},
460 sounds
= hades_sounds
.node_sound_metal_defaults(),
462 after_place_node
= function(pos
)
463 pipeworks
.scan_for_pipe_objects(pos
)
465 after_dig_node
= function(pos
)
466 pipeworks
.scan_for_pipe_objects(pos
)
471 fixed
= airtightboxes
,
476 { -2/16, -2/16, -8/16, 2/16, 2/16, 8/16 },
477 { -8/16, -8/16, -1/16, 8/16, 8/16, 1/16 }
480 drop
= "pipeworks:entry_panel_empty"
483 local sensorboxes
= {}
484 pipeworks
.add_node_box(sensorboxes
, pipeworks
.pipe_leftstub
)
485 pipeworks
.add_node_box(sensorboxes
, pipeworks
.pipe_sensorbody
)
486 pipeworks
.add_node_box(sensorboxes
, pipeworks
.pipe_rightstub
)
488 minetest
.register_node("pipeworks:flow_sensor_empty", {
489 description
= S("Flow Sensor"),
490 _tt_help
= S("Provides mesecon signal when liquid flows through pipe"),
491 drawtype
= "nodebox",
493 "pipeworks_plain.png",
494 "pipeworks_plain.png",
495 "pipeworks_plain.png",
496 "pipeworks_plain.png",
497 "pipeworks_windowed_empty.png",
498 "pipeworks_windowed_empty.png"
500 sunlight_propagates
= true,
502 paramtype2
= "facedir",
503 groups
= {snappy
=3, pipe
=1},
504 sounds
= hades_sounds
.node_sound_metal_defaults(),
506 after_place_node
= function(pos
)
507 pipeworks
.scan_for_pipe_objects(pos
)
509 after_dig_node
= function(pos
)
510 pipeworks
.scan_for_pipe_objects(pos
)
513 on_construct
= function(pos
)
515 mesecon
:receptor_off(pos
, rules
)
525 { -8/16, -2/16, -2/16, 8/16, 2/16, 2/16 },
528 mesecons
= pipereceptor_off
531 minetest
.register_node("pipeworks:flow_sensor_loaded", {
532 description
= S("Flow sensor (on)"),
533 drawtype
= "nodebox",
535 "pipeworks_plain.png",
536 "pipeworks_plain.png",
537 "pipeworks_plain.png",
538 "pipeworks_plain.png",
539 "pipeworks_sensor_sides_on.png",
540 "pipeworks_sensor_sides_on.png"
542 sunlight_propagates
= true,
544 paramtype2
= "facedir",
545 groups
= {snappy
=3, pipe
=1, not_in_creative_inventory
=1},
546 sounds
= hades_sounds
.node_sound_metal_defaults(),
548 after_place_node
= function(pos
)
549 pipeworks
.scan_for_pipe_objects(pos
)
551 after_dig_node
= function(pos
)
552 pipeworks
.scan_for_pipe_objects(pos
)
554 on_construct
= function(pos
)
556 mesecon
:receptor_on(pos
, rules
)
567 { -8/16, -2/16, -2/16, 8/16, 2/16, 2/16 },
570 drop
= "pipeworks:flow_sensor_empty",
571 mesecons
= pipereceptor_on
,
578 local filldesc
= S("empty")
579 local sgroups
= {snappy
=3, pipe
=1, tankfill
=fill
+1}
583 filldesc
= S("@1% full", fill
*10)
584 sgroups
= {snappy
=3, pipe
=1, tankfill
=fill
+1, not_in_creative_inventory
=1}
585 image
= "pipeworks_storage_tank_fittings.png"
588 minetest
.register_node("pipeworks:expansion_tank_"..fill
, {
589 description
= S("Expansion Tank (@1)", filldesc
),
591 "pipeworks_storage_tank_fittings.png",
592 "pipeworks_storage_tank_fittings.png",
593 "pipeworks_storage_tank_back.png",
594 "pipeworks_storage_tank_back.png",
595 "pipeworks_storage_tank_back.png",
596 pipeworks
.liquid_texture
.."^pipeworks_storage_tank_front_"..fill
..".png"
598 inventory_image
= image
,
600 paramtype2
= "facedir",
601 groups
= {snappy
=3, pipe
=1, tankfill
=fill
+1, not_in_creative_inventory
=1},
602 sounds
= hades_sounds
.node_sound_metal_defaults(),
604 drop
= "pipeworks:storage_tank_"..fill
,
605 after_place_node
= function(pos
)
606 pipeworks
.look_for_stackable_tanks(pos
)
607 pipeworks
.scan_for_pipe_objects(pos
)
609 after_dig_node
= function(pos
)
610 pipeworks
.scan_for_pipe_objects(pos
)
615 minetest
.register_node("pipeworks:storage_tank_"..fill
, {
616 description
= S("Fluid Storage Tank (@1)", filldesc
),
618 "pipeworks_storage_tank_fittings.png",
619 "pipeworks_storage_tank_fittings.png",
620 "pipeworks_storage_tank_back.png",
621 "pipeworks_storage_tank_back.png",
622 "pipeworks_storage_tank_back.png",
623 pipeworks
.liquid_texture
.."^pipeworks_storage_tank_front_"..fill
..".png"
625 inventory_image
= image
,
627 paramtype2
= "facedir",
629 sounds
= hades_sounds
.node_sound_metal_defaults(),
631 after_place_node
= function(pos
)
632 pipeworks
.look_for_stackable_tanks(pos
)
633 pipeworks
.scan_for_pipe_objects(pos
)
635 after_dig_node
= function(pos
)
636 pipeworks
.scan_for_pipe_objects(pos
)
644 minetest
.register_node("pipeworks:fountainhead", {
645 description
= S("Fountainhead"),
646 _tt_help
= S("Can pour out liquid above").."\n"..S("Connects with pipe below"),
647 drawtype
= "nodebox",
649 "pipeworks_fountainhead_top.png",
650 "pipeworks_pipe_end.png",
651 "pipeworks_plain.png",
653 sunlight_propagates
= true,
655 groups
= {snappy
=3, pipe
=1},
656 sounds
= hades_sounds
.node_sound_metal_defaults(),
658 after_place_node
= function(pos
)
659 pipeworks
.scan_for_pipe_objects(pos
)
661 after_dig_node
= function(pos
)
662 pipeworks
.scan_for_pipe_objects(pos
)
664 on_construct
= function(pos
)
666 mesecon
:receptor_on(pos
, rules
)
671 fixed
= pipeworks
.fountainhead_model
,
675 fixed
= { -2/16, -8/16, -2/16, 2/16, 8/16, 2/16 }
680 minetest
.register_node("pipeworks:fountainhead_pouring", {
681 description
= S("Fountainhead (pouring)"),
682 drawtype
= "nodebox",
684 "pipeworks_fountainhead_top.png",
685 "pipeworks_pipe_end.png",
686 "pipeworks_plain.png",
688 sunlight_propagates
= true,
690 groups
= {snappy
=3, pipe
=1, not_in_creative_inventory
=1},
691 sounds
= hades_sounds
.node_sound_metal_defaults(),
693 after_place_node
= function(pos
)
694 pipeworks
.scan_for_pipe_objects(pos
)
696 after_dig_node
= function(pos
)
697 pipeworks
.scan_for_pipe_objects(pos
)
699 on_construct
= function(pos
)
701 mesecon
:receptor_on(pos
, rules
)
706 fixed
= pipeworks
.fountainhead_model
,
710 fixed
= { -2/16, -8/16, -2/16, 2/16, 8/16, 2/16 },
712 drop
= "pipeworks:fountainhead",
716 minetest
.register_alias("pipeworks:valve_off_loaded", "pipeworks:valve_off_empty")