RealBadAngel
2013-02-13 d037d26bc79dfa0258b4f03f795a3cf010b80076
commit | author | age
478407 1     minetest.register_node("technic:wall", {
R 2         description = description,
3         drawtype = "nodebox",
4         tiles = {"default_wood.png"},
5         paramtype = "light",
6         --paramtype2 = "facedir",
7         sunlight_propagates = true,
8         is_ground_content = true,
9         node_box = {
10             type = "fixed",
11             --fixed = {-0.5, -0.5, 0.25, 0.5, 0.5, 0.5},
12     fixed={
13     {-0.5, -0.5, -0.5, -0.4, 0.5, -0.4},
14     {-0.4, -0.5, 0.3, -0.3, 0.5, 0.4},
15     {0.3, -0.5, 0.3, 0.4, 0.5,0.4},
16     {0.3, -0.5, -0.3, 0.4, 0.5,-0.4},
17     {-0.3, -0.35, -0.3, 0.3, -0.2,-0.25},
18     {-0.3, 0.2, -0.3,     0.3, 0.35,-0.25},
19     {-0.3, -0.35, 0.25, 0.3, -0.2,0.3},
20     {-0.3, 0.2, 0.25,     0.3, 0.35,0.3},
21     {-0.3, -0.35, -0.25, -0.25, -0.2,0.25},
22     {-0.3, 0.2, -0.25,     -0.25, 0.35,0.25},
23     {0.25, -0.35, -0.25, 0.3, -0.2,0.25},
24     {0.25, 0.2, -0.25,    0.3, 0.35,0.25},
25     },},
26         sounds = default.node_sound_stone_defaults(),
27     })
28
29 function get_face(pos,ppos,pvect)
30     ppos={x=ppos.x-pos.x,y=ppos.y-pos.y+1.5,z=ppos.z-pos.z}
31     if pvect.x>0 then
32         local t=(-0.5-ppos.x)/pvect.x
33         local y_int=ppos.y+t*pvect.y
34         local z_int=ppos.z+t*pvect.z
35         if y_int>-0.4 and y_int<0.4 and z_int>-0.4 and z_int<0.4 then return 1 end 
36     elseif pvect.x<0 then
37         local t=(0.5-ppos.x)/pvect.x
38         local y_int=ppos.y+t*pvect.y
39         local z_int=ppos.z+t*pvect.z
40         if y_int>-0.4 and y_int<0.4 and z_int>-0.4 and z_int<0.4 then return 2 end 
41     end
42     if pvect.y>0 then
43         local t=(-0.5-ppos.y)/pvect.y
44         local x_int=ppos.x+t*pvect.x
45         local z_int=ppos.z+t*pvect.z
46         if x_int>-0.4 and x_int<0.4 and z_int>-0.4 and z_int<0.4 then return 3 end 
47     elseif pvect.y<0 then
48         local t=(0.5-ppos.y)/pvect.y
49         local x_int=ppos.x+t*pvect.x
50         local z_int=ppos.z+t*pvect.z
51         if x_int>-0.4 and x_int<0.4 and z_int>-0.4 and z_int<0.4 then return 4 end 
52     end
53     if pvect.z>0 then
54         local t=(-0.5-ppos.z)/pvect.z
55         local x_int=ppos.x+t*pvect.x
56         local y_int=ppos.y+t*pvect.y
57         if x_int>-0.4 and x_int<0.4 and y_int>-0.4 and y_int<0.4 then return 5 end 
58     elseif pvect.z<0 then
59         local t=(0.5-ppos.z)/pvect.z
60         local x_int=ppos.x+t*pvect.x
61         local y_int=ppos.y+t*pvect.y
62         if x_int>-0.4 and x_int<0.4 and y_int>-0.4 and y_int<0.4 then return 6 end 
63     end
64 end
65
66
67 for xm=0,1 do
68 for xp=0,1 do
69 for ym=0,1 do
70 for yp=0,1 do
71 for zm=0,1 do
72 for zp=0,1 do
73
74 local a=8/16
75 local b=7/16
76 local nodeboxes= {
77     { -a, -a, -a, -b,  a, -b },
78     { -a, -a,  b, -b,  a,  a },
79     {  b, -a,  b,  a,  a,  a },
80     {  b, -a, -a,  a,  a, -b },
81
82     { -b,  b, -a,  b,  a, -b },
83     { -b, -a, -a,  b, -b, -b },
84     
85     { -b,  b,  b,  b,  a,  a },
86     { -b, -a,  b,  b, -b,  a },
87
88     {  b,  b, -b,  a,  a,  b },
89     {  b, -a, -b,  a, -b,  b },
90
91     { -a,  b, -b, -b,  a,  b },
92     { -a, -a, -b, -b, -b,  b },
93     }
94     
95     if yp==0 then
96         table.insert(nodeboxes, {-b,b,-b, b,a,b})
97     end
98     if ym==0 then
99         table.insert(nodeboxes, {-b,-a,-b, b,-b,b})
100     end
101     if xp==0 then
102         table.insert(nodeboxes, {b,b,b,a,-b,-b})
103     end
104     if xm==0 then
105         table.insert(nodeboxes, {-a,-b,-b,-b,b,b})
106     end
107     if zp==0 then
108         table.insert(nodeboxes, {-b,-b,b, b,b,a})
109     end
110     if zm==0 then
111         table.insert(nodeboxes, {-b,-b,-a, b,b,-b})
112     end
113     
114     local nameext=tostring(xm)..tostring(xp)..tostring(ym)..tostring(yp)..tostring(zm)..tostring(zp)
115     local groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2}
116     if nameext~="111111" then groups.not_in_creative_inventory=1 end
117     
118
119     minetest.register_node("technic:frame_"..nameext,{
120         description = "Frame",
121         tiles = {"technic_frame.png"},
122         groups=groups,
123         drawtype = "nodebox",
124         node_box = {
125             type = "fixed",
126         fixed=nodeboxes,
127         },
128         paramtype = "light",
129         frame=1,
130         drop="technic:frame_111111",
131         frame_connect_all=function(pos)
132             local nodename=minetest.env:get_node(pos).name
133             l2={}
134             l1={{x=-1,y=0,z=0},{x=1,y=0,z=0},{x=0,y=-1,z=0},{x=0,y=1,z=0},{x=0,y=0,z=-1},{x=0,y=0,z=1}}
135             for i,dir in ipairs(l1) do
136                 if string.sub(nodename,-7+i,-7+i)=="1" then
137                     l2[#(l2)+1]=dir
138                 end
139             end
140             return l2
141         end,
142         on_punch=function(pos,node,puncher)
143             local ppos=puncher:getpos()
144             local pvect=puncher:get_look_dir()
145             local pface=get_face(pos,ppos,pvect)
146             if pface==nil then return end
147             local nodename=node.name
148             local newstate=tostring(1-tonumber(string.sub(nodename,-7+pface,-7+pface)))
149             if pface<=5 then
150                 nodename=string.sub(nodename,1,-7+pface-1)..newstate..string.sub(nodename,-7+pface+1)
151             else
152                 nodename=string.sub(nodename,1,-2)..newstate
153             end
154             node.name=nodename
155             minetest.env:set_node(pos,node)
156         end
157     })
158
159 end
160 end
161 end
162 end
163 end
164 end
165
166
167 function frame_motor1_on(pos,node)
168     local npos={x=pos.x,y=pos.y+1,z=pos.z}
169     local nnode=minetest.env:get_node(npos)
170     if node.param2==0 then
171         dir={x=1,y=0,z=0}
172     elseif node.param2==1 then
173         dir={x=0,y=0,z=-1}
174     elseif node.param2==2 then
175         dir={x=-1,y=0,z=0}
176     else
177         dir={x=0,y=0,z=1}
178     end
179     if minetest.registered_nodes[nnode.name].frame==1 then
180         local connected_nodes=get_connected_nodes(npos)
181         move_nodes_vect(connected_nodes,dir)
182     end
183 end
184
185 function frame_motor2_on(pos,node)
186     local npos={x=pos.x,y=pos.y-1,z=pos.z}
187     local nnode=minetest.env:get_node(npos)
188     if node.param2==0 then
189         dir={x=1,y=0,z=0}
190     elseif node.param2==1 then
191         dir={x=0,y=0,z=-1}
192     elseif node.param2==2 then
193         dir={x=-1,y=0,z=0}
194     else
195         dir={x=0,y=0,z=1}
196     end
197     if minetest.registered_nodes[nnode.name].frame==1 then
198         local connected_nodes=get_connected_nodes(npos)
199         move_nodes_vect(connected_nodes,dir)
200     end
201 end
202
203 function frame_motor3_on(pos,node)
204     local npos={x=pos.x,y=pos.y,z=pos.z}
205     if node.param2==0 then
206         dir={x=1,y=0,z=0}
207         npos.z=npos.z-1
208     elseif node.param2==1 then
209         dir={x=0,y=0,z=-1}
210         npos.x=npos.x-1
211     elseif node.param2==2 then
212         dir={x=-1,y=0,z=0}
213         npos.z=npos.z+1
214     else
215         dir={x=0,y=0,z=1}
216         npos.x=npos.x+1
217     end
218     local nnode=minetest.env:get_node(npos)
219     if minetest.registered_nodes[nnode.name].frame==1 then
220         local connected_nodes=get_connected_nodes(npos)
221         move_nodes_vect(connected_nodes,dir)
222     end
223 end
224
225 function frame_motor4_on(pos,node)
226     local npos={x=pos.x,y=pos.y,z=pos.z}
227     if node.param2==0 then
228         dir={x=-1,y=0,z=0}
229         npos.z=npos.z-1
230     elseif node.param2==1 then
231         dir={x=0,y=0,z=1}
232         npos.x=npos.x-1
233     elseif node.param2==2 then
234         dir={x=1,y=0,z=0}
235         npos.z=npos.z+1
236     else
237         dir={x=0,y=0,z=-1}
238         npos.x=npos.x+1
239     end
240     local nnode=minetest.env:get_node(npos)
241     if minetest.registered_nodes[nnode.name].frame==1 then
242         local connected_nodes=get_connected_nodes(npos)
243         move_nodes_vect(connected_nodes,dir)
244     end
245 end
246
247 function frame_motor5_on(pos,node)
248     local npos={x=pos.x,y=pos.y,z=pos.z}
249     if node.param2==0 then
250         npos.z=npos.z-1
251     elseif node.param2==1 then
252         npos.x=npos.x-1
253     elseif node.param2==2 then
254         npos.z=npos.z+1
255     else
256         npos.x=npos.x+1
257     end
258     dir={x=0,y=1,z=0}
259     local nnode=minetest.env:get_node(npos)
260     if minetest.registered_nodes[nnode.name].frame==1 then
261         local connected_nodes=get_connected_nodes(npos)
262         move_nodes_vect(connected_nodes,dir)
263     end
264 end
265
266 function frame_motor6_on(pos,node)
267     local npos={x=pos.x,y=pos.y,z=pos.z}
268     if node.param2==0 then
269         npos.z=npos.z-1
270     elseif node.param2==1 then
271         npos.x=npos.x-1
272     elseif node.param2==2 then
273         npos.z=npos.z+1
274     else
275         npos.x=npos.x+1
276     end
277     dir={x=0,y=-1,z=0}
278     local nnode=minetest.env:get_node(npos)
279     if minetest.registered_nodes[nnode.name].frame==1 then
280         local connected_nodes=get_connected_nodes(npos)
281         move_nodes_vect(connected_nodes,dir)
282     end
283 end
284
285
286 minetest.register_node("technic:frame_motor1",{
287     description = "Frame motor 1",
288     tiles = {"pipeworks_filter_top.png", "technic_lv_cable.png", "technic_lv_cable.png",
289         "technic_lv_cable.png", "technic_lv_cable.png", "technic_lv_cable.png"},
290     groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,mesecon=2},
291     paramtype2 = "facedir",
292     mesecons={effector={action_on=frame_motor1_on}},
293     frames_can_connect=function(pos,dir)
294         return dir.y~=-1
295     end
296 })
297
298 minetest.register_node("technic:frame_motor2",{
299     description = "Frame motor 2",
300     tiles = {"technic_lv_cable.png", "pipeworks_filter_top.png", "technic_lv_cable.png",
301         "technic_lv_cable.png", "technic_lv_cable.png", "technic_lv_cable.png"},
302     groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,mesecon=2},
303     paramtype2 = "facedir",
304     mesecons={effector={action_on=frame_motor2_on}},
305     frames_can_connect=function(pos,dir)
306         return dir.y~=1
307     end
308 })
309
310 minetest.register_node("technic:frame_motor3",{
311     description = "Frame motor 3",
312     tiles = {"technic_lv_cable.png", "technic_lv_cable.png", "technic_lv_cable.png",
313         "technic_lv_cable.png", "technic_lv_cable.png", "pipeworks_filter_top.png"},
314     groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,mesecon=2},
315     paramtype2 = "facedir",
316     mesecons={effector={action_on=frame_motor3_on}},
317     frames_can_connect=function(pos,dir)
318         local node=minetest.env:get_node(pos)
319         if node.param2==0 then return dir.z~=1
320         elseif node.param2==1 then return dir.x~=1
321         elseif node.param2==2 then return dir.z~=-1
322         else return dir.x~=-1 end
323     end
324 })
325
326 minetest.register_node("technic:frame_motor4",{
327     description = "Frame motor 4",
328     tiles = {"technic_lv_cable.png", "technic_lv_cable.png", "technic_lv_cable.png",
329         "technic_lv_cable.png", "technic_lv_cable.png", "pipeworks_filter_top.png"},
330     groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,mesecon=2},
331     paramtype2 = "facedir",
332     mesecons={effector={action_on=frame_motor4_on}},
333     frames_can_connect=function(pos,dir)
334         local node=minetest.env:get_node(pos)
335         if node.param2==0 then return dir.z~=1
336         elseif node.param2==1 then return dir.x~=1
337         elseif node.param2==2 then return dir.z~=-1
338         else return dir.x~=-1 end
339     end
340 })
341
342 minetest.register_node("technic:frame_motor5",{
343     description = "Frame motor 5",
344     tiles = {"technic_lv_cable.png", "technic_lv_cable.png", "technic_lv_cable.png",
345         "technic_lv_cable.png", "technic_lv_cable.png", "pipeworks_filter_top.png"},
346     groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,mesecon=2},
347     paramtype2 = "facedir",
348     mesecons={effector={action_on=frame_motor5_on}},
349     frames_can_connect=function(pos,dir)
350         local node=minetest.env:get_node(pos)
351         if node.param2==0 then return dir.z~=1
352         elseif node.param2==1 then return dir.x~=1
353         elseif node.param2==2 then return dir.z~=-1
354         else return dir.x~=-1 end
355     end
356 })
357
358 minetest.register_node("technic:frame_motor6",{
359     description = "Frame motor 6",
360     tiles = {"technic_lv_cable.png", "technic_lv_cable.png", "technic_lv_cable.png",
361         "technic_lv_cable.png", "technic_lv_cable.png", "pipeworks_filter_top.png"},
362     groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,mesecon=2},
363     paramtype2 = "facedir",
364     mesecons={effector={action_on=frame_motor6_on}},
365     frames_can_connect=function(pos,dir)
366         local node=minetest.env:get_node(pos)
367         if node.param2==0 then return dir.z~=1
368         elseif node.param2==1 then return dir.x~=1
369         elseif node.param2==2 then return dir.z~=-1
370         else return dir.x~=-1 end
371     end
372 })
373
374
375
376
377 function move_nodes_vect(poslist,vect)
378     for _,pos in ipairs(poslist) do
379         local npos=addVect(pos,vect)
380         if minetest.env:get_node(npos).name~="air" and not(pos_in_list(poslist,npos)) then return end
381     end
382     nodelist={}
383     for _,pos in ipairs(poslist) do
384         local node=minetest.env:get_node(pos)
385         local meta=minetest.env:get_meta(pos):to_table()
386         nodelist[#(nodelist)+1]={pos=pos,node=node,meta=meta}
387         minetest.env:remove_node(pos)
388     end
389     for _,n in ipairs(nodelist) do
390         local npos=addVect(n.pos,vect)
391         minetest.env:set_node(npos,n.node)
392         local meta=minetest.env:get_meta(npos)
393         meta:from_table(n.meta)
394     end
395 end
396
397 function get_connected_nodes(pos)
398     c={pos}
399     local nodename=minetest.env:get_node(pos).name
400     connected(pos,c,minetest.registered_nodes[nodename].frame_connect_all(pos))
401     return c
402 end
403
404 function addVect(pos,vect)
405     return {x=pos.x+vect.x,y=pos.y+vect.y,z=pos.z+vect.z}
406 end
407
408 function pos_in_list(l,pos)
409     for _,p in ipairs(l) do
410         if p.x==pos.x and p.y==pos.y and p.z==pos.z then return true end
411     end
412     return false
413 end
414
415 function connected(pos,c,adj)
416     for _,vect in ipairs(adj) do
417         local pos1=addVect(pos,vect)
418         local nodename=minetest.env:get_node(pos1).name
419         if not(pos_in_list(c,pos1)) and nodename~="air" and
420         (minetest.registered_nodes[nodename].frames_can_connect==nil or
421         minetest.registered_nodes[nodename].frames_can_connect(pos1,vect)) then
422             c[#(c)+1]=pos1
423             if minetest.registered_nodes[nodename].frame==1 then
424                 local adj=minetest.registered_nodes[nodename].frame_connect_all(pos1)
425                 connected(pos1,c,adj)
426             end
427         end
428     end
429 end
430