1
- -- Get mesecon rules of pistons
2
- local piston_rules = {
3
- {x = 0 , y = 0 , z = 1 }, -- everything apart from z- (pusher side)
4
- {x = 1 , y = 0 , z = 0 },
5
- {x =- 1 , y = 0 , z = 0 },
6
- {x = 1 , y = 1 , z = 0 },
7
- {x = 1 , y =- 1 , z = 0 },
8
- {x =- 1 , y = 1 , z = 0 },
9
- {x =- 1 , y =- 1 , z = 0 },
10
- {x = 0 , y = 1 , z = 1 },
11
- {x = 0 , y =- 1 , z = 1 }
12
- }
13
-
14
- local piston_up_rules = {
15
- {x = 0 , y = 0 , z =- 1 }, -- everything apart from y+ (pusher side)
16
- {x = 1 , y = 0 , z = 0 },
17
- {x =- 1 , y = 0 , z = 0 },
18
- {x = 0 , y = 0 , z = 1 },
19
- {x = 1 , y =- 1 , z = 0 },
20
- {x =- 1 , y =- 1 , z = 0 },
21
- {x = 0 , y =- 1 , z = 1 },
22
- {x = 0 , y =- 1 , z =- 1 }
23
- }
24
-
25
- local piston_down_rules = {
26
- {x = 0 , y = 0 , z =- 1 }, -- everything apart from y- (pusher side)
27
- {x = 1 , y = 0 , z = 0 },
28
- {x =- 1 , y = 0 , z = 0 },
29
- {x = 0 , y = 0 , z = 1 },
30
- {x = 1 , y = 1 , z = 0 },
31
- {x =- 1 , y = 1 , z = 0 },
32
- {x = 0 , y = 1 , z = 1 },
33
- {x = 0 , y = 1 , z =- 1 }
1
+ local specs = {
2
+ normal = {
3
+ offname = " mesecons_pistons:piston_normal_off" ,
4
+ onname = " mesecons_pistons:piston_normal_on" ,
5
+ pusher = " mesecons_pistons:piston_pusher_normal" ,
6
+ },
7
+ sticky = {
8
+ offname = " mesecons_pistons:piston_sticky_off" ,
9
+ onname = " mesecons_pistons:piston_sticky_on" ,
10
+ pusher = " mesecons_pistons:piston_pusher_sticky" ,
11
+ sticky = true ,
12
+ },
34
13
}
35
14
36
- local function piston_get_rules (node )
37
- local rules = piston_rules
38
- for i = 1 , node .param2 do
39
- rules = mesecon .rotate_rules_left (rules )
15
+ local function get_pistonspec_name (name , part )
16
+ if part then
17
+ for spec_name , spec in pairs (specs ) do
18
+ if name == spec [part ] then
19
+ return spec_name , part
20
+ end
21
+ end
22
+ return
23
+ end
24
+ for spec_name , spec in pairs (specs ) do
25
+ for part , value in pairs (spec ) do
26
+ if name == value then
27
+ return spec_name , part
28
+ end
29
+ end
40
30
end
41
- return rules
42
31
end
43
32
44
- local function piston_facedir_direction (node )
45
- local rules = {{x = 0 , y = 0 , z = - 1 }}
46
- for i = 1 , node .param2 do
47
- rules = mesecon .rotate_rules_left (rules )
48
- end
49
- return rules [1 ]
33
+ local function get_pistonspec (name , part )
34
+ return specs [get_pistonspec_name (name , part )]
50
35
end
51
36
52
- local function piston_get_direction (dir , node )
53
- if type (dir ) == " function" then
54
- return dir (node )
55
- else
56
- return dir
37
+ local max_push = mesecon .setting (" piston_max_push" , 15 )
38
+ local max_pull = mesecon .setting (" piston_max_pull" , 15 )
39
+
40
+ -- Get mesecon rules of pistons
41
+ local function piston_get_rules (node )
42
+ local dir = minetest .facedir_to_dir (node .param2 )
43
+ for k , v in pairs (dir ) do
44
+ if v ~= 0 then
45
+ dir = {k , - v }
46
+ break
47
+ end
48
+ end
49
+ local rules = table .copy (mesecon .rules .default )
50
+ for i , rule in ipairs (rules ) do
51
+ if rule [dir [1 ]] == dir [2 ] then
52
+ table.remove (rules , i )
53
+ end
57
54
end
55
+ return rules
58
56
end
59
57
60
- local piston_remove_pusher = function (pos , node )
61
- local pistonspec = minetest . registered_nodes [ node .name ]. mesecons_piston
62
- local dir = piston_get_direction ( pistonspec . dir , node )
58
+ local function piston_remove_pusher (pos , node )
59
+ local pistonspec = get_pistonspec ( node .name , " onname " )
60
+ local dir = vector . multiply ( minetest . facedir_to_dir ( node . param2 ), - 1 )
63
61
local pusherpos = vector .add (pos , dir )
64
62
local pushername = minetest .get_node (pusherpos ).name
65
63
@@ -74,67 +72,163 @@ local piston_remove_pusher = function(pos, node)
74
72
max_hear_distance = 20 ,
75
73
gain = 0.3 ,
76
74
})
77
- nodeupdate (pusherpos )
78
75
end
79
76
80
77
local piston_on = function (pos , node )
81
- local pistonspec = minetest .registered_nodes [node .name ].mesecons_piston
82
-
83
- local dir = piston_get_direction (pistonspec .dir , node )
84
- local np = vector .add (pos , dir )
85
- local maxpush = mesecon .setting (" piston_max_push" , 15 )
86
- local success , stack , oldstack = mesecon .mvps_push (np , dir , maxpush )
87
- if success then
88
- minetest .set_node (pos , {param2 = node .param2 , name = pistonspec .onname })
89
- minetest .set_node (np , {param2 = node .param2 , name = pistonspec .pusher })
90
- minetest .sound_play (" piston_extend" , {
91
- pos = pos ,
92
- max_hear_distance = 20 ,
93
- gain = 0.3 ,
94
- })
95
- mesecon .mvps_process_stack (stack )
96
- mesecon .mvps_move_objects (np , dir , oldstack )
78
+ local pistonspec = get_pistonspec (node .name , " offname" )
79
+ local dir = vector .multiply (minetest .facedir_to_dir (node .param2 ), - 1 )
80
+ local pusher_pos = vector .add (pos , dir )
81
+ local success , stack , oldstack = mesecon .mvps_push (pusher_pos , dir , max_push )
82
+ if not success then
83
+ return
97
84
end
85
+ minetest .set_node (pos , {param2 = node .param2 , name = pistonspec .onname })
86
+ minetest .set_node (pusher_pos , {param2 = node .param2 , name = pistonspec .pusher })
87
+ minetest .sound_play (" piston_extend" , {
88
+ pos = pos ,
89
+ max_hear_distance = 20 ,
90
+ gain = 0.3 ,
91
+ })
92
+ mesecon .mvps_process_stack (stack )
93
+ mesecon .mvps_move_objects (pusher_pos , dir , oldstack )
98
94
end
99
95
100
- local piston_off = function (pos , node )
101
- local pistonspec = minetest . registered_nodes [ node .name ]. mesecons_piston
96
+ local function piston_off (pos , node )
97
+ local pistonspec = get_pistonspec ( node .name , " onname " )
102
98
minetest .set_node (pos , {param2 = node .param2 , name = pistonspec .offname })
103
99
piston_remove_pusher (pos , node )
104
100
105
- if pistonspec .sticky then
106
- local maxpull = mesecon .setting (" piston_max_pull" , 15 )
107
- local dir = piston_get_direction (pistonspec .dir , node )
108
- local pullpos = vector .add (pos , vector .multiply (dir , 2 ))
109
- local stack = mesecon .mvps_pull_single (pullpos , vector .multiply (dir , - 1 ), maxpull )
110
- mesecon .mvps_process_stack (pos , dir , stack )
101
+ if not pistonspec .sticky then
102
+ return
111
103
end
104
+ local dir = vector .multiply (minetest .facedir_to_dir (node .param2 ), - 1 )
105
+ local pullpos = vector .add (pos , vector .multiply (dir , 2 ))
106
+ local stack = mesecon .mvps_pull_single (pullpos , vector .multiply (dir , - 1 ), max_pull )
107
+ mesecon .mvps_process_stack (pos , dir , stack )
112
108
end
113
109
114
- local piston_orientate = function ( pos , placer )
115
- -- not placed by player
116
- if not placer then return end
117
-
118
- -- placer pitch in degrees
119
- local pitch = placer : get_look_pitch () * ( 180 / math.pi )
110
+ local orientations = {
111
+ [ 0 ] = { 4 , 8 },
112
+ { 13 , 17 },
113
+ { 10 , 6 },
114
+ { 20 , 15 },
115
+ }
120
116
117
+ local function piston_orientate (pos , placer )
118
+ if not placer then
119
+ return
120
+ end
121
+ local pitch = math.deg (placer :get_look_vertical ())
121
122
local node = minetest .get_node (pos )
122
- local pistonspec = minetest .registered_nodes [node .name ].mesecons_piston
123
+ if pitch > 55 then
124
+ node .param2 = orientations [node .param2 ][1 ]
125
+ elseif pitch < - 55 then
126
+ node .param2 = orientations [node .param2 ][2 ]
127
+ else
128
+ return
129
+ end
130
+ minetest .swap_node (pos , node )
131
+ -- minetest.after, because on_placenode for unoriented piston must be processed first
132
+ minetest .after (0 , mesecon .on_placenode , pos , node )
133
+ end
123
134
124
- -- looking upwards (pitch > 55) / looking downwards (pitch < -55)
125
- local nn = nil
126
- if pitch > 55 then nn = {name = pistonspec .piston_down } end
127
- if pitch < - 55 then nn = {name = pistonspec .piston_up } end
135
+ local rotations = {
136
+ {0 , 16 , 20 , 12 },
137
+ {2 , 14 , 22 , 18 },
138
+ {1 , 5 , 23 , 9 },
139
+ {3 , 11 , 21 , 7 },
140
+ {4 , 13 , 10 , 19 },
141
+ {6 , 15 , 8 , 17 },
142
+ }
128
143
129
- if nn then
130
- minetest .set_node (pos , nn )
131
- -- minetest.after, because on_placenode for unoriented piston must be processed first
132
- minetest .after (0 , mesecon .on_placenode , pos , nn )
144
+ local function get_rotation (param2 )
145
+ for a = 1 , # rotations do
146
+ for f = 1 , # rotations [a ] do
147
+ if rotations [a ][f ] == param2 then
148
+ return a , f
149
+ end
150
+ end
133
151
end
134
152
end
135
153
154
+ local function rotate (param2 , mode )
155
+ local axis , face = get_rotation (param2 )
156
+ if mode == screwdriver .ROTATE_FACE then
157
+ face = face + 1
158
+ if face > 4 then
159
+ face = 1
160
+ end
161
+ elseif mode == screwdriver .ROTATE_AXIS then
162
+ axis = axis + 1
163
+ if axis > 6 then
164
+ axis = 1
165
+ end
166
+ face = 1
167
+ else
168
+ return param2
169
+ end
170
+ return rotations [axis ][face ]
171
+ end
136
172
137
- -- Horizontal pistons
173
+ local function piston_rotate (pos , node , _ , mode )
174
+ node .param2 = rotate (node .param2 , mode )
175
+ minetest .swap_node (pos , node )
176
+ mesecon .execute_autoconnect_hooks_now (pos , node )
177
+ return true
178
+ end
179
+
180
+ local function piston_rotate_on (pos , node , player , mode )
181
+ local pistonspec = get_pistonspec (node .name , " onname" )
182
+ local dir = vector .multiply (minetest .facedir_to_dir (node .param2 ), - 1 )
183
+ local pusher_pos = vector .add (dir , pos )
184
+ local pusher_node = minetest .get_node (pusher_pos )
185
+ if pusher_node .name ~= pistonspec .pusher then
186
+ return piston_rotate (pos , node , nil , mode )
187
+ end
188
+ if mode == screwdriver .ROTATE_FACE then
189
+ piston_rotate (pusher_pos , pusher_node , nil , mode )
190
+ return piston_rotate (pos , node , nil , mode )
191
+ elseif mode ~= screwdriver .ROTATE_AXIS then
192
+ return false
193
+ end
194
+ local player_name = player and player :is_player () and player :get_player_name () or " "
195
+ local ok , dir_after , pusher_pos_after
196
+ for i = 1 , 5 do
197
+ node .param2 = rotate (node .param2 , mode )
198
+ dir_after = vector .multiply (minetest .facedir_to_dir (node .param2 ), - 1 )
199
+ pusher_pos_after = vector .add (dir_after , pos )
200
+ local pusher_pos_after_node_name = minetest .get_node (pusher_pos_after ).name
201
+ local pusher_pos_after_node_def = minetest .registered_nodes [pusher_pos_after_node_name ]
202
+ if pusher_pos_after_node_def and pusher_pos_after_node_def .buildable_to and
203
+ not minetest .is_protected (pusher_pos_after , player_name ) then
204
+ ok = true
205
+ break
206
+ end
207
+ end
208
+ if not ok then
209
+ return false
210
+ end
211
+ pusher_node .param2 = node .param2
212
+ minetest .remove_node (pusher_pos )
213
+ minetest .set_node (pusher_pos_after , pusher_node )
214
+ minetest .swap_node (pos , node )
215
+ mesecon .execute_autoconnect_hooks_now (pos , node )
216
+ return true
217
+ end
218
+
219
+ local function piston_rotate_pusher (pos , node , player , mode )
220
+ local pistonspec = get_pistonspec (node .name , " pusher" )
221
+ local piston_pos = vector .add (pos , minetest .facedir_to_dir (node .param2 ))
222
+ local piston_node = minetest .get_node (piston_pos )
223
+ if piston_node .name ~= pistonspec .onname then
224
+ minetest .remove_node (pos ) -- Make it possible to remove alone pushers.
225
+ return false
226
+ end
227
+ return piston_rotate_on (piston_pos , piston_node , player , mode )
228
+ end
229
+
230
+
231
+ -- Boxes:
138
232
139
233
local pt = 3 / 16 -- pusher thickness
140
234
@@ -143,28 +237,18 @@ local piston_pusher_box = {
143
237
fixed = {
144
238
{- 2 / 16 , - 2 / 16 , - .5 + pt , 2 / 16 , 2 / 16 , .5 + pt },
145
239
{- .5 , - .5 , - .5 , .5 , .5 , - .5 + pt },
146
- }
240
+ },
147
241
}
148
242
149
243
local piston_on_box = {
150
244
type = " fixed" ,
151
245
fixed = {
152
246
{- .5 , - .5 , - .5 + pt , .5 , .5 , .5 }
153
- }
247
+ },
154
248
}
155
249
156
250
157
- -- Normal (non-sticky) ones:
158
-
159
- local pistonspec_normal = {
160
- offname = " mesecons_pistons:piston_normal_off" ,
161
- onname = " mesecons_pistons:piston_normal_on" ,
162
- dir = piston_facedir_direction ,
163
- pusher = " mesecons_pistons:piston_pusher_normal" ,
164
- piston_down = " mesecons_pistons:piston_down_normal_off" ,
165
- piston_up = " mesecons_pistons:piston_up_normal_off" ,
166
- }
167
-
251
+ -- Normal (non-sticky) Pistons:
168
252
-- offstate
169
253
minetest .register_node (" mesecons_pistons:piston_normal_off" , {
170
254
description = " Piston" ,
@@ -175,21 +259,22 @@ minetest.register_node("mesecons_pistons:piston_normal_off", {
175
259
" mesecons_piston_right.png" ,
176
260
" mesecons_piston_back.png" ,
177
261
" mesecons_piston_pusher_front.png"
178
- },
262
+ },
179
263
groups = {cracky = 3 },
180
264
paramtype2 = " facedir" ,
181
265
after_place_node = piston_orientate ,
182
- mesecons_piston = pistonspec_normal ,
183
266
sounds = default .node_sound_wood_defaults (),
184
267
mesecons = {effector = {
185
268
action_on = piston_on ,
186
- rules = piston_get_rules
269
+ rules = piston_get_rules ,
187
270
}},
271
+ on_rotate = piston_rotate ,
188
272
on_blast = mesecon .on_blastnode ,
189
273
})
190
274
191
275
-- onstate
192
276
minetest .register_node (" mesecons_pistons:piston_normal_on" , {
277
+ description = " Activated Piston Base" ,
193
278
drawtype = " nodebox" ,
194
279
tiles = {
195
280
" mesecons_piston_top.png" ,
@@ -198,27 +283,26 @@ minetest.register_node("mesecons_pistons:piston_normal_on", {
198
283
" mesecons_piston_right.png" ,
199
284
" mesecons_piston_back.png" ,
200
285
" mesecons_piston_on_front.png"
201
- },
202
- inventory_image = " mesecons_piston_top.png" ,
203
- wield_image = " mesecons_piston_top.png" ,
286
+ },
204
287
groups = {cracky = 3 , not_in_creative_inventory = 1 },
205
288
paramtype = " light" ,
206
289
paramtype2 = " facedir" ,
207
290
drop = " mesecons_pistons:piston_normal_off" ,
208
291
after_dig_node = piston_remove_pusher ,
209
292
node_box = piston_on_box ,
210
293
selection_box = piston_on_box ,
211
- mesecons_piston = pistonspec_normal ,
212
294
sounds = default .node_sound_wood_defaults (),
213
295
mesecons = {effector = {
214
296
action_off = piston_off ,
215
- rules = piston_get_rules
297
+ rules = piston_get_rules ,
216
298
}},
299
+ on_rotate = piston_rotate_on ,
217
300
on_blast = mesecon .on_blastnode ,
218
301
})
219
302
220
303
-- pusher
221
304
minetest .register_node (" mesecons_pistons:piston_pusher_normal" , {
305
+ description = " Piston Pusher" ,
222
306
drawtype = " nodebox" ,
223
307
tiles = {
224
308
" mesecons_piston_pusher_top.png" ,
@@ -227,28 +311,18 @@ minetest.register_node("mesecons_pistons:piston_pusher_normal", {
227
311
" mesecons_piston_pusher_right.png" ,
228
312
" mesecons_piston_pusher_back.png" ,
229
313
" mesecons_piston_pusher_front.png"
230
- },
314
+ },
315
+ groups = {not_in_creative_inventory = 1 },
231
316
paramtype = " light" ,
232
317
paramtype2 = " facedir" ,
233
318
diggable = false ,
234
- corresponding_piston = " mesecons_pistons:piston_normal_on" ,
235
319
selection_box = piston_pusher_box ,
236
320
node_box = piston_pusher_box ,
321
+ on_rotate = piston_rotate_pusher ,
237
322
drop = " " ,
238
323
})
239
324
240
325
-- Sticky ones
241
-
242
- local pistonspec_sticky = {
243
- offname = " mesecons_pistons:piston_sticky_off" ,
244
- onname = " mesecons_pistons:piston_sticky_on" ,
245
- dir = piston_facedir_direction ,
246
- pusher = " mesecons_pistons:piston_pusher_sticky" ,
247
- sticky = true ,
248
- piston_down = " mesecons_pistons:piston_down_sticky_off" ,
249
- piston_up = " mesecons_pistons:piston_up_sticky_off" ,
250
- }
251
-
252
326
-- offstate
253
327
minetest .register_node (" mesecons_pistons:piston_sticky_off" , {
254
328
description = " Sticky Piston" ,
@@ -259,21 +333,22 @@ minetest.register_node("mesecons_pistons:piston_sticky_off", {
259
333
" mesecons_piston_right.png" ,
260
334
" mesecons_piston_back.png" ,
261
335
" mesecons_piston_pusher_front_sticky.png"
262
- },
336
+ },
263
337
groups = {cracky = 3 },
264
338
paramtype2 = " facedir" ,
265
339
after_place_node = piston_orientate ,
266
- mesecons_piston = pistonspec_sticky ,
267
340
sounds = default .node_sound_wood_defaults (),
268
341
mesecons = {effector = {
269
342
action_on = piston_on ,
270
- rules = piston_get_rules
343
+ rules = piston_get_rules ,
271
344
}},
345
+ on_rotate = piston_rotate ,
272
346
on_blast = mesecon .on_blastnode ,
273
347
})
274
348
275
349
-- onstate
276
350
minetest .register_node (" mesecons_pistons:piston_sticky_on" , {
351
+ description = " Activated Sticky Piston Base" ,
277
352
drawtype = " nodebox" ,
278
353
tiles = {
279
354
" mesecons_piston_top.png" ,
@@ -282,27 +357,26 @@ minetest.register_node("mesecons_pistons:piston_sticky_on", {
282
357
" mesecons_piston_right.png" ,
283
358
" mesecons_piston_back.png" ,
284
359
" mesecons_piston_on_front.png"
285
- },
286
- inventory_image = " mesecons_piston_top.png" ,
287
- wield_image = " mesecons_piston_top.png" ,
360
+ },
288
361
groups = {cracky = 3 , not_in_creative_inventory = 1 },
289
362
paramtype = " light" ,
290
363
paramtype2 = " facedir" ,
291
364
drop = " mesecons_pistons:piston_sticky_off" ,
292
365
after_dig_node = piston_remove_pusher ,
293
366
node_box = piston_on_box ,
294
367
selection_box = piston_on_box ,
295
- mesecons_piston = pistonspec_sticky ,
296
368
sounds = default .node_sound_wood_defaults (),
297
369
mesecons = {effector = {
298
370
action_off = piston_off ,
299
- rules = piston_get_rules
371
+ rules = piston_get_rules ,
300
372
}},
373
+ on_rotate = piston_rotate_on ,
301
374
on_blast = mesecon .on_blastnode ,
302
375
})
303
376
304
377
-- pusher
305
378
minetest .register_node (" mesecons_pistons:piston_pusher_sticky" , {
379
+ description = " Sticky Piston Pusher" ,
306
380
drawtype = " nodebox" ,
307
381
tiles = {
308
382
" mesecons_piston_pusher_top.png" ,
@@ -311,412 +385,36 @@ minetest.register_node("mesecons_pistons:piston_pusher_sticky", {
311
385
" mesecons_piston_pusher_right.png" ,
312
386
" mesecons_piston_pusher_back.png" ,
313
387
" mesecons_piston_pusher_front_sticky.png"
314
- },
388
+ },
389
+ groups = {not_in_creative_inventory = 1 },
315
390
paramtype = " light" ,
316
391
paramtype2 = " facedir" ,
317
392
diggable = false ,
318
- corresponding_piston = " mesecons_pistons:piston_sticky_on" ,
319
393
selection_box = piston_pusher_box ,
320
394
node_box = piston_pusher_box ,
321
- drop = " " ,
322
- })
323
-
324
- --
325
- --
326
- -- UP
327
- --
328
- --
329
-
330
- local piston_up_pusher_box = {
331
- type = " fixed" ,
332
- fixed = {
333
- {- 2 / 16 , - .5 - pt , - 2 / 16 , 2 / 16 , .5 - pt , 2 / 16 },
334
- {- .5 , .5 - pt , - .5 , .5 , .5 , .5 },
335
- }
336
- }
337
-
338
- local piston_up_on_box = {
339
- type = " fixed" ,
340
- fixed = {
341
- {- .5 , - .5 , - .5 , .5 , .5 - pt , .5 }
342
- }
343
- }
344
-
345
- -- Normal
346
-
347
- local pistonspec_normal_up = {
348
- offname = " mesecons_pistons:piston_up_normal_off" ,
349
- onname = " mesecons_pistons:piston_up_normal_on" ,
350
- dir = {x = 0 , y = 1 , z = 0 },
351
- pusher = " mesecons_pistons:piston_up_pusher_normal"
352
- }
353
-
354
- -- offstate
355
- minetest .register_node (" mesecons_pistons:piston_up_normal_off" , {
356
- tiles = {
357
- " mesecons_piston_pusher_front.png" ,
358
- " mesecons_piston_back.png" ,
359
- " mesecons_piston_left.png^[transformR270" ,
360
- " mesecons_piston_right.png^[transformR90" ,
361
- " mesecons_piston_bottom.png" ,
362
- " mesecons_piston_top.png^[transformR180" ,
363
- },
364
- inventory_image = " mesecons_piston_top.png" ,
365
- wield_image = " mesecons_piston_top.png" ,
366
- groups = {cracky = 3 , not_in_creative_inventory = 1 },
367
- paramtype2 = " facedir" ,
368
- drop = " mesecons_pistons:piston_normal_off" ,
369
- mesecons_piston = pistonspec_normal_up ,
370
- mesecons = {effector = {
371
- action_on = piston_on ,
372
- rules = piston_up_rules ,
373
- }},
374
- on_blast = mesecon .on_blastnode ,
375
- })
376
-
377
- -- onstate
378
- minetest .register_node (" mesecons_pistons:piston_up_normal_on" , {
379
- drawtype = " nodebox" ,
380
- tiles = {
381
- " mesecons_piston_on_front.png" ,
382
- " mesecons_piston_back.png" ,
383
- " mesecons_piston_left.png^[transformR270" ,
384
- " mesecons_piston_right.png^[transformR90" ,
385
- " mesecons_piston_bottom.png" ,
386
- " mesecons_piston_top.png^[transformR180" ,
387
- },
388
- inventory_image = " mesecons_piston_top.png" ,
389
- wield_image = " mesecons_piston_top.png" ,
390
- groups = {cracky = 3 , not_in_creative_inventory = 1 },
391
- paramtype = " light" ,
392
- paramtype2 = " facedir" ,
393
- drop = " mesecons_pistons:piston_normal_off" ,
394
- after_dig_node = piston_remove_pusher ,
395
- node_box = piston_up_on_box ,
396
- selection_box = piston_up_on_box ,
397
- mesecons_piston = pistonspec_normal_up ,
398
- sounds = default .node_sound_wood_defaults (),
399
- mesecons = {effector = {
400
- action_off = piston_off ,
401
- rules = piston_up_rules ,
402
- }},
403
- on_blast = mesecon .on_blastnode ,
404
- })
405
-
406
- -- pusher
407
- minetest .register_node (" mesecons_pistons:piston_up_pusher_normal" , {
408
- drawtype = " nodebox" ,
409
- tiles = {
410
- " mesecons_piston_pusher_front.png" ,
411
- " mesecons_piston_pusher_back.png" ,
412
- " mesecons_piston_pusher_left.png^[transformR270" ,
413
- " mesecons_piston_pusher_right.png^[transformR90" ,
414
- " mesecons_piston_pusher_bottom.png" ,
415
- " mesecons_piston_pusher_top.png^[transformR180" ,
416
- },
417
- paramtype = " light" ,
418
- paramtype2 = " facedir" ,
419
- diggable = false ,
420
- corresponding_piston = " mesecons_pistons:piston_up_normal_on" ,
421
- selection_box = piston_up_pusher_box ,
422
- node_box = piston_up_pusher_box ,
423
- drop = " " ,
424
- })
425
-
426
-
427
-
428
- -- Sticky
429
-
430
-
431
- local pistonspec_sticky_up = {
432
- offname = " mesecons_pistons:piston_up_sticky_off" ,
433
- onname = " mesecons_pistons:piston_up_sticky_on" ,
434
- dir = {x = 0 , y = 1 , z = 0 },
435
- pusher = " mesecons_pistons:piston_up_pusher_sticky" ,
436
- sticky = true
437
- }
438
-
439
- -- offstate
440
- minetest .register_node (" mesecons_pistons:piston_up_sticky_off" , {
441
- tiles = {
442
- " mesecons_piston_pusher_front_sticky.png" ,
443
- " mesecons_piston_back.png" ,
444
- " mesecons_piston_left.png^[transformR270" ,
445
- " mesecons_piston_right.png^[transformR90" ,
446
- " mesecons_piston_bottom.png" ,
447
- " mesecons_piston_top.png^[transformR180" ,
448
- " mesecons_piston_tb.png"
449
- },
450
- inventory_image = " mesecons_piston_top.png" ,
451
- wield_image = " mesecons_piston_top.png" ,
452
- groups = {cracky = 3 , not_in_creative_inventory = 1 },
453
- paramtype2 = " facedir" ,
454
- drop = " mesecons_pistons:piston_sticky_off" ,
455
- mesecons_piston = pistonspec_sticky_up ,
456
- sounds = default .node_sound_wood_defaults (),
457
- mesecons = {effector = {
458
- action_on = piston_on ,
459
- rules = piston_up_rules ,
460
- }},
461
- on_blast = mesecon .on_blastnode ,
462
- })
463
-
464
- -- onstate
465
- minetest .register_node (" mesecons_pistons:piston_up_sticky_on" , {
466
- drawtype = " nodebox" ,
467
- tiles = {
468
- " mesecons_piston_on_front.png" ,
469
- " mesecons_piston_back.png" ,
470
- " mesecons_piston_left.png^[transformR270" ,
471
- " mesecons_piston_right.png^[transformR90" ,
472
- " mesecons_piston_bottom.png" ,
473
- " mesecons_piston_top.png^[transformR180" ,
474
- },
475
- inventory_image = " mesecons_piston_top.png" ,
476
- wield_image = " mesecons_piston_top.png" ,
477
- groups = {cracky = 3 , not_in_creative_inventory = 1 },
478
- paramtype = " light" ,
479
- paramtype2 = " facedir" ,
480
- drop = " mesecons_pistons:piston_normal_off" ,
481
- after_dig_node = piston_remove_pusher ,
482
- node_box = piston_up_on_box ,
483
- selection_box = piston_up_on_box ,
484
- mesecons_piston = pistonspec_sticky_up ,
485
- sounds = default .node_sound_wood_defaults (),
486
- mesecons = {effector = {
487
- action_off = piston_off ,
488
- rules = piston_up_rules ,
489
- }},
490
- on_blast = mesecon .on_blastnode ,
491
- })
492
-
493
- -- pusher
494
- minetest .register_node (" mesecons_pistons:piston_up_pusher_sticky" , {
495
- drawtype = " nodebox" ,
496
- tiles = {
497
- " mesecons_piston_pusher_front_sticky.png" ,
498
- " mesecons_piston_pusher_back.png" ,
499
- " mesecons_piston_pusher_left.png^[transformR270" ,
500
- " mesecons_piston_pusher_right.png^[transformR90" ,
501
- " mesecons_piston_pusher_bottom.png" ,
502
- " mesecons_piston_pusher_top.png^[transformR180" ,
503
- },
504
- paramtype = " light" ,
505
- paramtype2 = " facedir" ,
506
- diggable = false ,
507
- corresponding_piston = " mesecons_pistons:piston_up_sticky_on" ,
508
- selection_box = piston_up_pusher_box ,
509
- node_box = piston_up_pusher_box ,
510
- drop = " " ,
511
- })
512
-
513
- --
514
- --
515
- -- DOWN
516
- --
517
- --
518
-
519
- local piston_down_pusher_box = {
520
- type = " fixed" ,
521
- fixed = {
522
- {- 2 / 16 , - .5 + pt , - 2 / 16 , 2 / 16 , .5 + pt , 2 / 16 },
523
- {- .5 , - .5 , - .5 , .5 , - .5 + pt , .5 },
524
- }
525
- }
526
-
527
- local piston_down_on_box = {
528
- type = " fixed" ,
529
- fixed = {
530
- {- .5 , - .5 + pt , - .5 , .5 , .5 , .5 }
531
- }
532
- }
533
-
534
-
535
-
536
- -- Normal
537
-
538
- local pistonspec_normal_down = {
539
- offname = " mesecons_pistons:piston_down_normal_off" ,
540
- onname = " mesecons_pistons:piston_down_normal_on" ,
541
- dir = {x = 0 , y = - 1 , z = 0 },
542
- pusher = " mesecons_pistons:piston_down_pusher_normal" ,
543
- }
544
-
545
- -- offstate
546
- minetest .register_node (" mesecons_pistons:piston_down_normal_off" , {
547
- tiles = {
548
- " mesecons_piston_back.png" ,
549
- " mesecons_piston_pusher_front.png" ,
550
- " mesecons_piston_left.png^[transformR90" ,
551
- " mesecons_piston_right.png^[transformR270" ,
552
- " mesecons_piston_bottom.png^[transformR180" ,
553
- " mesecons_piston_top.png" ,
554
- },
555
- inventory_image = " mesecons_piston_top.png" ,
556
- wield_image = " mesecons_piston_top.png" ,
557
- groups = {cracky = 3 , not_in_creative_inventory = 1 },
558
- paramtype2 = " facedir" ,
559
- drop = " mesecons_pistons:piston_normal_off" ,
560
- mesecons_piston = pistonspec_normal_down ,
561
- sounds = default .node_sound_wood_defaults (),
562
- mesecons = {effector = {
563
- action_on = piston_on ,
564
- rules = piston_down_rules ,
565
- }},
566
- on_blast = mesecon .on_blastnode ,
567
- })
568
-
569
- -- onstate
570
- minetest .register_node (" mesecons_pistons:piston_down_normal_on" , {
571
- drawtype = " nodebox" ,
572
- tiles = {
573
- " mesecons_piston_back.png" ,
574
- " mesecons_piston_on_front.png" ,
575
- " mesecons_piston_left.png^[transformR90" ,
576
- " mesecons_piston_right.png^[transformR270" ,
577
- " mesecons_piston_bottom.png^[transformR180" ,
578
- " mesecons_piston_top.png" ,
579
- },
580
- inventory_image = " mesecons_piston_top.png" ,
581
- wield_image = " mesecons_piston_top.png" ,
582
- groups = {cracky = 3 , not_in_creative_inventory = 1 },
583
- paramtype = " light" ,
584
- paramtype2 = " facedir" ,
585
- drop = " mesecons_pistons:piston_normal_off" ,
586
- after_dig_node = piston_remove_pusher ,
587
- node_box = piston_down_on_box ,
588
- selection_box = piston_down_on_box ,
589
- mesecons_piston = pistonspec_normal_down ,
590
- sounds = default .node_sound_wood_defaults (),
591
- mesecons = {effector = {
592
- action_off = piston_off ,
593
- rules = piston_down_rules ,
594
- }},
595
- on_blast = mesecon .on_blastnode ,
596
- })
597
-
598
- -- pusher
599
- minetest .register_node (" mesecons_pistons:piston_down_pusher_normal" , {
600
- drawtype = " nodebox" ,
601
- tiles = {
602
- " mesecons_piston_pusher_back.png" ,
603
- " mesecons_piston_pusher_front.png" ,
604
- " mesecons_piston_pusher_left.png^[transformR90" ,
605
- " mesecons_piston_pusher_right.png^[transformR270" ,
606
- " mesecons_piston_pusher_bottom.png^[transformR180" ,
607
- " mesecons_piston_pusher_top.png" ,
608
- },
609
- paramtype = " light" ,
610
- paramtype2 = " facedir" ,
611
- diggable = false ,
612
- corresponding_piston = " mesecons_pistons:piston_down_normal_on" ,
613
- selection_box = piston_down_pusher_box ,
614
- node_box = piston_down_pusher_box ,
615
- drop = " " ,
616
- })
617
-
618
- -- Sticky
619
-
620
- local pistonspec_sticky_down = {
621
- onname = " mesecons_pistons:piston_down_sticky_on" ,
622
- offname = " mesecons_pistons:piston_down_sticky_off" ,
623
- dir = {x = 0 , y = - 1 , z = 0 },
624
- pusher = " mesecons_pistons:piston_down_pusher_sticky" ,
625
- sticky = true
626
- }
627
-
628
- -- offstate
629
- minetest .register_node (" mesecons_pistons:piston_down_sticky_off" , {
630
- tiles = {
631
- " mesecons_piston_back.png" ,
632
- " mesecons_piston_pusher_front_sticky.png" ,
633
- " mesecons_piston_left.png^[transformR90" ,
634
- " mesecons_piston_right.png^[transformR270" ,
635
- " mesecons_piston_bottom.png^[transformR180" ,
636
- " mesecons_piston_top.png" ,
637
- },
638
- inventory_image = " mesecons_piston_top.png" ,
639
- wield_image = " mesecons_piston_top.png" ,
640
- groups = {cracky = 3 , not_in_creative_inventory = 1 },
641
- paramtype2 = " facedir" ,
642
- drop = " mesecons_pistons:piston_sticky_off" ,
643
- mesecons_piston = pistonspec_sticky_down ,
644
- sounds = default .node_sound_wood_defaults (),
645
- mesecons = {effector = {
646
- action_on = piston_on ,
647
- rules = piston_down_rules ,
648
- }},
649
- on_blast = mesecon .on_blastnode ,
650
- })
651
-
652
- -- onstate
653
- minetest .register_node (" mesecons_pistons:piston_down_sticky_on" , {
654
- drawtype = " nodebox" ,
655
- tiles = {
656
- " mesecons_piston_back.png" ,
657
- " mesecons_piston_on_front.png" ,
658
- " mesecons_piston_left.png^[transformR90" ,
659
- " mesecons_piston_right.png^[transformR270" ,
660
- " mesecons_piston_bottom.png^[transformR180" ,
661
- " mesecons_piston_top.png" ,
662
- },
663
- inventory_image = " mesecons_piston_top.png" ,
664
- wield_image = " mesecons_piston_top.png" ,
665
- groups = {cracky = 3 , not_in_creative_inventory = 1 },
666
- paramtype = " light" ,
667
- paramtype2 = " facedir" ,
668
- drop = " mesecons_pistons:piston_sticky_off" ,
669
- after_dig_node = piston_remove_pusher ,
670
- node_box = piston_down_on_box ,
671
- selection_box = piston_down_on_box ,
672
- mesecons_piston = pistonspec_sticky_down ,
673
- sounds = default .node_sound_wood_defaults (),
674
- mesecons = {effector = {
675
- action_off = piston_off ,
676
- rules = piston_down_rules ,
677
- }},
678
- on_blast = mesecon .on_blastnode ,
679
- })
680
-
681
- -- pusher
682
- minetest .register_node (" mesecons_pistons:piston_down_pusher_sticky" , {
683
- drawtype = " nodebox" ,
684
- tiles = {
685
- " mesecons_piston_pusher_back.png" ,
686
- " mesecons_piston_pusher_front_sticky.png" ,
687
- " mesecons_piston_pusher_left.png^[transformR90" ,
688
- " mesecons_piston_pusher_right.png^[transformR270" ,
689
- " mesecons_piston_pusher_bottom.png^[transformR180" ,
690
- " mesecons_piston_pusher_top.png" ,
691
- },
692
- paramtype = " light" ,
693
- paramtype2 = " facedir" ,
694
- diggable = false ,
695
- corresponding_piston = " mesecons_pistons:piston_down_sticky_on" ,
696
- selection_box = piston_down_pusher_box ,
697
- node_box = piston_down_pusher_box ,
395
+ on_rotate = piston_rotate_pusher ,
698
396
drop = " " ,
699
397
})
700
398
701
399
702
400
-- Register pushers as stoppers if they would be seperated from the piston
703
- local piston_pusher_get_stopper = function (node , dir , stack , stackid )
401
+ local function piston_pusher_get_stopper (node , dir , stack , stackid )
704
402
if (stack [stackid + 1 ]
705
- and stack [stackid + 1 ].node .name == minetest . registered_nodes [ node .name ]. corresponding_piston
403
+ and stack [stackid + 1 ].node .name == get_pistonspec ( node .name , " pusher " ). onname
706
404
and stack [stackid + 1 ].node .param2 == node .param2 )
707
405
or (stack [stackid - 1 ]
708
- and stack [stackid - 1 ].node .name == minetest . registered_nodes [ node .name ]. corresponding_piston
406
+ and stack [stackid - 1 ].node .name == get_pistonspec ( node .name , " pusher " ). onname
709
407
and stack [stackid - 1 ].node .param2 == node .param2 ) then
710
408
return false
711
409
end
712
410
return true
713
411
end
714
412
715
- local piston_pusher_up_down_get_stopper = function (node , dir , stack , stackid )
413
+ local function piston_pusher_up_down_get_stopper (node , dir , stack , stackid )
716
414
if (stack [stackid + 1 ]
717
- and stack [stackid + 1 ].node .name == minetest . registered_nodes [ node .name ]. corresponding_piston )
415
+ and stack [stackid + 1 ].node .name == get_pistonspec ( node .name , " pusher " ). onname )
718
416
or (stack [stackid - 1 ]
719
- and stack [stackid - 1 ].node .name == minetest . registered_nodes [ node .name ]. corresponding_piston ) then
417
+ and stack [stackid - 1 ].node .name == get_pistonspec ( node .name , " pusher " ). onname ) then
720
418
return false
721
419
end
722
420
return true
@@ -725,31 +423,24 @@ end
725
423
mesecon .register_mvps_stopper (" mesecons_pistons:piston_pusher_normal" , piston_pusher_get_stopper )
726
424
mesecon .register_mvps_stopper (" mesecons_pistons:piston_pusher_sticky" , piston_pusher_get_stopper )
727
425
728
- mesecon .register_mvps_stopper (" mesecons_pistons:piston_up_pusher_normal" , piston_pusher_up_down_get_stopper )
729
- mesecon .register_mvps_stopper (" mesecons_pistons:piston_up_pusher_sticky" , piston_pusher_up_down_get_stopper )
730
-
731
- mesecon .register_mvps_stopper (" mesecons_pistons:piston_down_pusher_normal" , piston_pusher_up_down_get_stopper )
732
- mesecon .register_mvps_stopper (" mesecons_pistons:piston_down_pusher_sticky" , piston_pusher_up_down_get_stopper )
733
-
734
426
735
427
-- Register pistons as stoppers if they would be seperated from the stopper
736
428
local piston_up_down_get_stopper = function (node , dir , stack , stackid )
737
429
if (stack [stackid + 1 ]
738
- and stack [stackid + 1 ].node .name == minetest . registered_nodes [ node .name ]. mesecons_piston .pusher )
430
+ and stack [stackid + 1 ].node .name == get_pistonspec ( node .name , " onname " ) .pusher )
739
431
or (stack [stackid - 1 ]
740
- and stack [stackid - 1 ].node .name == minetest . registered_nodes [ node .name ]. mesecons_piston .pusher ) then
432
+ and stack [stackid - 1 ].node .name == get_pistonspec ( node .name , " onname " ) .pusher ) then
741
433
return false
742
434
end
743
435
return true
744
436
end
745
437
746
- local piston_get_stopper = function (node , dir , stack , stackid )
747
- pistonspec = minetest . registered_nodes [ node .name ]. mesecons_piston
748
- dir = piston_get_direction ( pistonspec . dir , node )
749
- local pusherpos = vector .add (stack [stackid ].pos , dir )
438
+ local function piston_get_stopper (node , dir , stack , stackid )
439
+ local pistonspec = get_pistonspec ( node .name , " onname " )
440
+ local dir = vector . multiply ( minetest . facedir_to_dir ( node . param2 ), - 1 )
441
+ local pusherpos = vector .add (stack [stackid ].pos , dir )
750
442
local pushernode = minetest .get_node (pusherpos )
751
-
752
- if minetest .registered_nodes [node .name ].mesecons_piston .pusher == pushernode .name then
443
+ if pistonspec .pusher == pushernode .name then
753
444
for _ , s in ipairs (stack ) do
754
445
if vector .equals (s .pos , pusherpos ) -- pusher is also to be pushed
755
446
and s .node .param2 == node .param2 then
@@ -763,18 +454,13 @@ end
763
454
mesecon .register_mvps_stopper (" mesecons_pistons:piston_normal_on" , piston_get_stopper )
764
455
mesecon .register_mvps_stopper (" mesecons_pistons:piston_sticky_on" , piston_get_stopper )
765
456
766
- mesecon .register_mvps_stopper (" mesecons_pistons:piston_up_normal_on" , piston_up_down_get_stopper )
767
- mesecon .register_mvps_stopper (" mesecons_pistons:piston_up_sticky_on" , piston_up_down_get_stopper )
768
-
769
- mesecon .register_mvps_stopper (" mesecons_pistons:piston_down_normal_on" , piston_up_down_get_stopper )
770
- mesecon .register_mvps_stopper (" mesecons_pistons:piston_down_sticky_on" , piston_up_down_get_stopper )
771
457
772
458
-- craft recipes
773
459
minetest .register_craft ({
774
460
output = " mesecons_pistons:piston_normal_off 2" ,
775
461
recipe = {
776
- {" group:wood" , " group:wood" , " group:wood" },
777
- {" default:cobble" , " default:steel_ingot" , " default:cobble" },
462
+ {" group:wood" , " group:wood" , " group:wood" },
463
+ {" default:cobble" , " default:steel_ingot" , " default:cobble" },
778
464
{" default:cobble" , " group:mesecon_conductor_craftable" , " default:cobble" },
779
465
}
780
466
})
@@ -786,3 +472,7 @@ minetest.register_craft({
786
472
{" mesecons_pistons:piston_normal_off" },
787
473
}
788
474
})
475
+
476
+
477
+ -- load legacy code
478
+ dofile (minetest .get_modpath (" mesecons_pistons" ).. DIR_DELIM .. " legacy.lua" )
0 commit comments