commit | author | age
|
354ee6
|
1 |
|
S |
2 |
local S = technic.getter |
|
3 |
|
c06cdf
|
4 |
frames = {} |
1524a9
|
5 |
|
c06cdf
|
6 |
-- Helpers |
N |
7 |
|
|
8 |
local function get_face(pos,ppos,pvect) |
|
9 |
-- Raytracer to get which face has been clicked |
478407
|
10 |
ppos={x=ppos.x-pos.x,y=ppos.y-pos.y+1.5,z=ppos.z-pos.z} |
R |
11 |
if pvect.x>0 then |
|
12 |
local t=(-0.5-ppos.x)/pvect.x |
|
13 |
local y_int=ppos.y+t*pvect.y |
|
14 |
local z_int=ppos.z+t*pvect.z |
|
15 |
if y_int>-0.4 and y_int<0.4 and z_int>-0.4 and z_int<0.4 then return 1 end |
|
16 |
elseif pvect.x<0 then |
|
17 |
local t=(0.5-ppos.x)/pvect.x |
|
18 |
local y_int=ppos.y+t*pvect.y |
|
19 |
local z_int=ppos.z+t*pvect.z |
|
20 |
if y_int>-0.4 and y_int<0.4 and z_int>-0.4 and z_int<0.4 then return 2 end |
|
21 |
end |
|
22 |
if pvect.y>0 then |
|
23 |
local t=(-0.5-ppos.y)/pvect.y |
|
24 |
local x_int=ppos.x+t*pvect.x |
|
25 |
local z_int=ppos.z+t*pvect.z |
|
26 |
if x_int>-0.4 and x_int<0.4 and z_int>-0.4 and z_int<0.4 then return 3 end |
|
27 |
elseif pvect.y<0 then |
|
28 |
local t=(0.5-ppos.y)/pvect.y |
|
29 |
local x_int=ppos.x+t*pvect.x |
|
30 |
local z_int=ppos.z+t*pvect.z |
|
31 |
if x_int>-0.4 and x_int<0.4 and z_int>-0.4 and z_int<0.4 then return 4 end |
|
32 |
end |
|
33 |
if pvect.z>0 then |
|
34 |
local t=(-0.5-ppos.z)/pvect.z |
|
35 |
local x_int=ppos.x+t*pvect.x |
|
36 |
local y_int=ppos.y+t*pvect.y |
|
37 |
if x_int>-0.4 and x_int<0.4 and y_int>-0.4 and y_int<0.4 then return 5 end |
|
38 |
elseif pvect.z<0 then |
|
39 |
local t=(0.5-ppos.z)/pvect.z |
|
40 |
local x_int=ppos.x+t*pvect.x |
|
41 |
local y_int=ppos.y+t*pvect.y |
|
42 |
if x_int>-0.4 and x_int<0.4 and y_int>-0.4 and y_int<0.4 then return 6 end |
|
43 |
end |
|
44 |
end |
|
45 |
|
5cf765
|
46 |
local function lines(str) |
808d38
|
47 |
local t = {} |
N |
48 |
local function helper(line) table.insert(t, line) return "" end |
|
49 |
helper((str:gsub("(.-)\r?\n", helper))) |
|
50 |
return t |
|
51 |
end |
|
52 |
|
|
53 |
local function pos_to_string(pos) |
|
54 |
if pos.x == 0 then pos.x = 0 end -- Fix for signed 0 |
|
55 |
if pos.y == 0 then pos.y = 0 end -- Fix for signed 0 |
|
56 |
if pos.z == 0 then pos.z = 0 end -- Fix for signed 0 |
|
57 |
return tostring(pos.x).."\n"..tostring(pos.y).."\n"..tostring(pos.z) |
|
58 |
end |
|
59 |
|
|
60 |
local function pos_from_string(str) |
|
61 |
local l = lines(str) |
|
62 |
return {x = tonumber(l[1]), y = tonumber(l[2]), z = tonumber(l[3])} |
|
63 |
end |
|
64 |
|
c06cdf
|
65 |
local function pos_in_list(l,pos) |
N |
66 |
for _,p in ipairs(l) do |
|
67 |
if p.x==pos.x and p.y==pos.y and p.z==pos.z then return true end |
|
68 |
end |
|
69 |
return false |
808d38
|
70 |
end |
N |
71 |
|
|
72 |
local function table_empty(table) |
|
73 |
for _, __ in pairs(table) do |
|
74 |
return false |
|
75 |
end |
|
76 |
return true |
c06cdf
|
77 |
end |
478407
|
78 |
|
c06cdf
|
79 |
local function add_table(table,toadd) |
N |
80 |
local i=1 |
|
81 |
while true do |
|
82 |
o=table[i] |
|
83 |
if o==toadd then return end |
|
84 |
if o==nil then break end |
|
85 |
i=i+1 |
|
86 |
end |
|
87 |
table[i]=toadd |
|
88 |
end |
|
89 |
|
3cf0d3
|
90 |
local function move_nodes_vect(poslist,vect,must_not_move,owner) |
N |
91 |
if minetest.is_protected then |
|
92 |
for _,pos in ipairs(poslist) do |
66e4b5
|
93 |
local npos=vector.add(pos,vect) |
3cf0d3
|
94 |
if minetest.is_protected(pos, owner) or minetest.is_protected(npos, owner) then |
N |
95 |
return |
|
96 |
end |
|
97 |
end |
|
98 |
end |
c06cdf
|
99 |
for _,pos in ipairs(poslist) do |
N |
100 |
local npos=vector.add(pos,vect) |
|
101 |
local name = minetest.env:get_node(npos).name |
|
102 |
if (name~="air" and minetest.registered_nodes[name].liquidtype=="none") and not(pos_in_list(poslist,npos)) then |
|
103 |
return |
|
104 |
end |
a73d56
|
105 |
--[[if pos.x==must_not_move.x and pos.y==must_not_move.y and pos.z==must_not_move.z then |
c06cdf
|
106 |
return |
a73d56
|
107 |
end]] |
c06cdf
|
108 |
end |
N |
109 |
nodelist={} |
|
110 |
for _,pos in ipairs(poslist) do |
|
111 |
local node=minetest.env:get_node(pos) |
|
112 |
local meta=minetest.env:get_meta(pos):to_table() |
|
113 |
nodelist[#(nodelist)+1]={pos=pos,node=node,meta=meta} |
|
114 |
end |
|
115 |
objects={} |
|
116 |
for _,pos in ipairs(poslist) do |
|
117 |
for _,object in ipairs(minetest.env:get_objects_inside_radius(pos, 1)) do |
|
118 |
add_table(objects,object) |
|
119 |
end |
|
120 |
end |
|
121 |
for _,obj in ipairs(objects) do |
|
122 |
obj:setpos(vector.add(obj:getpos(),vect)) |
|
123 |
le=obj:get_luaentity() |
|
124 |
if le and le.name == "pipeworks:tubed_item" then |
|
125 |
le.start_pos=vector.add(le.start_pos,vect) |
|
126 |
end |
|
127 |
end |
|
128 |
for _,n in ipairs(nodelist) do |
|
129 |
local npos=vector.add(n.pos,vect) |
|
130 |
minetest.env:set_node(npos,n.node) |
|
131 |
local meta=minetest.env:get_meta(npos) |
|
132 |
meta:from_table(n.meta) |
|
133 |
for __,pos in ipairs(poslist) do |
|
134 |
if npos.x==pos.x and npos.y==pos.y and npos.z==pos.z then |
|
135 |
table.remove(poslist, __) |
|
136 |
break |
|
137 |
end |
|
138 |
end |
|
139 |
end |
|
140 |
for __,pos in ipairs(poslist) do |
|
141 |
minetest.env:remove_node(pos) |
|
142 |
end |
|
143 |
end |
|
144 |
|
|
145 |
|
|
146 |
|
|
147 |
-- Frames |
478407
|
148 |
for xm=0,1 do |
R |
149 |
for xp=0,1 do |
|
150 |
for ym=0,1 do |
|
151 |
for yp=0,1 do |
|
152 |
for zm=0,1 do |
|
153 |
for zp=0,1 do |
|
154 |
|
|
155 |
local a=8/16 |
|
156 |
local b=7/16 |
|
157 |
local nodeboxes= { |
|
158 |
{ -a, -a, -a, -b, a, -b }, |
|
159 |
{ -a, -a, b, -b, a, a }, |
|
160 |
{ b, -a, b, a, a, a }, |
|
161 |
{ b, -a, -a, a, a, -b }, |
|
162 |
|
|
163 |
{ -b, b, -a, b, a, -b }, |
|
164 |
{ -b, -a, -a, b, -b, -b }, |
|
165 |
|
|
166 |
{ -b, b, b, b, a, a }, |
|
167 |
{ -b, -a, b, b, -b, a }, |
|
168 |
|
|
169 |
{ b, b, -b, a, a, b }, |
|
170 |
{ b, -a, -b, a, -b, b }, |
|
171 |
|
|
172 |
{ -a, b, -b, -b, a, b }, |
|
173 |
{ -a, -a, -b, -b, -b, b }, |
|
174 |
} |
|
175 |
|
|
176 |
if yp==0 then |
|
177 |
table.insert(nodeboxes, {-b,b,-b, b,a,b}) |
|
178 |
end |
|
179 |
if ym==0 then |
|
180 |
table.insert(nodeboxes, {-b,-a,-b, b,-b,b}) |
|
181 |
end |
|
182 |
if xp==0 then |
|
183 |
table.insert(nodeboxes, {b,b,b,a,-b,-b}) |
|
184 |
end |
|
185 |
if xm==0 then |
|
186 |
table.insert(nodeboxes, {-a,-b,-b,-b,b,b}) |
|
187 |
end |
|
188 |
if zp==0 then |
|
189 |
table.insert(nodeboxes, {-b,-b,b, b,b,a}) |
|
190 |
end |
|
191 |
if zm==0 then |
|
192 |
table.insert(nodeboxes, {-b,-b,-a, b,b,-b}) |
|
193 |
end |
|
194 |
|
|
195 |
local nameext=tostring(xm)..tostring(xp)..tostring(ym)..tostring(yp)..tostring(zm)..tostring(zp) |
|
196 |
local groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2} |
|
197 |
if nameext~="111111" then groups.not_in_creative_inventory=1 end |
|
198 |
|
|
199 |
|
|
200 |
minetest.register_node("technic:frame_"..nameext,{ |
354ee6
|
201 |
description = S("Frame"), |
478407
|
202 |
tiles = {"technic_frame.png"}, |
R |
203 |
groups=groups, |
|
204 |
drawtype = "nodebox", |
|
205 |
node_box = { |
|
206 |
type = "fixed", |
|
207 |
fixed=nodeboxes, |
|
208 |
}, |
3a5215
|
209 |
selection_box = { |
N |
210 |
type="fixed", |
|
211 |
fixed={-0.5,-0.5,-0.5,0.5,0.5,0.5} |
|
212 |
}, |
478407
|
213 |
paramtype = "light", |
R |
214 |
frame=1, |
|
215 |
drop="technic:frame_111111", |
|
216 |
frame_connect_all=function(pos) |
|
217 |
local nodename=minetest.env:get_node(pos).name |
|
218 |
l2={} |
|
219 |
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}} |
|
220 |
for i,dir in ipairs(l1) do |
|
221 |
if string.sub(nodename,-7+i,-7+i)=="1" then |
|
222 |
l2[#(l2)+1]=dir |
|
223 |
end |
|
224 |
end |
|
225 |
return l2 |
|
226 |
end, |
|
227 |
on_punch=function(pos,node,puncher) |
|
228 |
local ppos=puncher:getpos() |
|
229 |
local pvect=puncher:get_look_dir() |
|
230 |
local pface=get_face(pos,ppos,pvect) |
|
231 |
if pface==nil then return end |
|
232 |
local nodename=node.name |
|
233 |
local newstate=tostring(1-tonumber(string.sub(nodename,-7+pface,-7+pface))) |
|
234 |
if pface<=5 then |
|
235 |
nodename=string.sub(nodename,1,-7+pface-1)..newstate..string.sub(nodename,-7+pface+1) |
|
236 |
else |
|
237 |
nodename=string.sub(nodename,1,-2)..newstate |
|
238 |
end |
|
239 |
node.name=nodename |
|
240 |
minetest.env:set_node(pos,node) |
|
241 |
end |
|
242 |
}) |
|
243 |
|
|
244 |
end |
|
245 |
end |
|
246 |
end |
|
247 |
end |
|
248 |
end |
|
249 |
end |
|
250 |
|
c06cdf
|
251 |
|
N |
252 |
|
|
253 |
|
|
254 |
-- Frame motor |
|
255 |
local function connected(pos,c,adj) |
|
256 |
for _,vect in ipairs(adj) do |
|
257 |
local pos1=vector.add(pos,vect) |
|
258 |
local nodename=minetest.env:get_node(pos1).name |
|
259 |
if not(pos_in_list(c,pos1)) and nodename~="air" and |
|
260 |
(minetest.registered_nodes[nodename].frames_can_connect==nil or |
|
261 |
minetest.registered_nodes[nodename].frames_can_connect(pos1,vect)) then |
|
262 |
c[#(c)+1]=pos1 |
|
263 |
if minetest.registered_nodes[nodename].frame==1 then |
|
264 |
local adj=minetest.registered_nodes[nodename].frame_connect_all(pos1) |
|
265 |
connected(pos1,c,adj) |
|
266 |
end |
|
267 |
end |
|
268 |
end |
|
269 |
end |
|
270 |
|
|
271 |
local function get_connected_nodes(pos) |
|
272 |
c={pos} |
|
273 |
local nodename=minetest.env:get_node(pos).name |
|
274 |
connected(pos,c,minetest.registered_nodes[nodename].frame_connect_all(pos)) |
|
275 |
return c |
|
276 |
end |
|
277 |
|
|
278 |
local function frame_motor_on(pos, node) |
48ea6f
|
279 |
local dirs = {{x=0,y=1,z=0},{x=0,y=0,z=1},{x=0,y=0,z=-1},{x=1,y=0,z=0},{x=-1,y=0,z=0},{x=0,y=-1,z=0}} |
c06cdf
|
280 |
local nnodepos = vector.add(pos, dirs[math.floor(node.param2/4)+1]) |
48ea6f
|
281 |
local dir = minetest.facedir_to_dir(node.param2) |
N |
282 |
local nnode=minetest.get_node(nnodepos) |
a579ee
|
283 |
local meta = minetest.get_meta(pos) |
N |
284 |
local owner = meta:get_string("owner") |
478407
|
285 |
if minetest.registered_nodes[nnode.name].frame==1 then |
48ea6f
|
286 |
local connected_nodes=get_connected_nodes(nnodepos) |
a579ee
|
287 |
move_nodes_vect(connected_nodes,dir,pos,owner) |
478407
|
288 |
end |
R |
289 |
end |
|
290 |
|
48ea6f
|
291 |
minetest.register_node("technic:frame_motor",{ |
354ee6
|
292 |
description = S("Frame Motor"), |
48ea6f
|
293 |
tiles = {"pipeworks_filter_top.png^[transformR90", "technic_lv_cable.png", "technic_lv_cable.png", |
478407
|
294 |
"technic_lv_cable.png", "technic_lv_cable.png", "technic_lv_cable.png"}, |
R |
295 |
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,mesecon=2}, |
|
296 |
paramtype2 = "facedir", |
48ea6f
|
297 |
mesecons={effector={action_on=frame_motor_on}}, |
a579ee
|
298 |
after_place_node = function(pos, placer, itemstack) |
N |
299 |
local meta = minetest.get_meta(pos) |
|
300 |
meta:set_string("owner", placer:get_player_name()) |
|
301 |
end, |
478407
|
302 |
frames_can_connect=function(pos,dir) |
48ea6f
|
303 |
local node = minetest.get_node(pos) |
N |
304 |
local dir2 = ({{x=0,y=1,z=0},{x=0,y=0,z=1},{x=0,y=0,z=-1},{x=1,y=0,z=0},{x=-1,y=0,z=0},{x=0,y=-1,z=0}})[math.floor(node.param2/4)+1] |
|
305 |
return dir2.x~=-dir.x or dir2.y~=-dir.y or dir2.z~=-dir.z |
478407
|
306 |
end |
R |
307 |
}) |
|
308 |
|
|
309 |
|
c06cdf
|
310 |
|
N |
311 |
-- Templates |
808d38
|
312 |
local function template_connected(pos,c,connectors) |
c06cdf
|
313 |
for _,vect in ipairs({{x=0,y=1,z=0},{x=0,y=0,z=1},{x=0,y=0,z=-1},{x=1,y=0,z=0},{x=-1,y=0,z=0},{x=0,y=-1,z=0}}) do |
N |
314 |
local pos1=vector.add(pos,vect) |
|
315 |
local nodename=minetest.get_node(pos1).name |
808d38
|
316 |
if not(pos_in_list(c,pos1)) and (nodename=="technic:template" or nodename == "technic:template_connector")then |
a73d56
|
317 |
local meta = minetest.get_meta(pos1) |
N |
318 |
if meta:get_string("connected") == "" then |
|
319 |
c[#(c)+1]=pos1 |
808d38
|
320 |
template_connected(pos1,c,connectors) |
N |
321 |
if nodename == "technic:template_connector" then |
|
322 |
connectors[#connectors+1] = pos1 |
|
323 |
end |
a73d56
|
324 |
end |
a579ee
|
325 |
end |
478407
|
326 |
end |
R |
327 |
end |
|
328 |
|
c06cdf
|
329 |
local function get_templates(pos) |
808d38
|
330 |
local c = {pos} |
N |
331 |
local connectors |
|
332 |
if minetest.get_node(pos).name == "technic:template_connector" then |
|
333 |
connectors = {pos} |
|
334 |
else |
|
335 |
connectors = {} |
|
336 |
end |
|
337 |
template_connected(pos,c,connectors) |
|
338 |
return c, connectors |
|
339 |
end |
|
340 |
|
|
341 |
local function swap_template(pos, new) |
|
342 |
local meta = minetest.get_meta(pos) |
|
343 |
local saved_node = meta:get_string("saved_node") |
|
344 |
meta:set_string("saved_node", "") |
f3d8b4
|
345 |
technic.swap_node(pos, new) |
808d38
|
346 |
local meta = minetest.get_meta(pos) |
N |
347 |
meta:set_string("saved_node", saved_node) |
478407
|
348 |
end |
R |
349 |
|
c06cdf
|
350 |
local function save_node(pos) |
N |
351 |
local node = minetest.get_node(pos) |
808d38
|
352 |
if node.name == "air" then |
N |
353 |
minetest.set_node(pos, {name="technic:template"}) |
|
354 |
return |
|
355 |
end |
|
356 |
if node.name == "technic:template" then |
|
357 |
swap_template(pos, "technic:template_connector") |
|
358 |
local meta = minetest.get_meta(pos) |
|
359 |
meta:set_string("connected", "") |
|
360 |
return |
|
361 |
end |
c06cdf
|
362 |
local meta = minetest.get_meta(pos) |
N |
363 |
local meta0 = meta:to_table() |
|
364 |
for _, list in pairs(meta0.inventory) do |
|
365 |
for key, stack in pairs(list) do |
|
366 |
list[key] = stack:to_string() |
|
367 |
end |
478407
|
368 |
end |
c06cdf
|
369 |
node.meta = meta0 |
808d38
|
370 |
minetest.set_node(pos, {name="technic:template"}) |
c06cdf
|
371 |
return node |
478407
|
372 |
end |
R |
373 |
|
c06cdf
|
374 |
local function restore_node(pos, node) |
N |
375 |
minetest.set_node(pos, node) |
|
376 |
local meta = minetest.get_meta(pos) |
|
377 |
for _, list in pairs(node.meta.inventory) do |
|
378 |
for key, stack in pairs(list) do |
|
379 |
list[key] = ItemStack(stack) |
|
380 |
end |
|
381 |
end |
|
382 |
meta:from_table(node.meta) |
|
383 |
end |
|
384 |
|
|
385 |
local function expand_template(pos) |
|
386 |
local meta = minetest.get_meta(pos) |
|
387 |
local c = meta:get_string("connected") |
|
388 |
if c == "" then return end |
|
389 |
c = minetest.deserialize(c) |
|
390 |
for _, vect in ipairs(c) do |
808d38
|
391 |
local pos1 = vector.add(pos, vect) |
N |
392 |
local saved_node = save_node(pos1) |
|
393 |
local meta1 = minetest.get_meta(pos1) |
|
394 |
if saved_node ~= nil then |
|
395 |
meta1:set_string("saved_node", minetest.serialize(saved_node)) |
|
396 |
else |
|
397 |
--meta1:set_string("saved_node", "") |
|
398 |
end |
|
399 |
end |
|
400 |
end |
|
401 |
|
|
402 |
local function compress_templates(pos) |
|
403 |
local templates, connectors = get_templates(pos) |
|
404 |
if #connectors == 0 then |
|
405 |
connectors = {pos} |
|
406 |
end |
|
407 |
for _, cn in ipairs(connectors) do |
|
408 |
local meta = minetest.get_meta(cn) |
|
409 |
local c = {} |
|
410 |
for _,p in ipairs(templates) do |
|
411 |
local np = vector.subtract(p, cn) |
|
412 |
if not pos_in_list(c,np) then |
|
413 |
c[#c+1] = np |
478407
|
414 |
end |
808d38
|
415 |
end |
N |
416 |
local cc = {} |
|
417 |
for _,p in ipairs(connectors) do |
|
418 |
local np = vector.subtract(p, cn) |
|
419 |
if (np.x ~= 0 or np.y ~= 0 or np.z ~= 0) then |
|
420 |
cc[pos_to_string(np)] = true |
|
421 |
end |
|
422 |
end |
|
423 |
swap_template(cn, "technic:template") |
|
424 |
meta:set_string("connected", minetest.serialize(c)) |
|
425 |
meta:set_string("connectors_connected", minetest.serialize(cc)) |
|
426 |
end |
|
427 |
|
|
428 |
for _,p in ipairs(templates) do |
|
429 |
if not pos_in_list(connectors, p) then |
|
430 |
minetest.set_node(p, {name = "air"}) |
478407
|
431 |
end |
R |
432 |
end |
|
433 |
end |
|
434 |
|
48d571
|
435 |
local function template_drops(pos, node, oldmeta, digger) |
N |
436 |
local c = oldmeta.fields.connected |
808d38
|
437 |
local cc = oldmeta.fields.connectors_connected |
48d571
|
438 |
local drops |
N |
439 |
if c == "" or c == nil then |
|
440 |
drops = {"technic:template 1"} |
|
441 |
else |
808d38
|
442 |
if cc == "" or cc == nil then |
N |
443 |
drops = {"technic:template 1"} |
|
444 |
else |
|
445 |
local dcc = minetest.deserialize(cc) |
|
446 |
if not table_empty(dcc) then |
|
447 |
drops = {} |
|
448 |
for sp, _ in pairs(dcc) do |
|
449 |
local ssp = pos_from_string(sp) |
|
450 |
local p = vector.add(ssp, pos) |
|
451 |
local meta = minetest.get_meta(p) |
|
452 |
local d = minetest.deserialize(meta:get_string("connectors_connected")) |
|
453 |
if d ~= nil then |
|
454 |
d[pos_to_string({x=-ssp.x, y=-ssp.y, z=-ssp.z})] = nil |
|
455 |
meta:set_string("connectors_connected", minetest.serialize(d)) |
|
456 |
end |
|
457 |
end |
|
458 |
else |
|
459 |
local stack_max = 99 |
|
460 |
local num = #(minetest.deserialize(c)) |
|
461 |
drops = {} |
|
462 |
while num > stack_max do |
|
463 |
drops[#drops+1] = "technic:template "..stack_max |
|
464 |
num = num - stack_max |
|
465 |
end |
|
466 |
drops[#drops+1] = "technic:template "..num |
|
467 |
end |
48d571
|
468 |
end |
N |
469 |
end |
|
470 |
minetest.handle_node_drops(pos, drops, digger) |
808d38
|
471 |
end |
N |
472 |
|
|
473 |
local function template_on_destruct(pos, node) |
|
474 |
local meta = minetest.get_meta(pos) |
|
475 |
local saved_node = meta:get_string("saved_node") |
|
476 |
if saved_node ~= "" then |
|
477 |
local nnode = minetest.deserialize(saved_node) |
|
478 |
minetest.after(0, restore_node, pos, nnode) |
|
479 |
end |
48d571
|
480 |
end |
N |
481 |
|
c06cdf
|
482 |
minetest.register_node("technic:template",{ |
354ee6
|
483 |
description = S("Template"), |
c06cdf
|
484 |
tiles = {"technic_mv_cable.png"}, |
48d571
|
485 |
drop = "", |
c06cdf
|
486 |
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2}, |
808d38
|
487 |
on_destruct = template_on_destruct, |
48d571
|
488 |
after_dig_node = template_drops, |
c06cdf
|
489 |
on_punch = function(pos,node,puncher) |
808d38
|
490 |
swap_template(pos, "technic:template_disabled") |
c06cdf
|
491 |
end |
N |
492 |
}) |
|
493 |
|
|
494 |
minetest.register_node("technic:template_disabled",{ |
354ee6
|
495 |
description = S("Template"), |
c06cdf
|
496 |
tiles = {"technic_hv_cable.png"}, |
48d571
|
497 |
drop = "", |
808d38
|
498 |
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,not_in_creative_inventory=1}, |
N |
499 |
on_destruct = template_on_destruct, |
48d571
|
500 |
after_dig_node = template_drops, |
c06cdf
|
501 |
on_punch = function(pos,node,puncher) |
808d38
|
502 |
local meta = minetest.get_meta(pos) |
N |
503 |
swap_template(pos, "technic:template_connector") |
|
504 |
end |
|
505 |
}) |
|
506 |
|
|
507 |
minetest.register_node("technic:template_connector",{ |
354ee6
|
508 |
description = S("Template"), |
808d38
|
509 |
tiles = {"technic_lv_cable.png"}, |
N |
510 |
drop = "", |
|
511 |
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,not_in_creative_inventory=1}, |
|
512 |
on_destruct = template_on_destruct, |
|
513 |
after_dig_node = template_drops, |
|
514 |
on_punch = function(pos,node,puncher) |
|
515 |
swap_template(pos, "technic:template") |
c06cdf
|
516 |
end |
N |
517 |
}) |
|
518 |
|
|
519 |
minetest.register_craftitem("technic:template_replacer",{ |
354ee6
|
520 |
description = S("Template (replacing)"), |
c06cdf
|
521 |
inventory_image = "technic_template_replacer.png", |
N |
522 |
on_place = function(itemstack, placer, pointed_thing) |
|
523 |
local p = pointed_thing.under |
|
524 |
if minetest.is_protected and minetest.is_protected(p, placer:get_player_name()) then |
|
525 |
return nil |
|
526 |
end |
|
527 |
local node = minetest.get_node(p) |
|
528 |
if node.name == "technic:template" then return end |
|
529 |
local saved_node = save_node(p) |
|
530 |
itemstack:take_item() |
|
531 |
if saved_node ~= nil then |
|
532 |
local meta = minetest.get_meta(p) |
|
533 |
meta:set_string("saved_node", minetest.serialize(saved_node)) |
|
534 |
end |
|
535 |
return itemstack |
|
536 |
end |
|
537 |
}) |
|
538 |
|
|
539 |
minetest.register_tool("technic:template_tool",{ |
354ee6
|
540 |
description = S("Template tool"), |
c06cdf
|
541 |
inventory_image = "technic_template_tool.png", |
N |
542 |
on_use = function(itemstack, puncher, pointed_thing) |
|
543 |
local pos = pointed_thing.under |
a73d56
|
544 |
if pos == nil or (minetest.is_protected and minetest.is_protected(pos, placer:get_player_name())) then |
c06cdf
|
545 |
return nil |
N |
546 |
end |
|
547 |
local node = minetest.get_node(pos) |
808d38
|
548 |
if node.name ~= "technic:template" and node.name ~= "technic:template_connector" then return end |
c06cdf
|
549 |
local meta = minetest.get_meta(pos) |
N |
550 |
local c2 = meta:get_string("connected") |
|
551 |
if c2 ~= "" then |
|
552 |
expand_template(pos) |
808d38
|
553 |
else |
N |
554 |
compress_templates(pos) |
c06cdf
|
555 |
end |
808d38
|
556 |
|
c06cdf
|
557 |
end |
N |
558 |
}) |
|
559 |
|
|
560 |
|
|
561 |
|
|
562 |
-- Template motor |
|
563 |
local function get_template_nodes(pos) |
|
564 |
local meta = minetest.get_meta(pos) |
|
565 |
local connected = meta:get_string("connected") |
|
566 |
if connected == "" then return {} end |
|
567 |
local adj = minetest.deserialize(connected) |
|
568 |
local c = {} |
|
569 |
for _,vect in ipairs(adj) do |
|
570 |
local pos1=vector.add(pos,vect) |
|
571 |
local nodename=minetest.env:get_node(pos1).name |
|
572 |
if not(pos_in_list(c,pos1)) and nodename~="air" then |
|
573 |
c[#(c)+1]=pos1 |
|
574 |
end |
|
575 |
end |
|
576 |
return c |
|
577 |
end |
|
578 |
|
|
579 |
local function template_motor_on(pos, node) |
|
580 |
local dirs = {{x=0,y=1,z=0},{x=0,y=0,z=1},{x=0,y=0,z=-1},{x=1,y=0,z=0},{x=-1,y=0,z=0},{x=0,y=-1,z=0}} |
|
581 |
local nnodepos = vector.add(pos, dirs[math.floor(node.param2/4)+1]) |
|
582 |
local dir = minetest.facedir_to_dir(node.param2) |
|
583 |
local nnode=minetest.get_node(nnodepos) |
3cf0d3
|
584 |
local meta = minetest.get_meta(pos) |
N |
585 |
local owner = meta:get_string("owner") |
c06cdf
|
586 |
if nnode.name == "technic:template" then |
N |
587 |
local connected_nodes=get_template_nodes(nnodepos) |
3cf0d3
|
588 |
move_nodes_vect(connected_nodes,dir,pos,owner) |
c06cdf
|
589 |
end |
N |
590 |
end |
|
591 |
|
|
592 |
minetest.register_node("technic:template_motor",{ |
354ee6
|
593 |
description = S("Template motor"), |
c06cdf
|
594 |
tiles = {"pipeworks_filter_top.png^[transformR90", "technic_lv_cable.png", "technic_lv_cable.png", |
N |
595 |
"technic_lv_cable.png", "technic_lv_cable.png", "technic_lv_cable.png"}, |
|
596 |
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,mesecon=2}, |
|
597 |
paramtype2 = "facedir", |
|
598 |
mesecons={effector={action_on=template_motor_on}}, |
3cf0d3
|
599 |
after_place_node = function(pos, placer, itemstack) |
N |
600 |
local meta = minetest.get_meta(pos) |
|
601 |
meta:set_string("owner", placer:get_player_name()) |
|
602 |
end, |
c06cdf
|
603 |
}) |
768794
|
604 |
|
N |
605 |
-- Crafts |
|
606 |
minetest.register_craft({ |
|
607 |
output = 'technic:frame_111111', |
|
608 |
recipe = { |
|
609 |
{'', 'default:stick', ''}, |
|
610 |
{'default:stick', 'technic:brass_ingot', 'default:stick'}, |
|
611 |
{'', 'default:stick', ''}, |
|
612 |
} |
|
613 |
}) |
|
614 |
|
|
615 |
minetest.register_craft({ |
|
616 |
output = 'technic:frame_motor', |
|
617 |
recipe = { |
|
618 |
{'', 'technic:frame_111111', ''}, |
|
619 |
{'group:mesecons_conductor_craftable', 'technic:motor', 'group:mesecons_conductor_craftable'}, |
|
620 |
{'', 'technic:frame_111111', ''}, |
|
621 |
} |
|
622 |
}) |
|
623 |
|
|
624 |
minetest.register_craft({ |
|
625 |
output = 'technic:template 10', |
|
626 |
recipe = { |
|
627 |
{'', 'technic:brass_ingot', ''}, |
|
628 |
{'technic:brass_ingot', 'default:mese_crystal', 'technic:brass_ingot'}, |
|
629 |
{'', 'technic:brass_ingot', ''}, |
|
630 |
} |
|
631 |
}) |
|
632 |
|
|
633 |
minetest.register_craft({ |
|
634 |
output = 'technic:template_replacer', |
|
635 |
recipe = {{'technic:template'}} |
|
636 |
}) |
|
637 |
|
|
638 |
minetest.register_craft({ |
|
639 |
output = 'technic:template', |
|
640 |
recipe = {{'technic:template_replacer'}} |
|
641 |
}) |
|
642 |
|
|
643 |
minetest.register_craft({ |
|
644 |
output = 'technic:template_motor', |
|
645 |
recipe = { |
|
646 |
{'', 'technic:template', ''}, |
|
647 |
{'group:mesecons_conductor_craftable', 'technic:motor', 'group:mesecons_conductor_craftable'}, |
|
648 |
{'', 'technic:template', ''}, |
|
649 |
} |
|
650 |
}) |
|
651 |
|
|
652 |
minetest.register_craft({ |
|
653 |
output = 'technic:template_tool', |
|
654 |
recipe = { |
|
655 |
{'', 'technic:template', ''}, |
|
656 |
{'default:mese_crystal', 'default:stick', 'default:mese_crystal'}, |
|
657 |
{'', 'default:stick', ''}, |
|
658 |
} |
|
659 |
}) |