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