RealBadAngel
2012-12-13 b8d77627a4d28c624e63423eef317dd09c68e533
commit | author | age
b8d776 1 -- This file supplies pneumatic tubes and a 'test' device
R 2
3 minetest.register_node("pipeworks:testobject", {
4     description = "Pneumatic tube test ojbect",
5     tiles = {
6         "pipeworks_testobject.png",
7     },
8     paramtype = "light",
9     groups = {snappy=3, tubedevice=1},
10     sounds = default.node_sound_wood_defaults(),
11     walkable = true,
12     after_place_node = function(pos)
13             tube_scanforobjects(pos)
14     end,
15     after_dig_node = function(pos)
16             tube_scanforobjects(pos)
17     end,
18 })
19
20 -- tables
21
22 minetest.register_alias("pipeworks:tube", "pipeworks:tube_000000")
23
24 tube_leftstub = {
25     { -32/64, -9/64, -9/64, 9/64, 9/64, 9/64 },    -- tube segment against -X face
26 }
27
28 tube_rightstub = {
29     { -9/64, -9/64, -9/64,  32/64, 9/64, 9/64 },    -- tube segment against +X face
30 }
31
32 tube_bottomstub = {
33     { -9/64, -32/64, -9/64,   9/64, 9/64, 9/64 },    -- tube segment against -Y face
34 }
35
36
37 tube_topstub = {
38     { -9/64, -9/64, -9/64,   9/64, 32/64, 9/64 },    -- tube segment against +Y face
39 }
40
41 tube_frontstub = {
42     { -9/64, -9/64, -32/64,   9/64, 9/64, 9/64 },    -- tube segment against -Z face
43 }
44
45 tube_backstub = {
46     { -9/64, -9/64, -9/64,   9/64, 9/64, 32/64 },    -- tube segment against -Z face
47
48
49 tube_selectboxes = {
50     { -32/64,  -10/64,  -10/64,  10/64,  10/64,  10/64 },
51     { -10/64 ,  -10/64,  -10/64, 32/64,  10/64,  10/64 },
52     { -10/64 , -32/64,  -10/64,  10/64,  10/64,  10/64 },
53     { -10/64 ,  -10/64,  -10/64,  10/64, 32/64,  10/64 },
54     { -10/64 ,  -10/64, -32/64,  10/64,  10/64,  10/64 },
55     { -10/64 ,  -10/64,  -10/64,  10/64,  10/64, 32/64 }
56 }
57
58 --  Functions
59
60 function tube_addbox(t, b)
61     for i in ipairs(b)
62         do table.insert(t, b[i])
63     end
64 end
65
66 -- now define the nodes!
67
68 for xm = 0, 1 do
69 for xp = 0, 1 do
70 for ym = 0, 1 do
71 for yp = 0, 1 do
72 for zm = 0, 1 do
73 for zp = 0, 1 do
74     local outboxes = {}
75     local outsel = {}
76     local outimgs = {}
77
78     if yp==1 then
79         tube_addbox(outboxes, tube_topstub)
80         table.insert(outsel, tube_selectboxes[4])
81         table.insert(outimgs, "pipeworks_tube_noctr.png")
82     else
83         table.insert(outimgs, "pipeworks_tube_plain.png")
84     end
85     if ym==1 then
86         tube_addbox(outboxes, tube_bottomstub)
87         table.insert(outsel, tube_selectboxes[3])
88         table.insert(outimgs, "pipeworks_tube_noctr.png")
89     else
90         table.insert(outimgs, "pipeworks_tube_plain.png")
91     end
92     if xp==1 then
93         tube_addbox(outboxes, tube_rightstub)
94         table.insert(outsel, tube_selectboxes[2])
95         table.insert(outimgs, "pipeworks_tube_noctr.png")
96     else
97         table.insert(outimgs, "pipeworks_tube_plain.png")
98     end
99     if xm==1 then
100         tube_addbox(outboxes, tube_leftstub)
101         table.insert(outsel, tube_selectboxes[1])
102         table.insert(outimgs, "pipeworks_tube_noctr.png")
103     else
104         table.insert(outimgs, "pipeworks_tube_plain.png")
105     end
106     if zp==1 then
107         tube_addbox(outboxes, tube_backstub)
108         table.insert(outsel, tube_selectboxes[6])
109         table.insert(outimgs, "pipeworks_tube_noctr.png")
110     else
111         table.insert(outimgs, "pipeworks_tube_plain.png")
112     end
113     if zm==1 then
114         tube_addbox(outboxes, tube_frontstub)
115         table.insert(outsel, tube_selectboxes[5])
116         table.insert(outimgs, "pipeworks_tube_noctr.png")
117     else
118         table.insert(outimgs, "pipeworks_tube_plain.png")
119     end
120
121     local jx = xp+xm
122     local jy = yp+ym
123     local jz = zp+zm
124
125     if (jx+jy+jz) == 1 then
126         if xm == 1 then 
127             table.remove(outimgs, 3)
128             table.insert(outimgs, 3, "pipeworks_tube_end.png")
129         end
130         if xp == 1 then 
131             table.remove(outimgs, 4)
132             table.insert(outimgs, 4, "pipeworks_tube_end.png")
133         end
134         if ym == 1 then 
135             table.remove(outimgs, 1)
136             table.insert(outimgs, 1, "pipeworks_tube_end.png")
137         end
138         if xp == 1 then 
139             table.remove(outimgs, 2)
140             table.insert(outimgs, 2, "pipeworks_tube_end.png")
141         end
142         if zm == 1 then 
143             table.remove(outimgs, 5)
144             table.insert(outimgs, 5, "pipeworks_tube_end.png")
145         end
146         if zp == 1 then 
147             table.remove(outimgs, 6)
148             table.insert(outimgs, 6, "pipeworks_tube_end.png")
149         end
150     end
151
152     local tname = xm..xp..ym..yp..zm..zp
153     local tgroups = ""
154
155     if tname ~= "000000" then
156         tgroups = {snappy=3, tube=1, not_in_creative_inventory=1}
157         tubedesc = "Pneumatic tube segment ("..tname..")... You hacker, you."
158         iimg=nil
159         wscale = {x=1,y=1,z=1}
160     else
161         tgroups = {snappy=3, tube=1}
162         tubedesc = "Pneumatic tube segment"
163         iimg="pipeworks_tube_inv.png"
164         outimgs = {
165             "pipeworks_tube_short.png",
166             "pipeworks_tube_short.png",
167             "pipeworks_tube_end.png",
168             "pipeworks_tube_end.png",
169             "pipeworks_tube_short.png",
170             "pipeworks_tube_short.png"
171         }
172         outboxes = { -24/64, -9/64, -9/64, 24/64, 9/64, 9/64 }
173         outsel = { -24/64, -10/64, -10/64, 24/64, 10/64, 10/64 }
174         wscale = {x=1,y=1,z=0.01}
175     end
176     
177     minetest.register_node("pipeworks:tube_"..tname, {
178         description = tubedesc,
179         drawtype = "nodebox",
180         tiles = outimgs,
181         inventory_image=iimg,
182         wield_image=iimg,
183         wield_scale=wscale,
184         paramtype = "light",
185         selection_box = {
186                      type = "fixed",
187             fixed = outsel
188         },
189         node_box = {
190             type = "fixed",
191             fixed = outboxes
192         },
193         groups = tgroups,
194         sounds = default.node_sound_wood_defaults(),
195         walkable = true,
196         stack_max = 99,
197         drop = "pipeworks:tube_000000",
198         tubelike=1,
199         on_construct = function(pos)
200         local meta = minetest.env:get_meta(pos)
201         meta:set_int("tubelike",1)
202         end,
203         after_place_node = function(pos)
204             tube_scanforobjects(pos)
205         end,
206         after_dig_node = function(pos)
207             tube_scanforobjects(pos)
208         end
209     })
210
211 end
212 end
213 end
214 end
215 end
216 end
217