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