commit | author | age
|
82cba9
|
1 |
|
R |
2 |
minetest.register_craft({ |
|
3 |
type = "shapeless", |
|
4 |
output = 'technic:constructor_mk1_off 1', |
|
5 |
recipe = {'technic:nodebreaker_off', 'technic:deployer_off'}, |
|
6 |
|
|
7 |
}) |
|
8 |
minetest.register_craft({ |
|
9 |
type = "shapeless", |
|
10 |
output = 'technic:constructor_mk2_off 1', |
|
11 |
recipe = {'technic:constructor_mk1_off', 'technic:constructor_mk1_off'}, |
|
12 |
|
|
13 |
}) |
|
14 |
|
|
15 |
minetest.register_craft({ |
|
16 |
type = "shapeless", |
|
17 |
output = 'technic:constructor_mk3_off 1', |
|
18 |
recipe = {'technic:constructor_mk2_off', 'technic:constructor_mk2_off'}, |
|
19 |
|
|
20 |
}) |
|
21 |
|
|
22 |
mk1_on = function(pos, node) |
|
23 |
local meta = minetest.env:get_meta(pos) |
|
24 |
local inv = meta:get_inventory() |
|
25 |
local pos1={} |
|
26 |
pos1.x=pos.x |
|
27 |
pos1.y=pos.y |
|
28 |
pos1.z=pos.z |
|
29 |
if node.param2==3 then pos1.x=pos1.x+1 end |
|
30 |
if node.param2==2 then pos1.z=pos1.z+1 end |
|
31 |
if node.param2==1 then pos1.x=pos1.x-1 end |
|
32 |
if node.param2==0 then pos1.z=pos1.z-1 end |
|
33 |
|
|
34 |
if node.name == "technic:constructor_mk1_off" then |
|
35 |
hacky_swap_node(pos,"technic:constructor_mk1_on") |
|
36 |
nodeupdate(pos) |
|
37 |
local node1=minetest.env:get_node(pos1) |
|
38 |
deploy_node (inv,"slot1",pos1,node1,node) |
|
39 |
end |
|
40 |
end |
|
41 |
|
|
42 |
mk1_off = function(pos, node) |
|
43 |
if node.name == "technic:constructor_mk1_on" then |
|
44 |
hacky_swap_node(pos,"technic:constructor_mk1_off") |
|
45 |
nodeupdate(pos) |
|
46 |
end |
|
47 |
end |
|
48 |
|
|
49 |
|
|
50 |
minetest.register_node("technic:constructor_mk1_off", { |
|
51 |
description = "Constructor MK1", |
|
52 |
tile_images = {"technic_constructor_mk1_top_off.png","technic_constructor_mk1_bottom_off.png","technic_constructor_mk1_side2_off.png","technic_constructor_mk1_side1_off.png", |
|
53 |
"technic_constructor_back.png","technic_constructor_front_off.png"}, |
|
54 |
is_ground_content = true, |
|
55 |
paramtype2 = "facedir", |
|
56 |
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2, mesecon_receptor_off = 1, mesecon_effector_off = 1, mesecon = 2}, |
|
57 |
mesecons= {effector={action_on=mk1_on}}, |
|
58 |
sounds = default.node_sound_stone_defaults(), |
|
59 |
on_construct = function(pos) |
|
60 |
local meta = minetest.env:get_meta(pos) |
|
61 |
meta:set_string("formspec", |
|
62 |
"invsize[8,9;]".. |
|
63 |
"label[0,0;Constructor MK1]".. |
|
64 |
"label[5,0;Slot 1]".. |
|
65 |
"list[current_name;slot1;6,0;1,1;]".. |
|
66 |
"list[current_player;main;0,5;8,4;]") |
|
67 |
meta:set_string("infotext", "Constructor MK1") |
|
68 |
local inv = meta:get_inventory() |
|
69 |
inv:set_size("slot1", 1) |
|
70 |
end, |
|
71 |
|
|
72 |
can_dig = function(pos,player) |
|
73 |
local meta = minetest.env:get_meta(pos) |
|
74 |
local inv = meta:get_inventory() |
|
75 |
return inv:is_empty("slot1") |
|
76 |
end, |
|
77 |
}) |
|
78 |
|
|
79 |
minetest.register_node("technic:constructor_mk1_on", { |
|
80 |
description = "Constructor MK1", |
|
81 |
tile_images = {"technic_constructor_mk1_top_on.png","technic_constructor_mk1_bottom_on.png","technic_constructor_mk1_side2_on.png","technic_constructor_mk1_side1_on.png", |
|
82 |
"technic_constructor_back.png","technic_constructor_front_on.png"}, |
|
83 |
is_ground_content = true, |
|
84 |
paramtype2 = "facedir", |
|
85 |
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,mesecon = 2,not_in_creative_inventory=1}, |
|
86 |
mesecons= {effector={action_off=mk1_off}}, |
|
87 |
sounds = default.node_sound_stone_defaults(), |
|
88 |
}) |
|
89 |
|
|
90 |
|
|
91 |
--Constructor MK2 |
|
92 |
|
|
93 |
mk2_on = function(pos, node) |
|
94 |
local meta = minetest.env:get_meta(pos) |
|
95 |
local inv = meta:get_inventory() |
|
96 |
local pos1={} |
|
97 |
local pos2={} |
|
98 |
pos1.x=pos.x |
|
99 |
pos1.y=pos.y |
|
100 |
pos1.z=pos.z |
|
101 |
pos2.x=pos.x |
|
102 |
pos2.y=pos.y |
|
103 |
pos2.z=pos.z |
|
104 |
if node.param2==3 then pos1.x=pos1.x+1 pos2.x=pos2.x+2 end |
|
105 |
if node.param2==2 then pos1.z=pos1.z+1 pos2.z=pos2.z+2 end |
|
106 |
if node.param2==1 then pos1.x=pos1.x-1 pos2.x=pos2.x-2 end |
|
107 |
if node.param2==0 then pos1.z=pos1.z-1 pos2.z=pos2.z-2 end |
|
108 |
|
|
109 |
if node.name == "technic:constructor_mk2_off" then |
|
110 |
hacky_swap_node(pos,"technic:constructor_mk2_on") |
|
111 |
nodeupdate(pos) |
|
112 |
local node1=minetest.env:get_node(pos1) |
|
113 |
deploy_node (inv,"slot1",pos1,node1,node) |
|
114 |
local node1=minetest.env:get_node(pos2) |
|
115 |
deploy_node (inv,"slot2",pos2,node1,node) |
|
116 |
end |
|
117 |
end |
|
118 |
|
|
119 |
mk2_off = function(pos, node) |
|
120 |
if node.name == "technic:constructor_mk2_on" then |
|
121 |
hacky_swap_node(pos,"technic:constructor_mk2_off") |
|
122 |
nodeupdate(pos) |
|
123 |
end |
|
124 |
end |
|
125 |
|
|
126 |
minetest.register_node("technic:constructor_mk2_off", { |
|
127 |
description = "Constructor MK2", |
|
128 |
tile_images = {"technic_constructor_mk2_top_off.png","technic_constructor_mk2_bottom_off.png","technic_constructor_mk2_side2_off.png","technic_constructor_mk2_side1_off.png", |
|
129 |
"technic_constructor_back.png","technic_constructor_front_off.png"}, |
|
130 |
is_ground_content = true, |
|
131 |
paramtype2 = "facedir", |
|
132 |
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2, mesecon = 2}, |
|
133 |
mesecons= {effector={action_on=mk2_on}}, |
|
134 |
sounds = default.node_sound_stone_defaults(), |
|
135 |
on_construct = function(pos) |
|
136 |
local meta = minetest.env:get_meta(pos) |
|
137 |
meta:set_string("formspec", |
|
138 |
"invsize[8,9;]".. |
|
139 |
"label[0,0;Constructor MK2]".. |
|
140 |
"label[5,0;Slot 1]".. |
|
141 |
"list[current_name;slot1;6,0;1,1;]".. |
|
142 |
"label[5,1;Slot 2]".. |
|
143 |
"list[current_name;slot2;6,1;1,1;]".. |
|
144 |
"list[current_player;main;0,5;8,4;]") |
|
145 |
meta:set_string("infotext", "Constructor MK2") |
|
146 |
local inv = meta:get_inventory() |
|
147 |
inv:set_size("slot1", 1) |
|
148 |
inv:set_size("slot2", 1) |
|
149 |
end, |
|
150 |
|
|
151 |
can_dig = function(pos,player) |
|
152 |
local meta = minetest.env:get_meta(pos) |
|
153 |
local inv = meta:get_inventory() |
|
154 |
if inv:is_empty("slot1")==false or inv:is_empty("slot2")==false then return false end |
|
155 |
return true |
|
156 |
end, |
|
157 |
}) |
|
158 |
|
|
159 |
minetest.register_node("technic:constructor_mk2_on", { |
|
160 |
description = "Constructor MK2", |
|
161 |
tile_images = {"technic_constructor_mk2_top_on.png","technic_constructor_mk2_bottom_on.png","technic_constructor_mk2_side2_on.png","technic_constructor_mk2_side1_on.png", |
|
162 |
"technic_constructor_back.png","technic_constructor_front_on.png"}, |
|
163 |
is_ground_content = true, |
|
164 |
paramtype2 = "facedir", |
|
165 |
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2, mesecon = 2, not_in_creative_inventory=1}, |
|
166 |
mesecons= {effector={action_off=mk2_off}}, |
|
167 |
sounds = default.node_sound_stone_defaults(), |
|
168 |
}) |
|
169 |
|
|
170 |
|
|
171 |
-- Constructor MK3 |
|
172 |
mk3_on = function(pos, node) |
|
173 |
local meta = minetest.env:get_meta(pos) |
|
174 |
local inv = meta:get_inventory() |
|
175 |
|
|
176 |
local pos1={} |
|
177 |
local pos2={} |
|
178 |
local pos3={} |
|
179 |
local pos4={} |
|
180 |
|
|
181 |
pos1.x=pos.x |
|
182 |
pos1.y=pos.y |
|
183 |
pos1.z=pos.z |
|
184 |
|
|
185 |
pos2.x=pos.x |
|
186 |
pos2.y=pos.y |
|
187 |
pos2.z=pos.z |
|
188 |
|
|
189 |
pos3.x=pos.x |
|
190 |
pos3.y=pos.y |
|
191 |
pos3.z=pos.z |
|
192 |
|
|
193 |
pos4.x=pos.x |
|
194 |
pos4.y=pos.y |
|
195 |
pos4.z=pos.z |
|
196 |
|
|
197 |
if node.param2==3 then pos1.x=pos1.x+1 pos2.x=pos2.x+2 pos3.x=pos3.x+3 pos4.x=pos4.x+4 end |
|
198 |
if node.param2==2 then pos1.z=pos1.z+1 pos2.z=pos2.z+2 pos3.z=pos3.z+3 pos4.z=pos4.z+4 end |
|
199 |
if node.param2==1 then pos1.x=pos1.x-1 pos2.x=pos2.x-2 pos3.x=pos3.x-3 pos4.x=pos4.x-4 end |
|
200 |
if node.param2==0 then pos1.z=pos1.z-1 pos2.z=pos2.z-2 pos3.z=pos3.z-3 pos4.z=pos4.z-4 end |
|
201 |
|
|
202 |
if node.name == "technic:constructor_mk3_off" then |
|
203 |
hacky_swap_node(pos,"technic:constructor_mk3_on") |
|
204 |
nodeupdate(pos) |
|
205 |
local node1=minetest.env:get_node(pos1) |
|
206 |
deploy_node (inv,"slot1",pos1,node1,node) |
|
207 |
local node1=minetest.env:get_node(pos2) |
|
208 |
deploy_node (inv,"slot2",pos2,node1,node) |
|
209 |
local node1=minetest.env:get_node(pos3) |
|
210 |
deploy_node (inv,"slot3",pos3,node1,node) |
|
211 |
local node1=minetest.env:get_node(pos4) |
|
212 |
deploy_node (inv,"slot4",pos4,node1,node) |
|
213 |
end |
|
214 |
end |
|
215 |
|
|
216 |
mk3_off = function(pos, node) |
|
217 |
if node.name == "technic:constructor_mk3_on" then |
|
218 |
hacky_swap_node(pos,"technic:constructor_mk3_off") |
|
219 |
nodeupdate(pos) |
|
220 |
end |
|
221 |
end |
|
222 |
|
|
223 |
minetest.register_node("technic:constructor_mk3_off", { |
|
224 |
description = "Constructor MK3", |
|
225 |
tile_images = {"technic_constructor_mk3_top_off.png","technic_constructor_mk3_bottom_off.png","technic_constructor_mk3_side2_off.png","technic_constructor_mk3_side1_off.png", |
|
226 |
"technic_constructor_back.png","technic_constructor_front_off.png"}, |
|
227 |
is_ground_content = true, |
|
228 |
paramtype2 = "facedir", |
|
229 |
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2, mesecon = 2}, |
|
230 |
mesecons= {effector={action_on=mk3_on}}, |
|
231 |
sounds = default.node_sound_stone_defaults(), |
|
232 |
on_construct = function(pos) |
|
233 |
local meta = minetest.env:get_meta(pos) |
|
234 |
meta:set_string("formspec", |
|
235 |
"invsize[8,9;]".. |
|
236 |
"label[0,0;Constructor MK2]".. |
|
237 |
"label[5,0;Slot 1]".. |
|
238 |
"list[current_name;slot1;6,0;1,1;]".. |
|
239 |
"label[5,1;Slot 2]".. |
|
240 |
"list[current_name;slot2;6,1;1,1;]".. |
|
241 |
"label[5,2;Slot 3]".. |
|
242 |
"list[current_name;slot3;6,2;1,1;]".. |
|
243 |
"label[5,3;Slot 4]".. |
|
244 |
"list[current_name;slot4;6,3;1,1;]".. |
|
245 |
"list[current_player;main;0,5;8,4;]") |
|
246 |
meta:set_string("infotext", "Constructor MK3") |
|
247 |
local inv = meta:get_inventory() |
|
248 |
inv:set_size("slot1", 1) |
|
249 |
inv:set_size("slot2", 1) |
|
250 |
inv:set_size("slot3", 1) |
|
251 |
inv:set_size("slot4", 1) |
|
252 |
|
|
253 |
end, |
|
254 |
|
|
255 |
can_dig = function(pos,player) |
|
256 |
local meta = minetest.env:get_meta(pos) |
|
257 |
local inv = meta:get_inventory() |
|
258 |
if inv:is_empty("slot1")==false or inv:is_empty("slot2")==false or inv:is_empty("slot3")==false or inv:is_empty("slot4")==false then return false end |
|
259 |
return true |
|
260 |
end, |
|
261 |
}) |
|
262 |
|
|
263 |
minetest.register_node("technic:constructor_mk3_on", { |
|
264 |
description = "Constructor MK3", |
|
265 |
tile_images = {"technic_constructor_mk3_top_on.png","technic_constructor_mk3_bottom_on.png","technic_constructor_mk3_side2_on.png","technic_constructor_mk3_side1_on.png", |
|
266 |
"technic_constructor_back.png","technic_constructor_front_on.png"}, |
|
267 |
is_ground_content = true, |
|
268 |
paramtype2 = "facedir", |
|
269 |
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2, mesecon = 2,not_in_creative_inventory=1}, |
|
270 |
mesecons= {effector={action_off=mk3_off}}, |
|
271 |
sounds = default.node_sound_stone_defaults(), |
|
272 |
}) |
|
273 |
|
|
274 |
|
|
275 |
deploy_node =function (inv, slot_name, pos1, node1, node) |
a1da74
|
276 |
if node1.name == "air" then |
DM |
277 |
if not inv:is_empty(slot_name) then |
82cba9
|
278 |
stack1=inv:get_list(slot_name) |
a1da74
|
279 |
local def = stack1[1]:get_definition() |
DM |
280 |
if def.type == "node" then |
|
281 |
node_to_be_placed={name=stack1[1]:get_name(), param1=0, param2=node.param2} |
|
282 |
minetest.env:set_node(pos1,node_to_be_placed) |
|
283 |
stack1[1]:take_item() |
|
284 |
inv:set_stack(slot_name, 1, stack1[1]) |
|
285 |
elseif def.type == "craft" then |
0039f3
|
286 |
if def.on_place then |
DM |
287 |
-- print("deploy_node: item has on_place. trying...") |
|
288 |
local ok, stk = pcall(def.on_place, stack1[1], nil, { |
|
289 |
-- Fake pointed_thing |
|
290 |
type = "node", |
|
291 |
above = pos1, |
|
292 |
under = { x=pos1.x, y=pos1.y-1, z=pos1.z }, |
|
293 |
}) |
|
294 |
if ok then |
|
295 |
-- print("deploy_node: on_place succeeded!") |
|
296 |
inv:set_stack(slot_name, 1, stk or stack1[1]) |
|
297 |
return |
|
298 |
-- else |
|
299 |
-- print("deploy_node: WARNING: error while running on_place: "..tostring(stk)) |
|
300 |
end |
|
301 |
end |
a1da74
|
302 |
minetest.item_place_object(stack1[1], nil, { |
DM |
303 |
-- Fake pointed_thing |
|
304 |
type = "node", |
|
305 |
above = pos1, |
|
306 |
under = pos1, |
|
307 |
}) |
|
308 |
inv:set_stack(slot_name, 1, nil) |
82cba9
|
309 |
end |
R |
310 |
end |
a1da74
|
311 |
return |
DM |
312 |
end |
|
313 |
if node1.name == "ignore" or |
|
314 |
node1.name == "default:lava_source" or |
|
315 |
node1.name == "default:lava_flowing" or |
|
316 |
node1.name == "default:water_source" or |
|
317 |
node1.name == "default:water_flowing" |
|
318 |
then return end |
|
319 |
if inv:room_for_item(slot_name,node1) then |
|
320 |
local def = minetest.registered_nodes[node1.name] |
|
321 |
if not def then return end |
|
322 |
local drop = def.drop or node1.name |
|
323 |
if type(drop) == "table" then |
|
324 |
local pr = PseudoRandom(math.random()) |
|
325 |
local c = 0 |
|
326 |
local loop = 0 -- Prevent infinite loop |
|
327 |
while (c < (drop.max_items or 1)) and (loop < 1000) do |
|
328 |
local i = math.floor(pr:next(1, #drop.items)) |
|
329 |
if pr:next(1, drop.items[i].rarity or 1) == 1 then |
|
330 |
for _,item in ipairs(drop.items[i].items) do |
|
331 |
inv:add_item(slot_name,item) |
|
332 |
end |
|
333 |
c = c + 1 |
|
334 |
end |
|
335 |
loop = loop + 1 |
|
336 |
end |
|
337 |
minetest.env:remove_node(pos1) |
|
338 |
elseif type(drop) == "string" then |
|
339 |
inv:add_item(slot_name,drop) |
82cba9
|
340 |
minetest.env:remove_node(pos1) |
R |
341 |
end |
a1da74
|
342 |
end |
82cba9
|
343 |
|
R |
344 |
end |