Rename mod: walls → hades_walls
[minetest_hades/hades_revisited.git] / mods / pipeworks / tubes.lua
blob82649d93f6ca5af78fbf9b4451fcb37f405b533b
1 -- This file supplies the various kinds of pneumatic tubes
3 pipeworks.tubenodes = {}
5 minetest.register_alias("pipeworks:tube", "pipeworks:tube_000000")
7 -- now, a function to define the tubes
9 local REGISTER_COMPATIBILITY = true
11 local vti = {4, 3, 2, 1, 6, 5}
13 local register_one_tube = function(name, tname, dropname, desc, plain, noctrs, ends, short, inv, special, connects, style)
14 local outboxes = {}
15 local outsel = {}
16 local outimgs = {}
18 for i = 1, 6 do
19 outimgs[vti[i]] = plain[i]
20 end
22 for _, v in ipairs(connects) do
23 pipeworks.add_node_box(outboxes, pipeworks.tube_boxes[v])
24 table.insert(outsel, pipeworks.tube_selectboxes[v])
25 outimgs[vti[v]] = noctrs[v]
26 end
28 if #connects == 1 then
29 local v = connects[1]
30 v = v-1 + 2*(v%2) -- Opposite side
31 outimgs[vti[v]] = ends[v]
32 end
34 local tgroups = {snappy = 3, tube = 1, not_in_creative_inventory = 1}
35 local tubedesc = desc.." "..dump(connects)
36 local iimg = plain[1]
37 local wscale = {x = 1, y = 1, z = 1}
39 if #connects == 0 then
40 tgroups = {snappy = 3, tube = 1}
41 tubedesc = desc
42 iimg=inv
43 outimgs = {
44 short, short,
45 ends[3],ends[4],
46 short, short
48 outboxes = { -24/64, -9/64, -9/64, 24/64, 9/64, 9/64 }
49 outsel = { -24/64, -10/64, -10/64, 24/64, 10/64, 10/64 }
50 wscale = {x = 1, y = 1, z = 0.01}
51 end
53 table.insert(pipeworks.tubenodes, name.."_"..tname)
55 local nodedef = {
56 description = tubedesc,
57 drawtype = "nodebox",
58 tiles = outimgs,
59 use_texture_alpha = "clip",
60 sunlight_propagates = true,
61 inventory_image = iimg,
62 wield_image = iimg,
63 wield_scale = wscale,
64 paramtype = "light",
65 selection_box = {
66 type = "fixed",
67 fixed = outsel
69 node_box = {
70 type = "fixed",
71 fixed = outboxes
73 groups = tgroups,
74 sounds = hades_sounds.node_sound_glass_defaults(),
75 walkable = true,
76 stack_max = 99,
77 basename = name,
78 style = style,
79 drop = name.."_"..dropname,
80 tubelike = 1,
81 tube = {connect_sides = {front = 1, back = 1, left = 1, right = 1, top = 1, bottom = 1}},
82 on_construct = function(pos)
83 local meta = minetest.get_meta(pos)
84 meta:set_int("tubelike", 1)
85 if minetest.registered_nodes[name.."_"..tname].on_construct_ then
86 minetest.registered_nodes[name.."_"..tname].on_construct_(pos)
87 end
88 end,
89 after_place_node = function(pos)
90 pipeworks.scan_for_tube_objects(pos)
91 if minetest.registered_nodes[name.."_"..tname].after_place_node_ then
92 minetest.registered_nodes[name.."_"..tname].after_place_node_(pos)
93 end
94 end,
95 after_dig_node = function(pos)
96 pipeworks.scan_for_tube_objects(pos)
97 if minetest.registered_nodes[name.."_"..tname].after_dig_node_ then
98 minetest.registered_nodes[name.."_"..tname].after_dig_node_(pos)
99 end
102 if style == "6d" then
103 nodedef.paramtype2 = "facedir"
106 if special == nil then special = {} end
108 for key, value in pairs(special) do
109 if key == "on_construct" or key == "after_dig_node" or key == "after_place_node" then
110 nodedef[key.."_"] = value
111 elseif key == "groups" then
112 for group, val in pairs(value) do
113 nodedef.groups[group] = val
115 elseif key == "tube" then
116 for key, val in pairs(value) do
117 nodedef.tube[key] = val
119 elseif type(value) == "table" then
120 nodedef[key] = pipeworks.replace_name(value, "#id", tname)
121 elseif type(value) == "string" then
122 nodedef[key] = string.gsub(value, "#id", tname)
123 else
124 nodedef[key] = value
128 local prefix = ":"
129 if string.find(name, "pipeworks:") then prefix = "" end
131 minetest.register_node(prefix..name.."_"..tname, nodedef)
134 pipeworks.register_tube = function(name, desc, plain, noctrs, ends, short, inv, special, old_registration)
135 if old_registration then
136 for xm = 0, 1 do
137 for xp = 0, 1 do
138 for ym = 0, 1 do
139 for yp = 0, 1 do
140 for zm = 0, 1 do
141 for zp = 0, 1 do
142 local connects = {}
143 if xm == 1 then
144 connects[#connects+1] = 1
146 if xp == 1 then
147 connects[#connects+1] = 2
149 if ym == 1 then
150 connects[#connects+1] = 3
152 if yp == 1 then
153 connects[#connects+1] = 4
155 if zm == 1 then
156 connects[#connects+1] = 5
158 if zp == 1 then
159 connects[#connects+1] = 6
161 local tname = xm..xp..ym..yp..zm..zp
162 register_one_tube(name, tname, "000000", desc, plain, noctrs, ends, short, inv, special, connects, "old")
169 else
170 -- 6d tubes: uses only 10 nodes instead of 64, but the textures must be rotated
171 local cconnects = {{}, {1}, {1, 2}, {1, 3}, {1, 3, 5}, {1, 2, 3}, {1, 2, 3, 5}, {1, 2, 3, 4}, {1, 2, 3, 4, 5}, {1, 2, 3, 4, 5, 6}}
172 for index, connects in ipairs(cconnects) do
173 register_one_tube(name, tostring(index), "1", desc, plain, noctrs, ends, short, inv, special, connects, "6d")
175 if REGISTER_COMPATIBILITY then
176 local cname = name.."_compatibility"
177 minetest.register_node(cname, {
178 drawtype = "airlike",
179 style = "6d",
180 basename = name,
181 inventory_image = inv,
182 wield_image = inv,
183 paramtype = "light",
184 sunlight_propagates = true,
185 description = "Pneumatic Tube Segment (legacy)",
186 on_construct = function(pos)
187 local meta = minetest.get_meta(pos)
188 meta:set_int("tubelike", 1)
189 end,
190 after_place_node = function(pos)
191 pipeworks.scan_for_tube_objects(pos)
192 if minetest.registered_nodes[name.."_1"].after_place_node_ then
193 minetest.registered_nodes[name.."_1"].after_place_node_(pos)
195 end,
196 groups = {not_in_creative_inventory = 1, tube_to_update = 1},
197 tube = {connect_sides = {front = 1, back = 1, left = 1, right = 1, top = 1, bottom = 1}},
198 drop = name.."_1",
200 table.insert(pipeworks.tubenodes,cname)
201 for xm = 0, 1 do
202 for xp = 0, 1 do
203 for ym = 0, 1 do
204 for yp = 0, 1 do
205 for zm = 0, 1 do
206 for zp = 0, 1 do
207 local tname = xm..xp..ym..yp..zm..zp
208 minetest.register_alias(name.."_"..tname, cname)
219 if REGISTER_COMPATIBILITY then
220 minetest.register_abm({
221 nodenames = {"group:tube_to_update"},
222 interval = 1,
223 chance = 1,
224 action = function(pos, node, active_object_count, active_object_count_wider)
225 local minp = {x = pos.x-1, y = pos.y-1, z = pos.z-1}
226 local maxp = {x = pos.x+1, y = pos.y+1, z = pos.z+1}
227 if table.getn(minetest.find_nodes_in_area(minp, maxp, "ignore")) == 0 then
228 pipeworks.scan_for_tube_objects(pos)
234 -- now let's actually call that function to get the real work done!
236 local noctr_textures = {"pipeworks_tube_noctr.png", "pipeworks_tube_noctr.png", "pipeworks_tube_noctr.png",
237 "pipeworks_tube_noctr.png", "pipeworks_tube_noctr.png", "pipeworks_tube_noctr.png"}
238 local plain_textures = {"pipeworks_tube_plain.png", "pipeworks_tube_plain.png", "pipeworks_tube_plain.png",
239 "pipeworks_tube_plain.png", "pipeworks_tube_plain.png", "pipeworks_tube_plain.png"}
240 local end_textures = {"pipeworks_tube_end.png", "pipeworks_tube_end.png", "pipeworks_tube_end.png",
241 "pipeworks_tube_end.png", "pipeworks_tube_end.png", "pipeworks_tube_end.png"}
242 local short_texture = "pipeworks_tube_short.png"
243 local inv_texture = "pipeworks_tube_inv.png"
245 pipeworks.register_tube("pipeworks:tube", "Pneumatic Tube Segment", plain_textures, noctr_textures, end_textures, short_texture, inv_texture)
247 if pipeworks.enable_mese_tube then
248 local mese_noctr_textures = {"pipeworks_mese_tube_noctr_1.png", "pipeworks_mese_tube_noctr_2.png", "pipeworks_mese_tube_noctr_3.png",
249 "pipeworks_mese_tube_noctr_4.png", "pipeworks_mese_tube_noctr_5.png", "pipeworks_mese_tube_noctr_6.png"}
250 local mese_plain_textures = {"pipeworks_mese_tube_plain_1.png", "pipeworks_mese_tube_plain_2.png", "pipeworks_mese_tube_plain_3.png",
251 "pipeworks_mese_tube_plain_4.png", "pipeworks_mese_tube_plain_5.png", "pipeworks_mese_tube_plain_6.png"}
252 local mese_end_textures = {"pipeworks_mese_tube_end.png", "pipeworks_mese_tube_end.png", "pipeworks_mese_tube_end.png",
253 "pipeworks_mese_tube_end.png", "pipeworks_mese_tube_end.png", "pipeworks_mese_tube_end.png"}
254 local mese_short_texture = "pipeworks_mese_tube_short.png"
255 local mese_inv_texture = "pipeworks_mese_tube_inv.png"
256 pipeworks.register_tube("pipeworks:mese_tube", "Mese Pneumatic Tube Segment", mese_plain_textures, mese_noctr_textures,
257 mese_end_textures, mese_short_texture, mese_inv_texture,
258 {tube = {can_go = function(pos, node, velocity, stack)
259 local tbl = {}
260 local meta = minetest.get_meta(pos)
261 local inv = meta:get_inventory()
262 local found = false
263 local name = stack:get_name()
264 for i, vect in ipairs(pipeworks.meseadjlist) do
265 if meta:get_int("l"..tostring(i).."s") == 1 then
266 for _, st in ipairs(inv:get_list("line"..tostring(i))) do
267 if st:get_name() == name then
268 found = true
269 table.insert(tbl, vect)
274 if found == false then
275 for i, vect in ipairs(pipeworks.meseadjlist) do
276 if meta:get_int("l"..tostring(i).."s") == 1 then
277 if inv:is_empty("line"..tostring(i)) then
278 table.insert(tbl, vect)
283 return tbl
284 end},
285 on_construct = function(pos)
286 local meta = minetest.get_meta(pos)
287 local inv = meta:get_inventory()
288 for i = 1, 6 do
289 meta:set_int("l"..tostring(i).."s", 1)
290 inv:set_size("line"..tostring(i), 6*1)
292 meta:set_string("formspec",
293 "size[10,11]"..
294 "list[current_name;line1;2,0;6,1;]"..
295 "list[current_name;line2;2,1;6,1;]"..
296 "list[current_name;line3;2,2;6,1;]"..
297 "list[current_name;line4;2,3;6,1;]"..
298 "list[current_name;line5;2,4;6,1;]"..
299 "list[current_name;line6;2,5;6,1;]"..
300 "image[1,0;1,1;pipeworks_white.png]"..
301 "image[1,1;1,1;pipeworks_black.png]"..
302 "image[1,2;1,1;pipeworks_green.png]"..
303 "image[1,3;1,1;pipeworks_yellow.png]"..
304 "image[1,4;1,1;pipeworks_blue.png]"..
305 "image[1,5;1,1;pipeworks_red.png]"..
306 "button[8,0;1,1;button1;On]"..
307 "button[8,1;1,1;button2;On]"..
308 "button[8,2;1,1;button3;On]"..
309 "button[8,3;1,1;button4;On]"..
310 "button[8,4;1,1;button5;On]"..
311 "button[8,5;1,1;button6;On]"..
312 "list[current_player;main;0,7;10,4;]")
313 meta:set_string("infotext", "Mese pneumatic tube")
314 end,
315 on_receive_fields = function(pos, formname, fields, sender)
316 local meta = minetest.get_meta(pos)
317 local i
318 if fields.quit then return end
319 for key, _ in pairs(fields) do i = key end
320 if i == nil then return end
321 i = string.sub(i,-1)
322 newstate = 1 - meta:get_int("l"..i.."s")
323 meta:set_int("l"..i.."s",newstate)
324 local frm = "size[10,11]"..
325 "list[current_name;line1;2,0;6,1;]"..
326 "list[current_name;line2;2,1;6,1;]"..
327 "list[current_name;line3;2,2;6,1;]"..
328 "list[current_name;line4;2,3;6,1;]"..
329 "list[current_name;line5;2,4;6,1;]"..
330 "list[current_name;line6;2,5;6,1;]"..
331 "image[1,0;1,1;pipeworks_white.png]"..
332 "image[1,1;1,1;pipeworks_black.png]"..
333 "image[1,2;1,1;pipeworks_green.png]"..
334 "image[1,3;1,1;pipeworks_yellow.png]"..
335 "image[1,4;1,1;pipeworks_blue.png]"..
336 "image[1,5;1,1;pipeworks_red.png]"
337 for i = 1, 6 do
338 local st = meta:get_int("l"..tostring(i).."s")
339 if st == 0 then
340 frm = frm.."button[8,"..tostring(i-1)..";1,1;button"..tostring(i)..";Off]"
341 else
342 frm = frm.."button[8,"..tostring(i-1)..";1,1;button"..tostring(i)..";On]"
345 frm = frm.."list[current_player;main;0,7;10,4;]"
346 meta:set_string("formspec", frm)
347 end,
348 can_dig = function(pos, player)
349 local meta = minetest.get_meta(pos)
350 local inv = meta:get_inventory()
351 return (inv:is_empty("line1") and inv:is_empty("line2") and inv:is_empty("line3") and
352 inv:is_empty("line4") and inv:is_empty("line5") and inv:is_empty("line6"))
354 }, true) -- Must use old tubes, since the textures are rotated with 6d ones
357 if pipeworks.enable_detector_tube then
358 local detector_plain_textures = {"pipeworks_detector_tube_plain.png", "pipeworks_detector_tube_plain.png", "pipeworks_detector_tube_plain.png",
359 "pipeworks_detector_tube_plain.png", "pipeworks_detector_tube_plain.png", "pipeworks_detector_tube_plain.png"}
360 local detector_inv_texture = "pipeworks_detector_tube_inv.png"
361 pipeworks.register_tube("pipeworks:detector_tube_on", "Detector Tube Segment (on)", detector_plain_textures, noctr_textures,
362 end_textures, short_texture, detector_inv_texture,
363 {tube = {can_go = function(pos, node, velocity, stack)
364 local meta = minetest.get_meta(pos)
365 local name = minetest.get_node(pos).name
366 local nitems = meta:get_int("nitems")+1
367 meta:set_int("nitems", nitems)
368 minetest.after(0.1, minetest.registered_nodes[name].item_exit, pos)
369 return pipeworks.notvel(pipeworks.meseadjlist,velocity)
370 end},
371 groups = {mesecon = 2, not_in_creative_inventory = 1},
372 drop = "pipeworks:detector_tube_off_1",
373 mesecons = {receptor = {state = "on",
374 rules = pipeworks.mesecons_rules}},
375 item_exit = function(pos)
376 local meta = minetest.get_meta(pos)
377 local nitems = meta:get_int("nitems")-1
378 local node = minetest.get_node(pos)
379 local name = node.name
380 local fdir = node.param2
381 if nitems == 0 then
382 minetest.set_node(pos, {name = string.gsub(name, "on", "off"), param2 = fdir})
383 mesecon:receptor_off(pos, pipeworks.mesecons_rules)
384 else
385 meta:set_int("nitems", nitems)
387 end,
388 on_construct = function(pos)
389 local meta = minetest.get_meta(pos)
390 meta:set_int("nitems", 1)
391 local name = minetest.get_node(pos).name
392 minetest.after(0.1, minetest.registered_nodes[name].item_exit,pos)
393 end})
394 pipeworks.register_tube("pipeworks:detector_tube_off", "Detector Tube Segment", detector_plain_textures, noctr_textures,
395 end_textures, short_texture, detector_inv_texture,
396 {tube = {can_go = function(pos, node, velocity, stack)
397 local node = minetest.get_node(pos)
398 local name = node.name
399 local fdir = node.param2
400 minetest.set_node(pos,{name = string.gsub(name, "off", "on"), param2 = fdir})
401 mesecon:receptor_on(pos, pipeworks.mesecons_rules)
402 return pipeworks.notvel(pipeworks.meseadjlist, velocity)
403 end},
404 groups = {mesecon = 2},
405 mesecons = {receptor = {state = "off",
406 rules = pipeworks.mesecons_rules}}
410 if pipeworks.enable_conductor_tube then
411 local conductor_plain_textures = {"pipeworks_conductor_tube_plain.png", "pipeworks_conductor_tube_plain.png", "pipeworks_conductor_tube_plain.png",
412 "pipeworks_conductor_tube_plain.png", "pipeworks_conductor_tube_plain.png", "pipeworks_conductor_tube_plain.png"}
413 local conductor_noctr_textures = {"pipeworks_conductor_tube_noctr.png", "pipeworks_conductor_tube_noctr.png", "pipeworks_conductor_tube_noctr.png",
414 "pipeworks_conductor_tube_noctr.png", "pipeworks_conductor_tube_noctr.png", "pipeworks_conductor_tube_noctr.png"}
415 local conductor_end_textures = {"pipeworks_conductor_tube_end.png", "pipeworks_conductor_tube_end.png", "pipeworks_conductor_tube_end.png",
416 "pipeworks_conductor_tube_end.png", "pipeworks_conductor_tube_end.png", "pipeworks_conductor_tube_end.png"}
417 local conductor_short_texture = "pipeworks_conductor_tube_short.png"
418 local conductor_inv_texture = "pipeworks_conductor_tube_inv.png"
420 local conductor_on_plain_textures = {"pipeworks_conductor_tube_on_plain.png", "pipeworks_conductor_tube_on_plain.png", "pipeworks_conductor_tube_on_plain.png",
421 "pipeworks_conductor_tube_on_plain.png", "pipeworks_conductor_tube_on_plain.png", "pipeworks_conductor_tube_on_plain.png"}
422 local conductor_on_noctr_textures = {"pipeworks_conductor_tube_on_noctr.png", "pipeworks_conductor_tube_on_noctr.png", "pipeworks_conductor_tube_on_noctr.png",
423 "pipeworks_conductor_tube_on_noctr.png", "pipeworks_conductor_tube_on_noctr.png", "pipeworks_conductor_tube_on_noctr.png"}
424 local conductor_on_end_textures = {"pipeworks_conductor_tube_on_end.png", "pipeworks_conductor_tube_on_end.png", "pipeworks_conductor_tube_on_end.png",
425 "pipeworks_conductor_tube_on_end.png", "pipeworks_conductor_tube_on_end.png", "pipeworks_conductor_tube_on_end.png"}
427 pipeworks.register_tube("pipeworks:conductor_tube_off", "Conductor Tube Segment", conductor_plain_textures, conductor_noctr_textures,
428 conductor_end_textures, conductor_short_texture, conductor_inv_texture,
429 {groups = {mesecon = 2},
430 mesecons = {conductor = {state = "off",
431 rules = pipeworks.mesecons_rules,
432 onstate = "pipeworks:conductor_tube_on_#id"}}
435 pipeworks.register_tube("pipeworks:conductor_tube_on", "Conductor Tube Segment (on)", conductor_on_plain_textures, conductor_on_noctr_textures,
436 conductor_on_end_textures, conductor_short_texture, conductor_inv_texture,
437 {groups = {mesecon = 2, not_in_creative_inventory = 1},
438 drop = "pipeworks:conductor_tube_off_1",
439 mesecons = {conductor = {state = "on",
440 rules = pipeworks.mesecons_rules,
441 offstate = "pipeworks:conductor_tube_off_#id"}}
445 if pipeworks.enable_accelerator_tube then
446 local accelerator_noctr_textures = {"pipeworks_accelerator_tube_noctr.png", "pipeworks_accelerator_tube_noctr.png", "pipeworks_accelerator_tube_noctr.png",
447 "pipeworks_accelerator_tube_noctr.png", "pipeworks_accelerator_tube_noctr.png", "pipeworks_accelerator_tube_noctr.png"}
448 local accelerator_plain_textures = {"pipeworks_accelerator_tube_plain.png" ,"pipeworks_accelerator_tube_plain.png", "pipeworks_accelerator_tube_plain.png",
449 "pipeworks_accelerator_tube_plain.png", "pipeworks_accelerator_tube_plain.png", "pipeworks_accelerator_tube_plain.png"}
450 local accelerator_end_textures = {"pipeworks_accelerator_tube_end.png", "pipeworks_accelerator_tube_end.png", "pipeworks_accelerator_tube_end.png",
451 "pipeworks_accelerator_tube_end.png", "pipeworks_accelerator_tube_end.png", "pipeworks_accelerator_tube_end.png"}
452 local accelerator_short_texture = "pipeworks_accelerator_tube_short.png"
453 local accelerator_inv_texture = "pipeworks_accelerator_tube_inv.png"
455 pipeworks.register_tube("pipeworks:accelerator_tube", "Accelerator Pneumatic Tube Segment", accelerator_plain_textures,
456 accelerator_noctr_textures, accelerator_end_textures, accelerator_short_texture, accelerator_inv_texture,
457 {tube = {can_go = function(pos, node, velocity, stack)
458 velocity.speed = velocity.speed+1
459 return pipeworks.notvel(pipeworks.meseadjlist, velocity)
460 end}
464 if pipeworks.enable_crossing_tube then
465 -- FIXME: The textures are not the correct ones
466 local crossing_noctr_textures = {"pipeworks_crossing_tube_noctr.png", "pipeworks_crossing_tube_noctr.png", "pipeworks_crossing_tube_noctr.png",
467 "pipeworks_crossing_tube_noctr.png", "pipeworks_crossing_tube_noctr.png", "pipeworks_crossing_tube_noctr.png"}
468 local crossing_plain_textures = {"pipeworks_crossing_tube_plain.png" ,"pipeworks_crossing_tube_plain.png", "pipeworks_crossing_tube_plain.png",
469 "pipeworks_crossing_tube_plain.png", "pipeworks_crossing_tube_plain.png", "pipeworks_crossing_tube_plain.png"}
470 local crossing_end_textures = {"pipeworks_crossing_tube_end.png", "pipeworks_crossing_tube_end.png", "pipeworks_crossing_tube_end.png",
471 "pipeworks_crossing_tube_end.png", "pipeworks_crossing_tube_end.png", "pipeworks_crossing_tube_end.png"}
472 local crossing_short_texture = "pipeworks_crossing_tube_short.png"
473 local crossing_inv_texture = "pipeworks_crossing_tube_inv.png"
475 pipeworks.register_tube("pipeworks:crossing_tube", "Crossing Tube Segment", crossing_plain_textures,
476 crossing_noctr_textures, crossing_end_textures, crossing_short_texture, crossing_inv_texture,
477 {tube = {can_go = function(pos, node, velocity, stack)
478 return {velocity}
479 end}
483 if pipeworks.enable_sand_tube then
484 local sand_noctr_textures = {"pipeworks_sand_tube_noctr.png", "pipeworks_sand_tube_noctr.png", "pipeworks_sand_tube_noctr.png",
485 "pipeworks_sand_tube_noctr.png", "pipeworks_sand_tube_noctr.png", "pipeworks_sand_tube_noctr.png"}
486 local sand_plain_textures = {"pipeworks_sand_tube_plain.png", "pipeworks_sand_tube_plain.png", "pipeworks_sand_tube_plain.png",
487 "pipeworks_sand_tube_plain.png", "pipeworks_sand_tube_plain.png", "pipeworks_sand_tube_plain.png"}
488 local sand_end_textures = {"pipeworks_sand_tube_end.png", "pipeworks_sand_tube_end.png", "pipeworks_sand_tube_end.png",
489 "pipeworks_sand_tube_end.png", "pipeworks_sand_tube_end.png", "pipeworks_sand_tube_end.png"}
490 local sand_short_texture = "pipeworks_sand_tube_short.png"
491 local sand_inv_texture = "pipeworks_sand_tube_inv.png"
493 pipeworks.register_tube("pipeworks:sand_tube", "Sand Pneumatic Tube Segment", sand_plain_textures, sand_noctr_textures, sand_end_textures,
494 sand_short_texture, sand_inv_texture,
495 {groups = {sand_tube = 1}})
497 minetest.register_abm({nodenames = {"group:sand_tube"},
498 interval = 1,
499 chance = 1,
500 action = function(pos, node, active_object_count, active_object_count_wider)
501 for _, object in ipairs(minetest.get_objects_inside_radius(pos, 2)) do
502 if not object:is_player() and object:get_luaentity() and object:get_luaentity().name == "__builtin:item" then
503 if object:get_luaentity().itemstring ~= "" then
504 local titem = pipeworks.tube_item(pos,object:get_luaentity().itemstring)
505 titem:get_luaentity().start_pos = {x = pos.x, y = pos.y-1, z = pos.z}
506 titem:set_velocity({x = 0.01, y = 1, z = -0.01})
507 titem:set_acceleration({x = 0, y = 0, z = 0})
509 object:get_luaentity().itemstring = ""
510 object:remove()
517 if pipeworks.enable_mese_sand_tube then
518 local mese_sand_noctr_textures = {"pipeworks_mese_sand_tube_noctr.png", "pipeworks_mese_sand_tube_noctr.png", "pipeworks_mese_sand_tube_noctr.png",
519 "pipeworks_mese_sand_tube_noctr.png", "pipeworks_mese_sand_tube_noctr.png", "pipeworks_mese_sand_tube_noctr.png"}
520 local mese_sand_plain_textures = {"pipeworks_mese_sand_tube_plain.png", "pipeworks_mese_sand_tube_plain.png", "pipeworks_mese_sand_tube_plain.png",
521 "pipeworks_mese_sand_tube_plain.png", "pipeworks_mese_sand_tube_plain.png", "pipeworks_mese_sand_tube_plain.png"}
522 local mese_sand_end_textures = {"pipeworks_mese_sand_tube_end.png", "pipeworks_mese_sand_tube_end.png", "pipeworks_mese_sand_tube_end.png",
523 "pipeworks_mese_sand_tube_end.png", "pipeworks_mese_sand_tube_end.png", "pipeworks_mese_sand_tube_end.png"}
524 local mese_sand_short_texture = "pipeworks_mese_sand_tube_short.png"
525 local mese_sand_inv_texture = "pipeworks_mese_sand_tube_inv.png"
527 pipeworks.register_tube("pipeworks:mese_sand_tube", "Mese Sand Pneumatic Tube Segment", mese_sand_plain_textures, mese_sand_noctr_textures,
528 mese_sand_end_textures, mese_sand_short_texture,mese_sand_inv_texture,
529 {groups = {mese_sand_tube = 1},
530 on_construct = function(pos)
531 local meta = minetest.get_meta(pos)
532 meta:set_int("dist", 0)
533 meta:set_string("formspec",
534 "size[2,1]"..
535 "field[.5,.5;1.5,1;dist;distance;${dist}]")
536 meta:set_string("infotext", "Mese sand pneumatic tube")
537 end,
538 on_receive_fields = function(pos,formname,fields,sender)
539 local meta = minetest.get_meta(pos)
540 local dist
541 _, dist = pcall(tonumber, fields.dist)
542 if dist and 0 <= dist and dist <= 8 then meta:set_int("dist", dist) end
543 end,
546 local function get_objects_with_square_radius(pos, rad)
547 rad = rad + .5;
548 local objs = {}
549 for _,object in ipairs(minetest.get_objects_inside_radius(pos, math.sqrt(3)*rad)) do
550 if not object:is_player() and object:get_luaentity() and object:get_luaentity().name == "__builtin:item" then
551 local opos = object:get_pos()
552 if pos.x - rad <= opos.x and opos.x <= pos.x + rad and pos.y - rad <= opos.y and opos.y <= pos.y + rad and pos.z - rad <= opos.z and opos.z <= pos.z + rad then
553 objs[#objs + 1] = object
557 return objs
560 minetest.register_abm({nodenames = {"group:mese_sand_tube"},
561 interval = 1,
562 chance = 1,
563 action = function(pos, node, active_object_count, active_object_count_wider)
564 for _,object in ipairs(get_objects_with_square_radius(pos, minetest.get_meta(pos):get_int("dist"))) do
565 if not object:is_player() and object:get_luaentity() and object:get_luaentity().name == "__builtin:item" then
566 if object:get_luaentity().itemstring ~= "" then
567 local titem = pipeworks.tube_item(pos, object:get_luaentity().itemstring)
568 titem:get_luaentity().start_pos = {x = pos.x, y = pos.y-1, z = pos.z}
569 titem:set_velocity({x = 0.01, y = 1, z = -0.01})
570 titem:set_acceleration({x = 0, y = 0, z = 0})
572 object:get_luaentity().itemstring = ""
573 object:remove()
580 local function facedir_to_right_dir(facedir)
582 --find the other directions
583 local backdir = minetest.facedir_to_dir(facedir)
584 local topdir = ({[0] = {x = 0, y = 1, z = 0},
585 {x = 0, y = 0, z = 1},
586 {x = 0, y = 0, z = -1},
587 {x = 1, y = 0, z = 0},
588 {x = -1, y = 0, z = 0},
589 {x = 0, y = -1, z = 0}})[math.floor(facedir/4)]
591 --return a cross product
592 return {x = topdir.y*backdir.z - backdir.y*topdir.z,
593 y = topdir.z*backdir.x - backdir.z*topdir.x,
594 z = topdir.x*backdir.y - backdir.x*topdir.y}
597 if pipeworks.enable_one_way_tube then
598 minetest.register_node("pipeworks:one_way_tube", {
599 description = "One-Way Tube",
600 tiles = {"pipeworks_one_way_tube_top.png", "pipeworks_one_way_tube_top.png", "pipeworks_one_way_tube_output.png",
601 "pipeworks_one_way_tube_input.png", "pipeworks_one_way_tube_side.png", "pipeworks_one_way_tube_top.png"},
602 use_texture_alpha = "clip",
603 paramtype2 = "facedir",
604 drawtype = "nodebox",
605 paramtype = "light",
606 node_box = {type = "fixed",
607 fixed = {{-1/2, -9/64, -9/64, 1/2, 9/64, 9/64}}},
608 groups = {snappy = 2, choppy = 2, oddly_breakable_by_hand = 2, tubedevice = 1, tubedevice_receiver = 1},
609 sounds = hades_sounds.node_sound_glass_defaults(),
610 on_construct = function(pos)
611 minetest.get_meta(pos):set_int("tubelike", 1)
612 end,
613 after_place_node = function(pos)
614 pipeworks.scan_for_tube_objects(pos)
615 end,
616 after_dig_node = function(pos)
617 pipeworks.scan_for_tube_objects(pos)
618 end,
619 tube = {connect_sides = {left = 1, right = 1},
620 can_go = function(pos, node, velocity, stack)
621 return velocity
622 end,
623 insert_object = function(pos, node, stack, direction)
624 item1 = pipeworks.tube_item(pos, stack)
625 item1:get_luaentity().start_pos = pos
626 item1:set_velocity({x = direction.x*direction.speed, y = direction.y*direction.speed, z = direction.z*direction.speed})
627 item1:set_acceleration({x = 0, y = 0, z = 0})
628 return ItemStack("")
629 end,
630 can_insert = function(pos, node, stack, direction)
631 local dir = facedir_to_right_dir(node.param2)
632 if dir.x == direction.x and dir.y == direction.y and dir.z == direction.z then
633 return true
635 return false
636 end},