1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
|
minetest.register_node("factory:belt", {
description = "Conveyor Belt",
tiles = {{name="factory_belt_top_animation.png", animation={type="vertical_frames", aspect_w=16, aspect_h=16, length=0.4}}, "factory_belt_bottom.png", "factory_belt_side.png",
"factory_belt_side.png", "factory_belt_side.png", "factory_belt_side.png"},
groups = {cracky=1},
drawtype = "nodebox",
paramtype = "light",
paramtype2 = "facedir",
is_ground_content = true,
legacy_facedir_simple = true,
node_box = {
type = "fixed",
fixed = {{-0.5,-0.5,-0.5,0.5,0.0625,0.5},}
},
})
minetest.register_abm({
nodenames = {"factory:belt"},
neighbors = nil,
interval = 1,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
local all_objects = minetest.get_objects_inside_radius(pos, 1)
local _,obj
for _,obj in ipairs(all_objects) do
if not obj:is_player() and obj:get_luaentity() and obj:get_luaentity().name == "__builtin:item" then
local a = minetest.facedir_to_dir(minetest.get_node(pos).param2)
local b = {x = obj:getpos().x + (a.x / 3.5), y = obj:getpos().y, z = obj:getpos().z + (a.z / 3.5),}
obj:moveto(b, false)
end
end
end,
})
minetest.register_node("factory:arm",{
drawtype = "nodebox",
tiles = {"factory_steel_noise.png"},
paramtype = "light",
description = "Pneumatic Mover",
groups = {cracky=3},
paramtype2 = "facedir",
legacy_facedir_simple = true,
node_box = {
type = "fixed",
fixed = {
{-0.5,-0.5,-0.5,0.5,-0.4375,0.5}, --base1
{-0.125,-0.5,-0.375,0.125,0.0625,0.375}, --base2
{-0.125,0.25,-0.5,0.125,0.3125,0.375}, --tube
{-0.375,-0.5,-0.0625,0.375,0.0625,0.0625}, --base3
{-0.125,-0.125,0.375,0.125,0.125,0.5}, --tube2
{-0.125,0.0625,0.3125,0.125,0.25,0.375}, --NodeBox6
{-0.125,0.0625,-0.5,-0.0625,0.25,0.3125}, --NodeBox7
{0.0625,0.0625,-0.5,0.125,0.25,0.3125}, --NodeBox8
{-0.0625,0.0625,-0.5,0.0625,0.125,0.3125}, --NodeBox9
}
},
selection_box = {
type = "fixed",
fixed = {
{-0.5,-0.5,-0.5,0.5,0.5,0.5},
}
},
})
minetest.register_abm({
nodenames = {"factory:arm"},
neighbors = nil,
interval = 1,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
local all_objects = minetest.get_objects_inside_radius(pos, 0.8)
local _,obj
for _,obj in ipairs(all_objects) do
if not obj:is_player() and obj:get_luaentity() and obj:get_luaentity().name == "__builtin:item" then
local a = minetest.facedir_to_dir(minetest.get_node(pos).param2)
local b = {x = pos.x + a.x, y = pos.y + a.y, z = pos.z + a.z,}
local target = minetest.get_node(b)
local stack = ItemStack(obj:get_luaentity().itemstring)
if target.name == "default:chest" or target.name == "default:chest_locked" then
local meta = minetest.env:get_meta(b)
local inv = meta:get_inventory()
if inv:room_for_item("main", stack) then
inv:add_item("main", stack)
obj:remove()
else
obj:moveto({x = pos.x + (a.x * 2), y = pos.y + 0.5, z = pos.z + (a.z * 2)}, false)
end
end
for i,v in ipairs(armDevicesFurnacelike) do
if target.name == v then
local a = minetest.facedir_to_dir(minetest.get_node(pos).param2)
local b = {x = pos.x + a.x, y = pos.y + a.y, z = pos.z + a.z,}
local meta = minetest.env:get_meta(b)
local inv = meta:get_inventory()
if minetest.dir_to_facedir({x = -a.x, y = -a.y, z = -a.z}) == minetest.get_node(b).param2 then
-- back, fuel
if inv:room_for_item("fuel", stack) then
inv:add_item("fuel", stack)
obj:remove()
else
obj:moveto({x = pos.x + (a.x * 2), y = pos.y + 0.5, z = pos.z + (a.z * 2)}, false)
end
else
-- everytin else, src
if inv:room_for_item("src", stack) then
inv:add_item("src", stack)
obj:remove()
else
obj:moveto({x = pos.x + (a.x * 2), y = pos.y + 0.5, z = pos.z + (a.z * 2)}, false)
end
end
end
end
end
end
end,
})
function factory.register_taker(prefix, suffix, speed, name, ctiles)
minetest.register_node("factory:"..prefix.."taker"..suffix,{
drawtype = "nodebox",
tiles = ctiles,
paramtype = "light",
description = name,
groups = {cracky=3},
paramtype2 = "facedir",
legacy_facedir_simple = true,
node_box = {
type = "fixed",
fixed = {
{-0.5,-0.5,-0.5,0.5,-0.4375,0.5}, --base1
{-0.125,-0.5,-0.375,0.125,0.0625,0.375}, --base2
{-0.125,0.25,-0.5,0.125,0.3125,0.375}, --tube
{-0.375,-0.5,-0.0625,0.375,0.0625,0.0625}, --base3
{-0.125,-0.125,0.375,0.125,0.125,0.5}, --tube2
{-0.125,0.0625,0.3125,0.125,0.25,0.375}, --NodeBox6
{-0.125,0.0625,-0.5,-0.0625,0.25,0.3125}, --NodeBox7
{0.0625,0.0625,-0.5,0.125,0.25,0.3125}, --NodeBox8
{-0.0625,0.0625,-0.5,0.0625,0.125,0.3125}, --NodeBox9
}
},
selection_box = {
type = "fixed",
fixed = {
{-0.5,-0.5,-0.5,0.5,0.5,0.5},
}
},
})
minetest.register_abm({
nodenames = {"factory:"..prefix.."taker"..suffix},
neighbors = nil,
interval = speed,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
local a = minetest.facedir_to_dir(minetest.get_node(pos).param2)
local b = {x = pos.x + a.x, y = pos.y + a.y, z = pos.z + a.z,}
local target = minetest.get_node(b)
if target.name == "default:chest" or target.name == "default:chest_locked" then
local meta = minetest.env:get_meta(b)
local inv = meta:get_inventory()
if not inv:is_empty("main") then
local list = inv:get_list("main")
local i,item
for i,item in ipairs(inv:get_list("main")) do
if item:get_name() ~= "" then
local droppos = {x = pos.x - (a.x/1.5), y = pos.y + 0.5, z = pos.z - (a.z/1.5)}
if factory.logTaker then print(name.." at "..pos.x..", "..pos.y..", "..pos.z.." takes "..item:get_name().." from "..target.name) end
minetest.item_drop(item:peek_item(1), "", droppos)
item:take_item()
inv:set_stack("main", i, item)
return
end
end
end
end
for i,v in ipairs(takerDevicesFurnacelike) do
if target.name == v then
local meta = minetest.env:get_meta(b)
local inv = meta:get_inventory()
if not inv:is_empty("dst") then
local list = inv:get_list("dst")
for k,item in ipairs(inv:get_list("dst")) do
if item:get_name() ~= "" then
local droppos = {x = pos.x - (a.x/1.5), y = pos.y + 0.5, z = pos.z - (a.z/1.5)}
if factory.logTaker then print(name.." at "..pos.x..", "..pos.y..", "..pos.z.." takes "..item:get_name().." from "..target.name) end
minetest.item_drop(item:peek_item(1), "", droppos)
item:take_item()
inv:set_stack("dst", k, item)
return
end
end
end
end
end
end,
})
end
factory.register_taker("", "", 2.5, "Pneumatic Taker", {"factory_steel_noise_red.png"})
factory.register_taker("", "_gold", 1.8, "Pneumatic Taker Mk II", {"factory_steel_noise_gold.png"})
factory.register_taker("", "_diamond", 1.2, "Pneumatic Taker MK III", {"factory_steel_noise_diamond.png"})
minetest.register_node("factory:smoke_tube", {
drawtype = "nodebox",
tiles = {"factory_machine_brick_1.png"},
paramtype = "light",
description = "Smoke Tube",
groups = {cracky=3},
node_box = {
type = "fixed",
fixed = {
{-0.125,-0.5,0.3125,0.125,0.5,0.375},
{-0.125,-0.5,-0.375,0.125,0.5,-0.3125},
{0.3125,-0.5,-0.125,0.375,0.5,0.125},
{-0.375,-0.5,-0.125,-0.3125,0.5,0.125},
{0.125,-0.5,0.25,0.25,0.5,0.3125},
{0.25,-0.5,0.125,0.3125,0.5,0.25},
{0.25,-0.5,-0.25,0.3125,0.5,-0.125},
{0.125,-0.5,-0.3125,0.25,0.5,-0.25},
{-0.25,-0.5,-0.3125,-0.125,0.5,-0.25},
{-0.3125,-0.5,-0.25,-0.25,0.5,-0.125},
{-0.3125,-0.5,0.125,-0.25,0.5,0.25},
{-0.25,-0.5,0.25,-0.125,0.5,0.3125},
}
},
selection_box = {
type = "fixed",
fixed = {
{-0.375,-0.5,-0.375,0.375,0.5,0.375},
}
},
})
function qarm_handle (a, b, target, stack, minv, obj)
if target.name == "default:chest" or target.name == "default:chest_locked" then
local meta = minetest.env:get_meta(b)
local inv = meta:get_inventory()
if inv:room_for_item("main", stack) then
inv:add_item("main", stack)
if obj~=nil then obj:remove() end
elseif minv:room_for_item("main", stack) then
minv:add_item("main", stack)
if obj~=nil then obj:remove() end
else
if obj~=nil then obj:moveto({x = pos.x + (a.x * 2), y = pos.y + 0.5, z = pos.z + (a.z * 2)}, false) end
end
end
for i,v in ipairs(armDevicesFurnacelike) do
if target.name == v then
local meta = minetest.env:get_meta(b)
local inv = meta:get_inventory()
if minetest.dir_to_facedir({x = -a.x, y = -a.y, z = -a.z}) == minetest.get_node(b).param2 then
-- back, fuel
if inv:room_for_item("fuel", stack) then
inv:add_item("fuel", stack)
if obj~=nil then obj:remove() end
elseif minv:room_for_item("main", stack) then
minv:add_item("main", stack)
if obj~=nil then obj:remove() end
else
if obj~=nil then obj:moveto({x = pos.x + (a.x * 2), y = pos.y + 0.5, z = pos.z + (a.z * 2)}, false) end
end
else
-- everytin else, src
if inv:room_for_item("src", stack) then
inv:add_item("src", stack)
if obj~=nil then obj:remove() end
elseif minv:room_for_item("main", stack) then
minv:add_item("main", stack)
if obj~=nil then obj:remove() end
else
if obj~=nil then obj:moveto({x = pos.x + (a.x * 2), y = pos.y + 0.5, z = pos.z + (a.z * 2)}, false) end
end
end
end
end
end
factory.qformspec =
"size[8,8.5]"..
factory_gui_bg..
factory_gui_bg_img..
factory_gui_slots..
"list[current_name;main;0,0.3;8,3;]"..
"list[current_player;main;0,4.25;8,1;]"..
"list[current_player;main;0,5.5;8,3;8]"..
factory.get_hotbar_bg(0,4.25)
minetest.register_node("factory:queuedarm",{
drawtype = "nodebox",
tiles = {"factory_steel_noise.png"},
paramtype = "light",
description = "Queued Pneumatic Mover",
groups = {cracky=3},
paramtype2 = "facedir",
legacy_facedir_simple = true,
node_box = {
type = "fixed",
fixed = {
{-0.5,-0.5,-0.5,0.5,-0.4375,0.5}, --base1
{-0.125,-0.5,-0.375,0.125,0.0625,0.375}, --base2
{-0.125,0.25,-0.5,0.125,0.3125,0.375}, --tube
{-0.375,-0.5,-0.1875,0.375,0.0625,0.0625}, --base3
{-0.125,-0.125,0.375,0.125,0.125,0.5}, --tube2
{-0.125,0.0625,0.3125,0.125,0.25,0.375}, --nodebox6
{-0.125,0.0625,-0.5,-0.0625,0.25,0.3125}, --nodebox7
{0.0625,0.0625,-0.5,0.125,0.25,0.3125}, --nodebox8
{-0.0625,0.0625,-0.5,0.0625,0.125,0.3125}, --nodebox9
{-0.25,0.3125,-0.125,0.25,0.8,0.375}, --NodeBox10
{-0.1875,0.1875,-0.5,-0.125,0.3125,0.375}, --NodeBox11
{0.125,0.1875,-0.5,0.1875,0.3125,0.375}, --NodeBox12
{-0.125,0.3125,-0.4375,0.125,0.5,-0.125}, --NodeBox13
}
},
selection_box = {
type = "fixed",
fixed = {
{-0.5,-0.5,-0.5,0.5,0.5,0.5},
}
},
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("formspec",factory.qformspec)
meta:set_string("infotext", "Queued Pneumatic Mover")
local inv = meta:get_inventory()
inv:set_size("main", 8*3)
end,
can_dig = function(pos,player)
local meta = minetest.get_meta(pos);
local inv = meta:get_inventory()
return inv:is_empty("main")
end,
on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
minetest.log("action", player:get_player_name()..
" moves stuff in queued mover at "..minetest.pos_to_string(pos))
end,
on_metadata_inventory_put = function(pos, listname, index, stack, player)
minetest.log("action", player:get_player_name()..
" moves stuff to queued mover at "..minetest.pos_to_string(pos))
end,
on_metadata_inventory_take = function(pos, listname, index, stack, player)
minetest.log("action", player:get_player_name()..
" takes stuff from queued mover at "..minetest.pos_to_string(pos))
end,
})
minetest.register_abm({
nodenames = {"factory:queuedarm"},
neighbors = nil,
interval = 1,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
local mmeta = minetest.env:get_meta(pos)
local minv = mmeta:get_inventory()
local all_objects = minetest.get_objects_inside_radius(pos, 0.8)
local a = minetest.facedir_to_dir(minetest.get_node(pos).param2)
local b = {x = pos.x + a.x, y = pos.y + a.y, z = pos.z + a.z,}
local target = minetest.get_node(b)
for _,obj in ipairs(all_objects) do
if not obj:is_player() and obj:get_luaentity() and obj:get_luaentity().name == "__builtin:item" then
local stack = ItemStack(obj:get_luaentity().itemstring)
qarm_handle(a, b, target, stack, minv, obj)
end
end
for i,stack in ipairs(minv:get_list("main")) do
if stack:get_name() ~= "" then
minv:remove_item("main", stack)
qarm_handle(a, b, target, stack, minv, nil)
return
end
end
end,
})
minetest.register_node("factory:factory_brick", {
description = "Factory Brick",
tiles = {"factory_brick.png"},
is_ground_content = true,
groups = {cracky=3, stone=1}
})
|