From 4a834d17b28cd0d39fd116c67d3107a586f017f8 Mon Sep 17 00:00:00 2001 From: Vanessa Ezekowitz Date: Fri, 24 Aug 2012 13:39:29 -0400 Subject: [PATCH] Added pneumatic tubes with their own autoplace code (does not connect to steel pipes). Fixed a recursion bug that sometimes caused a stack overflow. --- autoplace.lua | 52 ++++++- changelog.txt | 3 + init.lua | 17 +- textures/pipeworks_tube_end.png | Bin 0 -> 482 bytes textures/pipeworks_tube_inv.png | Bin 0 -> 508 bytes textures/pipeworks_tube_noctr.png | Bin 0 -> 385 bytes textures/pipeworks_tube_plain.png | Bin 0 -> 399 bytes textures/pipeworks_tube_short.png | Bin 0 -> 269 bytes textures/pipeworks_tube_transparent.png | Bin 0 -> 109 bytes tubes.lua | 198 ++++++++++++++++++++++++ 10 files changed, 258 insertions(+), 12 deletions(-) create mode 100644 textures/pipeworks_tube_end.png create mode 100644 textures/pipeworks_tube_inv.png create mode 100644 textures/pipeworks_tube_noctr.png create mode 100644 textures/pipeworks_tube_plain.png create mode 100644 textures/pipeworks_tube_short.png create mode 100644 textures/pipeworks_tube_transparent.png create mode 100644 tubes.lua diff --git a/autoplace.lua b/autoplace.lua index 2f7c7f1..492f558 100644 --- a/autoplace.lua +++ b/autoplace.lua @@ -1,4 +1,6 @@ -pipe_scanforobjects = function(pos) +-- autorouting for pipes + +function pipe_scanforobjects(pos) pipe_autoroute({ x=pos.x-1, y=pos.y , z=pos.z }, "_loaded") pipe_autoroute({ x=pos.x+1, y=pos.y , z=pos.z }, "_loaded") pipe_autoroute({ x=pos.x , y=pos.y-1, z=pos.z }, "_loaded") @@ -17,19 +19,59 @@ pipe_scanforobjects = function(pos) end function pipe_autoroute(pos, state) - nctr = minetest.env:get_node(pos) if (string.find(nctr.name, "pipeworks:pipe_") == nil) then return end pipes_scansurroundings(pos) nsurround = pxm..pxp..pym..pyp..pzm..pzp - if nsurround == "000000" then nsurround = "110000" end - minetest.env:add_node(pos, { name = "pipeworks:pipe_"..nsurround..state }) end +-- autorouting for pneumatic tubes + +function tube_scanforobjects(pos) + tube_autoroute({ x=pos.x-1, y=pos.y , z=pos.z }) + tube_autoroute({ x=pos.x+1, y=pos.y , z=pos.z }) + tube_autoroute({ x=pos.x , y=pos.y-1, z=pos.z }) + tube_autoroute({ x=pos.x , y=pos.y+1, z=pos.z }) + tube_autoroute({ x=pos.x , y=pos.y , z=pos.z-1 }) + tube_autoroute({ x=pos.x , y=pos.y , z=pos.z+1 }) + tube_autoroute(pos) +end + +function tube_autoroute(pos) + nctr = minetest.env:get_node(pos) + if (string.find(nctr.name, "pipeworks:tube_") == nil) then return end + + pxm=0 + pxp=0 + pym=0 + pyp=0 + pzm=0 + pzp=0 + + nxm = minetest.env:get_node({ x=pos.x-1, y=pos.y , z=pos.z }) + nxp = minetest.env:get_node({ x=pos.x+1, y=pos.y , z=pos.z }) + nym = minetest.env:get_node({ x=pos.x , y=pos.y-1, z=pos.z }) + nyp = minetest.env:get_node({ x=pos.x , y=pos.y+1, z=pos.z }) + nzm = minetest.env:get_node({ x=pos.x , y=pos.y , z=pos.z-1 }) + nzp = minetest.env:get_node({ x=pos.x , y=pos.y , z=pos.z+1 }) + + if (string.find(nxm.name, "pipeworks:tube_") ~= nil) then pxm=1 end + if (string.find(nxp.name, "pipeworks:tube_") ~= nil) then pxp=1 end + if (string.find(nym.name, "pipeworks:tube_") ~= nil) then pym=1 end + if (string.find(nyp.name, "pipeworks:tube_") ~= nil) then pyp=1 end + if (string.find(nzm.name, "pipeworks:tube_") ~= nil) then pzm=1 end + if (string.find(nzp.name, "pipeworks:tube_") ~= nil) then pzp=1 end + + nsurround = pxm..pxp..pym..pyp..pzm..pzp + minetest.env:add_node(pos, { name = "pipeworks:tube_"..nsurround }) +end + +-- auto-rotation code for various devices the tubes attach to + function pipe_device_autorotate(pos, state, bname) if state == nil then @@ -53,7 +95,7 @@ function pipe_device_autorotate(pos, state, bname) end -pipes_scansurroundings = function(pos) +function pipes_scansurroundings(pos) pxm=0 pxp=0 pym=0 diff --git a/changelog.txt b/changelog.txt index 8db2a4a..9e51430 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,6 +1,9 @@ Changelog --------- +2012-08-24: Added square-ish pneumatic tubes, with their own autoplace code +(they do not connect to the steel pipes or their related devices). + 2012-08-22: Added outlet grate, made it participate in autoplace algorithm. Extended storage tank to show fill level in 10% steps (0% to 100%). Added "expansion tank" that appears if the user stacks tanks upwards. (Downwards is diff --git a/init.lua b/init.lua index fe5d353..a36fc16 100644 --- a/init.lua +++ b/init.lua @@ -1,13 +1,15 @@ -- Pipeworks mod by Vanessa Ezekowitz - 2012-08-05 -- --- Entirely my own code. This mod merely supplies enough nodes to build --- a bunch of pipes in all directions and with all types of junctions +-- Entirely my own code. This mod supplies various shapes of pipes +-- and devices that they can connect to such as pumps, valves, etc. +-- All pipes autoconnect as you lay them out, and devices will auto- +-- connect to them. -- -- License: WTFPL -- --- comment-out the following dofile line to disnable the old pipe nodes. -dofile(minetest.get_modpath("pipeworks").."/oldpipes.lua") +-- Un-comment the following dofile line to re-enable the old pipe nodes. +-- dofile(minetest.get_modpath("pipeworks").."/oldpipes.lua") -- tables @@ -116,7 +118,7 @@ dbg = function(s) end end -function fix_newpipe_names(table, replacement) +function pipes_fix_image_names(table, replacement) outtable={} for i in ipairs(table) do outtable[i]=string.gsub(table[i], "_XXXXX", replacement) @@ -249,7 +251,7 @@ for zp = 0, 1 do minetest.register_node("pipeworks:pipe_"..pname.."_empty", { description = pipedesc, drawtype = "nodebox", - tiles = fix_newpipe_names(outimgs, "_empty"), + tiles = pipes_fix_image_names(outimgs, "_empty"), paramtype = "light", selection_box = { type = "fixed", @@ -280,7 +282,7 @@ for zp = 0, 1 do minetest.register_node("pipeworks:pipe_"..pname.."_loaded", { description = "Pipe segment (loaded, "..pname..")... You hacker, you.", drawtype = "nodebox", - tiles = fix_newpipe_names(outimgs, "_loaded"), + tiles = pipes_fix_image_names(outimgs, "_loaded"), paramtype = "light", selection_box = { type = "fixed", @@ -314,6 +316,7 @@ end end end +dofile(minetest.get_modpath("pipeworks").."/tubes.lua") dofile(minetest.get_modpath("pipeworks").."/devices.lua") dofile(minetest.get_modpath("pipeworks").."/autoplace.lua") diff --git a/textures/pipeworks_tube_end.png b/textures/pipeworks_tube_end.png new file mode 100644 index 0000000000000000000000000000000000000000..e35edb336e3dfb333a5f9a21665f7f76211cc593 GIT binary patch literal 482 zcmV<80UiE{P)?i3o@vmN0PmDX1t1gP z6$hvQvN%05&85&=kYhYCPzPN)D9&#sKFGVL||M!{x33Z*l}t)|RnBdh>avK`#PO=X+E@kGY=;KqSB`Ms%-$ YA88U{c=Eoo#sB~S07*qoM6N<$f-O$R^Z)<= literal 0 HcmV?d00001 diff --git a/textures/pipeworks_tube_inv.png b/textures/pipeworks_tube_inv.png new file mode 100644 index 0000000000000000000000000000000000000000..93c51b1f51fbd22ecf29c757d3964dddc72a3955 GIT binary patch literal 508 zcmV{F7 zqcR8^Fbw^wgb#10vI+6EjExBSNG8(=M3 zHxjgE6Yze zzjq|wUTr{XNggTIVs$laFts3$6p4f(_Zgsc?9aTO;;JiGWU1BNA$qCh$p4DpzTZWp z%_%o>X+arwN{TCK3Vpb-5TZHx(!!99j*@(>Y~O->DkZGy9t|{4H6WsEs@4C|t1q|qh^DgK zE>AQ1HL`vee`3_q0Iv&93_|-5bvk7P9Y3~7Q yh@fY`k0nH`%Mioq4|h%gx(*A1AP9mWw8R%AG3Fg;-}Z6<0000{XE z)7O>#4u^!GIAiiudnN`3Mg>n7$B>F!Z)Y78Z7|?));=FvRVI>NDsrALSp9>_ge@(M zBA59ehDLFBJ>Pe%IKKI*Wqjh=iUTYiHlczB%?y7n%-OhH8dw;Pg-fPPYvXWGztCSC z%+FxuGK)c{nO~LBqp(Nx^_qJLSF_^GIz$+9E0r1|8A9X*7;}UdaCr31Ep<6NORQHm z)9rPPb($vU`WoLwmNf!V4fa20b=`aEGEt=EN%T@49q*4z=d9hspxv2p)j!xwL^w3%mJ54bRG$m#52;B?rb zGdEUBiQ#8a+yA-}mK1B3E`~GL^9qBO3hCqgp dehvQv+|`Ls#3b@(mjQ#1!PC{xWt~$(697x&i_HK4 literal 0 HcmV?d00001 diff --git a/textures/pipeworks_tube_plain.png b/textures/pipeworks_tube_plain.png new file mode 100644 index 0000000000000000000000000000000000000000..2d9c8d8a2c53f5391ca5e0e3fe3cc4ec295527e5 GIT binary patch literal 399 zcmV;A0dW3_P)2KC(7^FnW$!bXk+lqn~hwHQO)>tBj7E{XE z)7O>#4u^!Gl0xsXLn>~)y?$D>SwVm`VD99wnCPyp%ciUe_PONPB*-zp z`uZu!w)O{`fQlIy4En#`WZOvBKELxY*Tb|W3b&HZ}|GpSaiBC#Xs=Gt7 z56t8b-DuH2q2Z2u-j<*fBHtTkUHoP}C*pVR7d4*$<{V(VU*4N46f5yERA&u{>*?y} Jvd$@?2>|V)X`KK7 literal 0 HcmV?d00001 diff --git a/textures/pipeworks_tube_transparent.png b/textures/pipeworks_tube_transparent.png new file mode 100644 index 0000000000000000000000000000000000000000..4b4ee1fcb28be267ec2229b3f3f22a7f3908a6e9 GIT binary patch literal 109 zcmeAS@N?(olHy`uVBq!ia0vp^EFjFm1|(O0oL2{=I14-?iy0WWg+Z8+Vb&Z8pdfpR zr>`sf9S#Y8Gli|Uw;Tlu@p!s8hHzX@PFNrV~5 A3jhEB literal 0 HcmV?d00001 diff --git a/tubes.lua b/tubes.lua new file mode 100644 index 0000000..fb606a0 --- /dev/null +++ b/tubes.lua @@ -0,0 +1,198 @@ +-- This file supplies pneumatic tubes. + +-- tables + +minetest.register_alias("pipeworks:tube", "pipeworks:tube_000000") + +tube_leftstub = { + { -32/64, -9/64, -9/64, 9/64, 9/64, 9/64 }, -- tube segment against -X face +} + +tube_rightstub = { + { -9/64, -9/64, -9/64, 32/64, 9/64, 9/64 }, -- tube segment against +X face +} + +tube_bottomstub = { + { -9/64, -32/64, -9/64, 9/64, 9/64, 9/64 }, -- tube segment against -Y face +} + + +tube_topstub = { + { -9/64, -9/64, -9/64, 9/64, 32/64, 9/64 }, -- tube segment against +Y face +} + +tube_frontstub = { + { -9/64, -9/64, -32/64, 9/64, 9/64, 9/64 }, -- tube segment against -Z face +} + +tube_backstub = { + { -9/64, -9/64, -9/64, 9/64, 9/64, 32/64 }, -- tube segment against -Z face +} + +tube_selectboxes = { + { -32/64, -10/64, -10/64, 10/64, 10/64, 10/64 }, + { -10/64 , -10/64, -10/64, 32/64, 10/64, 10/64 }, + { -10/64 , -32/64, -10/64, 10/64, 10/64, 10/64 }, + { -10/64 , -10/64, -10/64, 10/64, 32/64, 10/64 }, + { -10/64 , -10/64, -32/64, 10/64, 10/64, 10/64 }, + { -10/64 , -10/64, -10/64, 10/64, 10/64, 32/64 } +} + +-- Functions + +function tube_addbox(t, b) + for i in ipairs(b) + do table.insert(t, b[i]) + end +end + +-- now define the nodes! + +for xm = 0, 1 do +for xp = 0, 1 do +for ym = 0, 1 do +for yp = 0, 1 do +for zm = 0, 1 do +for zp = 0, 1 do + local outboxes = {} + local outsel = {} + local outimgs = {} + + if yp==1 then + tube_addbox(outboxes, tube_topstub) + table.insert(outsel, tube_selectboxes[4]) + table.insert(outimgs, "pipeworks_tube_noctr.png") + else + table.insert(outimgs, "pipeworks_tube_plain.png") + end + if ym==1 then + tube_addbox(outboxes, tube_bottomstub) + table.insert(outsel, tube_selectboxes[3]) + table.insert(outimgs, "pipeworks_tube_noctr.png") + else + table.insert(outimgs, "pipeworks_tube_plain.png") + end + if xp==1 then + tube_addbox(outboxes, tube_rightstub) + table.insert(outsel, tube_selectboxes[2]) + table.insert(outimgs, "pipeworks_tube_noctr.png") + else + table.insert(outimgs, "pipeworks_tube_plain.png") + end + if xm==1 then + tube_addbox(outboxes, tube_leftstub) + table.insert(outsel, tube_selectboxes[1]) + table.insert(outimgs, "pipeworks_tube_noctr.png") + else + table.insert(outimgs, "pipeworks_tube_plain.png") + end + if zp==1 then + tube_addbox(outboxes, tube_backstub) + table.insert(outsel, tube_selectboxes[6]) + table.insert(outimgs, "pipeworks_tube_noctr.png") + else + table.insert(outimgs, "pipeworks_tube_plain.png") + end + if zm==1 then + tube_addbox(outboxes, tube_frontstub) + table.insert(outsel, tube_selectboxes[5]) + table.insert(outimgs, "pipeworks_tube_noctr.png") + else + table.insert(outimgs, "pipeworks_tube_plain.png") + end + + local jx = xp+xm + local jy = yp+ym + local jz = zp+zm + + if (jx+jy+jz) == 1 then + if xm == 1 then + table.remove(outimgs, 3) + table.insert(outimgs, 3, "pipeworks_tube_end.png") + end + if xp == 1 then + table.remove(outimgs, 4) + table.insert(outimgs, 4, "pipeworks_tube_end.png") + end + if ym == 1 then + table.remove(outimgs, 1) + table.insert(outimgs, 1, "pipeworks_tube_end.png") + end + if xp == 1 then + table.remove(outimgs, 2) + table.insert(outimgs, 2, "pipeworks_tube_end.png") + end + if zm == 1 then + table.remove(outimgs, 5) + table.insert(outimgs, 5, "pipeworks_tube_end.png") + end + if zp == 1 then + table.remove(outimgs, 6) + table.insert(outimgs, 6, "pipeworks_tube_end.png") + end + end + + local tname = xm..xp..ym..yp..zm..zp + local tgroups = "" + + if tname ~= "000000" then + tgroups = {snappy=3, tube=1, not_in_creative_inventory=1} + tubedesc = "Pneumatic tube segment ("..tname..")... You hacker, you." + iimg=nil + else + tgroups = {snappy=3, tube=1} + tubedesc = "Pneumatic tube segment" + iimg="pipeworks_tube_inv.png" + outimgs = { + "pipeworks_tube_short.png", + "pipeworks_tube_short.png", + "pipeworks_tube_end.png", + "pipeworks_tube_end.png", + "pipeworks_tube_short.png", + "pipeworks_tube_short.png" + } + outboxes = { -24/64, -9/64, -9/64, 24/64, 9/64, 9/64 } + outsel = { -24/64, -10/64, -10/64, 24/64, 10/64, 10/64 } + end + + minetest.register_node("pipeworks:tube_"..tname, { + description = tubedesc, + drawtype = "nodebox", + tiles = outimgs, + inventory_image=iimg, + wield_image=iimg, + paramtype = "light", + selection_box = { + type = "fixed", + fixed = outsel + }, + node_box = { + type = "fixed", + fixed = outboxes + }, + groups = tgroups, + sounds = default.node_sound_wood_defaults(), + walkable = true, + stack_max = 99, + drop = "pipeworks:tube_000000", + tubelike=1, + on_construct = function(pos) + local meta = minetest.env:get_meta(pos) + meta:set_int("tubelike",1) + end, + after_place_node = function(pos) + tube_scanforobjects(pos) + end, + after_dig_node = function(pos) + tube_scanforobjects(pos) + end + }) + +end +end +end +end +end +end + +print("pipeworks loaded!")