8
8
-- Pushes all block in front of it
9
9
-- Pull all blocks in its back
10
10
11
- function mesecon .get_movestone_direction (pos )
12
- local lpos
13
- local rules = {
14
- {x = 0 , y = 1 , z =- 1 },
15
- {x = 0 , y = 0 , z =- 1 },
16
- {x = 0 , y =- 1 , z =- 1 },
17
- {x = 0 , y = 1 , z = 1 },
18
- {x = 0 , y =- 1 , z = 1 },
19
- {x = 0 , y = 0 , z = 1 },
20
- {x = 1 , y = 0 , z = 0 },
21
- {x = 1 , y = 1 , z = 0 },
22
- {x = 1 , y =- 1 , z = 0 },
23
- {x =- 1 , y = 1 , z = 0 },
24
- {x =- 1 , y =- 1 , z = 0 },
25
- {x =- 1 , y = 0 , z = 0 }}
26
-
27
- lpos = {x = pos .x + 1 , y = pos .y , z = pos .z }
28
- for n = 1 , 3 do
29
- if mesecon .is_power_on (lpos , rules [n ]) then
30
- return {x = 0 , y = 0 , z =- 1 }
11
+ -- settings:
12
+ local timer_interval = 1 / mesecon .setting (" movestone_speed" , 3 )
13
+ local max_push = mesecon .setting (" movestone_max_push" , 50 )
14
+ local max_pull = mesecon .setting (" movestone_max_pull" , 50 )
15
+
16
+ -- helper functions:
17
+ local function get_movestone_direction (rulename , is_vertical )
18
+ if is_vertical then
19
+ if rulename .z > 0 then
20
+ return {x = 0 , y = - 1 , z = 0 }
21
+ elseif rulename .z < 0 then
22
+ return {x = 0 , y = 1 , z = 0 }
23
+ elseif rulename .x > 0 then
24
+ return {x = 0 , y = - 1 , z = 0 }
25
+ elseif rulename .x < 0 then
26
+ return {x = 0 , y = 1 , z = 0 }
31
27
end
32
- end
33
-
34
- lpos = {x = pos .x - 1 , y = pos .y , z = pos .z }
35
- for n = 4 , 6 do
36
- if mesecon .is_power_on (lpos , rules [n ]) then
37
- return {x = 0 , y = 0 , z = 1 }
38
- end
39
- end
40
-
41
- lpos = {x = pos .x , y = pos .y , z = pos .z + 1 }
42
- for n = 7 , 9 do
43
- if mesecon .is_power_on (lpos , rules [n ]) then
44
- return {x =- 1 , y = 0 , z = 0 }
45
- end
46
- end
47
-
48
- lpos = {x = pos .x , y = pos .y , z = pos .z - 1 }
49
- for n = 10 , 12 do
50
- if mesecon .is_power_on (lpos , rules [n ]) then
51
- return {x = 1 , y = 0 , z = 0 }
28
+ else
29
+ if rulename .z > 0 then
30
+ return {x = - 1 , y = 0 , z = 0 }
31
+ elseif rulename .z < 0 then
32
+ return {x = 1 , y = 0 , z = 0 }
33
+ elseif rulename .x > 0 then
34
+ return {x = 0 , y = 0 , z = - 1 }
35
+ elseif rulename .x < 0 then
36
+ return {x = 0 , y = 0 , z = 1 }
52
37
end
53
38
end
54
39
end
55
40
56
- function mesecon .register_movestone (name , def , is_sticky )
57
- local timer_interval = 1 / mesecon .setting (" movestone_speed" , 3 )
58
- local name_active = name .. " _active"
59
-
60
- local function movestone_move (pos )
61
- if minetest .get_node (pos ).name ~= name_active then
62
- return
63
- end
64
-
65
- local direction = mesecon .get_movestone_direction (pos )
66
- if not direction then
67
- minetest .set_node (pos , {name = name })
68
- return
69
- end
41
+ -- registration functions:
42
+ function mesecon .register_movestone (name , def , is_sticky , is_vertical )
43
+ local function movestone_move (pos , node , rulename )
44
+ local direction = get_movestone_direction (rulename , is_vertical )
70
45
local frontpos = vector .add (pos , direction )
71
- local backpos = vector .subtract (pos , direction )
72
46
73
47
-- ### Step 1: Push nodes in front ###
74
- local maxpush = mesecon .setting (" movestone_max_push" , 50 )
75
- local maxpull = mesecon .setting (" movestone_max_pull" , 50 )
76
- local success , stack , oldstack = mesecon .mvps_push (frontpos , direction , maxpush )
77
- if success then
78
- mesecon .mvps_process_stack (stack )
79
- mesecon .mvps_move_objects (frontpos , direction , oldstack )
80
- -- Too large stack/stopper in the way: try again very soon
81
- else
82
- minetest .after (0.05 , movestone_move , pos )
48
+ local success , stack , oldstack = mesecon .mvps_push (frontpos , direction , max_push )
49
+ if not success then
50
+ minetest .get_node_timer (pos ):start (timer_interval )
83
51
return
84
52
end
53
+ mesecon .mvps_process_stack (stack )
54
+ mesecon .mvps_move_objects (frontpos , direction , oldstack )
85
55
86
56
-- ### Step 2: Move the movestone ###
87
- local node = minetest .get_node (pos )
88
57
minetest .set_node (frontpos , node )
89
58
minetest .remove_node (pos )
90
59
mesecon .on_dignode (pos , node )
91
60
mesecon .on_placenode (frontpos , node )
92
- minetest .after ( timer_interval , movestone_move , frontpos )
61
+ minetest .get_node_timer ( frontpos ): start ( timer_interval )
93
62
94
63
-- ### Step 3: If sticky, pull stack behind ###
95
64
if is_sticky then
96
- mesecon .mvps_pull_all (backpos , direction , maxpull )
65
+ local backpos = vector .subtract (pos , direction )
66
+ mesecon .mvps_pull_all (backpos , direction , max_pull )
97
67
end
98
68
end
99
69
100
70
def .mesecons = {effector = {
101
- action_on = function (pos )
102
- if minetest .get_node (pos ).name ~= name_active then
103
- minetest .set_node (pos , {name = name_active })
104
- movestone_move (pos )
71
+ action_on = function (pos , node , rulename )
72
+ if rulename and not minetest .get_node_timer (pos ):is_started () then
73
+ movestone_move (pos , node , rulename )
105
74
end
106
75
end ,
107
- action_off = function (pos )
108
- minetest .set_node (pos , {name = name })
109
- end
76
+ rules = mesecon .rules .default ,
110
77
}}
111
78
112
- def .drop = name
79
+ def .on_timer = function (pos , elapsed )
80
+ local sourcepos = mesecon .is_powered (pos )
81
+ if not sourcepos then
82
+ return
83
+ end
84
+ local rulename = vector .subtract (sourcepos [1 ], pos )
85
+ mesecon .activate (pos , minetest .get_node (pos ), rulename , 0 )
86
+ end
87
+
88
+ def .on_blast = mesecon .on_blastnode
113
89
114
90
def .on_blast = mesecon .on_blastnode
115
91
116
92
minetest .register_node (name , def )
117
-
118
- -- active node only
119
- local def_active = table .copy (def )
120
- def_active .groups .not_in_creative_inventory = 1
121
- minetest .register_node (name_active , def_active )
122
93
end
123
94
95
+
96
+ -- registration:
124
97
mesecon .register_movestone (" mesecons_movestones:movestone" , {
125
- tiles = {" jeija_movestone_side.png" , " jeija_movestone_side.png" , " jeija_movestone_side.png" , " jeija_movestone_side.png" , " jeija_movestone_arrows.png" , " jeija_movestone_arrows.png" },
126
- groups = {cracky = 3 },
127
- description = " Movestone" ,
98
+ tiles = {
99
+ " jeija_movestone_side.png" ,
100
+ " jeija_movestone_side.png" ,
101
+ " jeija_movestone_arrows.png^[transformFX" ,
102
+ " jeija_movestone_arrows.png^[transformFX" ,
103
+ " jeija_movestone_arrows.png" ,
104
+ " jeija_movestone_arrows.png" ,
105
+ },
106
+ groups = {cracky = 3 },
107
+ description = " Movestone" ,
108
+ sounds = default .node_sound_stone_defaults ()
109
+ }, false , false )
110
+
111
+ mesecon .register_movestone (" mesecons_movestones:sticky_movestone" , {
112
+ tiles = {
113
+ " jeija_movestone_side.png" ,
114
+ " jeija_movestone_side.png" ,
115
+ " jeija_sticky_movestone.png^[transformFX" ,
116
+ " jeija_sticky_movestone.png^[transformFX" ,
117
+ " jeija_sticky_movestone.png" ,
118
+ " jeija_sticky_movestone.png" ,
119
+ },
120
+ groups = {cracky = 3 },
121
+ description = " Sticky Movestone" ,
122
+ sounds = default .node_sound_stone_defaults (),
123
+ }, true , false )
124
+
125
+ mesecon .register_movestone (" mesecons_movestones:movestone_vertical" , {
126
+ tiles = {
127
+ " jeija_movestone_side.png" ,
128
+ " jeija_movestone_side.png" ,
129
+ " jeija_movestone_arrows.png^[transformFXR90" ,
130
+ " jeija_movestone_arrows.png^[transformR90" ,
131
+ " jeija_movestone_arrows.png^[transformFXR90" ,
132
+ " jeija_movestone_arrows.png^[transformR90" ,
133
+ },
134
+ groups = {cracky = 3 },
135
+ description = " Vertical Movestone" ,
128
136
sounds = default .node_sound_stone_defaults ()
129
- }, false )
137
+ }, false , true )
138
+
139
+ mesecon .register_movestone (" mesecons_movestones:sticky_movestone_vertical" , {
140
+ tiles = {
141
+ " jeija_movestone_side.png" ,
142
+ " jeija_movestone_side.png" ,
143
+ " jeija_sticky_movestone.png^[transformFXR90" ,
144
+ " jeija_sticky_movestone.png^[transformR90" ,
145
+ " jeija_sticky_movestone.png^[transformFXR90" ,
146
+ " jeija_sticky_movestone.png^[transformR90" ,
147
+ },
148
+ groups = {cracky = 3 },
149
+ description = " Vertical Sticky Movestone" ,
150
+ sounds = default .node_sound_stone_defaults (),
151
+ }, true , true )
130
152
153
+
154
+ -- crafting:
155
+ -- base recipe:
131
156
minetest .register_craft ({
132
157
output = " mesecons_movestones:movestone 2" ,
133
158
recipe = {
@@ -137,22 +162,51 @@ minetest.register_craft({
137
162
}
138
163
})
139
164
140
- -- STICKY_MOVESTONE
141
- mesecon .register_movestone (" mesecons_movestones:sticky_movestone" , {
142
- tiles = {" jeija_movestone_side.png" , " jeija_movestone_side.png" , " jeija_movestone_side.png" , " jeija_movestone_side.png" , " jeija_sticky_movestone.png" , " jeija_sticky_movestone.png" },
143
- inventory_image = minetest .inventorycube (" jeija_sticky_movestone.png" , " jeija_movestone_side.png" , " jeija_movestone_side.png" ),
144
- groups = {cracky = 3 },
145
- description = " Sticky Movestone" ,
146
- sounds = default .node_sound_stone_defaults (),
147
- }, true )
165
+ -- conversation:
166
+ minetest .register_craft ({
167
+ type = " shapeless" ,
168
+ output = " mesecons_movestones:movestone" ,
169
+ recipe = {" mesecons_movestones:movestone_vertical" },
170
+ })
171
+
172
+ minetest .register_craft ({
173
+ type = " shapeless" ,
174
+ output = " mesecons_movestones:movestone_vertical" ,
175
+ recipe = {" mesecons_movestones:movestone" },
176
+ })
177
+
178
+ minetest .register_craft ({
179
+ type = " shapeless" ,
180
+ output = " mesecons_movestones:sticky_movestone" ,
181
+ recipe = {" mesecons_movestones:sticky_movestone_vertical" },
182
+ })
183
+
184
+ minetest .register_craft ({
185
+ type = " shapeless" ,
186
+ output = " mesecons_movestones:sticky_movestone_vertical" ,
187
+ recipe = {" mesecons_movestones:sticky_movestone" },
188
+ })
148
189
190
+ -- make sticky:
149
191
minetest .register_craft ({
150
192
output = " mesecons_movestones:sticky_movestone" ,
151
193
recipe = {
152
194
{" mesecons_materials:glue" , " mesecons_movestones:movestone" , " mesecons_materials:glue" },
153
195
}
154
196
})
155
197
156
- -- Don't allow pushing movestones while they're active
157
- mesecon .register_mvps_stopper (" mesecons_movestones:movestone_active" )
158
- mesecon .register_mvps_stopper (" mesecons_movestones:sticky_movestone_active" )
198
+ minetest .register_craft ({
199
+ output = " mesecons_movestones:sticky_movestone_vertical" ,
200
+ recipe = {
201
+ {" mesecons_materials:glue" },
202
+ {" mesecons_movestones:movestone_vertical" },
203
+ {" mesecons_materials:glue" },
204
+ }
205
+ })
206
+
207
+
208
+ -- legacy code:
209
+ minetest .register_alias (" mesecons_movestones:movestone_active" ,
210
+ " mesecons_movestones:movestone" )
211
+ minetest .register_alias (" mesecons_movestones:sticky_movestone_active" ,
212
+ " mesecons_movestones:sticky_movestone" )
0 commit comments