commit | author | age
|
82cba9
|
1 |
|
354ee6
|
2 |
local S = technic.getter |
S |
3 |
|
f3bba0
|
4 |
local function inject_items (pos) |
a41390
|
5 |
local meta=minetest.get_meta(pos) |
f3bba0
|
6 |
local inv = meta:get_inventory() |
VE |
7 |
local mode=meta:get_string("mode") |
|
8 |
if mode=="single items" then |
|
9 |
local i=0 |
|
10 |
for _,stack in ipairs(inv:get_list("main")) do |
|
11 |
i=i+1 |
|
12 |
if stack then |
|
13 |
local item0=stack:to_table() |
|
14 |
if item0 then |
baf7f6
|
15 |
item0["count"] = "1" |
049129
|
16 |
technic.tube_inject_item(pos, pos, vector.new(0, -1, 0), item0) |
baf7f6
|
17 |
stack:take_item(1) |
f3bba0
|
18 |
inv:set_stack("main", i, stack) |
VE |
19 |
return |
|
20 |
end |
|
21 |
end |
|
22 |
end |
|
23 |
end |
|
24 |
if mode=="whole stacks" then |
|
25 |
local i=0 |
|
26 |
for _,stack in ipairs(inv:get_list("main")) do |
|
27 |
i=i+1 |
|
28 |
if stack then |
|
29 |
local item0=stack:to_table() |
|
30 |
if item0 then |
049129
|
31 |
technic.tube_inject_item(pos, pos, vector.new(0, -1, 0), item0) |
f3bba0
|
32 |
stack:clear() |
VE |
33 |
inv:set_stack("main", i, stack) |
|
34 |
return |
|
35 |
end |
|
36 |
end |
|
37 |
end |
|
38 |
end |
|
39 |
|
|
40 |
end |
|
41 |
|
91cdd1
|
42 |
minetest.register_craft({ |
R |
43 |
output = 'technic:injector 1', |
|
44 |
recipe = { |
|
45 |
{'', 'technic:control_logic_unit',''}, |
|
46 |
{'', 'default:chest',''}, |
749df3
|
47 |
{'', 'pipeworks:tube_1',''}, |
91cdd1
|
48 |
} |
R |
49 |
}) |
|
50 |
|
827509
|
51 |
local function set_injector_formspec(meta) |
Z |
52 |
local is_stack = meta:get_string("mode") == "whole stacks" |
|
53 |
meta:set_string("formspec", |
|
54 |
"invsize[8,9;]".. |
|
55 |
"item_image[0,0;1,1;technic:injector]".. |
|
56 |
"label[1,0;"..S("Self-Contained Injector").."]".. |
|
57 |
(is_stack and |
|
58 |
"button[0,1;2,1;mode_item;"..S("Stackwise").."]" or |
|
59 |
"button[0,1;2,1;mode_stack;"..S("Itemwise").."]").. |
|
60 |
"list[current_name;main;0,2;8,2;]".. |
d732c8
|
61 |
"list[current_player;main;0,5;8,4;]".. |
E |
62 |
"listring[]") |
827509
|
63 |
end |
Z |
64 |
|
82cba9
|
65 |
minetest.register_node("technic:injector", { |
827509
|
66 |
description = S("Self-Contained Injector"), |
74cf47
|
67 |
tiles = {"technic_injector_top.png", "technic_injector_bottom.png", "technic_injector_side.png", |
R |
68 |
"technic_injector_side.png", "technic_injector_side.png", "technic_injector_side.png"}, |
ce40d1
|
69 |
groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2, tubedevice=1, tubedevice_receiver=1}, |
7ed1aa
|
70 |
tube = { |
T |
71 |
can_insert = function(pos, node, stack, direction) |
af3922
|
72 |
local onestack = stack:peek_item(1) |
VE |
73 |
return minetest.get_meta(pos):get_inventory():room_for_item("main", onestack) |
7ed1aa
|
74 |
end, |
T |
75 |
insert_object = function(pos, node, stack, direction) |
af3922
|
76 |
return minetest.get_meta(pos):get_inventory():add_item("main", stack) |
7ed1aa
|
77 |
end, |
T |
78 |
connect_sides = {left=1, right=1, front=1, back=1, top=1, bottom=1}, |
|
79 |
}, |
82cba9
|
80 |
sounds = default.node_sound_wood_defaults(), |
R |
81 |
on_construct = function(pos) |
a41390
|
82 |
local meta = minetest.get_meta(pos) |
827509
|
83 |
meta:set_string("infotext", S("Self-Contained Injector")) |
82cba9
|
84 |
local inv = meta:get_inventory() |
db0f8e
|
85 |
inv:set_size("main", 8*2) |
fd26a8
|
86 |
meta:set_string("mode","single items") |
827509
|
87 |
set_injector_formspec(meta) |
82cba9
|
88 |
end, |
R |
89 |
can_dig = function(pos,player) |
a41390
|
90 |
local meta = minetest.get_meta(pos); |
82cba9
|
91 |
local inv = meta:get_inventory() |
R |
92 |
return inv:is_empty("main") |
fd26a8
|
93 |
end, |
R |
94 |
on_receive_fields = function(pos, formanme, fields, sender) |
a41390
|
95 |
local meta = minetest.get_meta(pos) |
827509
|
96 |
if fields.mode_item then meta:set_string("mode", "single items") end |
Z |
97 |
if fields.mode_stack then meta:set_string("mode", "whole stacks") end |
|
98 |
set_injector_formspec(meta) |
82cba9
|
99 |
end, |
0809dd
|
100 |
allow_metadata_inventory_put = technic.machine_inventory_put, |
S |
101 |
allow_metadata_inventory_take = technic.machine_inventory_take, |
|
102 |
allow_metadata_inventory_move = technic.machine_inventory_move, |
bccefd
|
103 |
after_place_node = pipeworks.after_place, |
VE |
104 |
after_dig_node = pipeworks.after_dig |
82cba9
|
105 |
}) |
R |
106 |
|
74cf47
|
107 |
minetest.register_abm({ |
78f16c
|
108 |
label = "Machines: run injector", |
74cf47
|
109 |
nodenames = {"technic:injector"}, |
R |
110 |
interval = 1, |
|
111 |
chance = 1, |
|
112 |
action = function(pos, node, active_object_count, active_object_count_wider) |
35b10a
|
113 |
local pos1 = vector.add(pos, vector.new(0, -1, 0)) |
N |
114 |
local node1 = minetest.get_node(pos1) |
|
115 |
if minetest.get_item_group(node1.name, "tubedevice") > 0 then |
|
116 |
inject_items(pos) |
|
117 |
end |
82cba9
|
118 |
end, |
R |
119 |
}) |
|
120 |
|