commit | author | age
|
82cba9
|
1 |
|
354ee6
|
2 |
local S = technic.getter |
S |
3 |
|
f3bba0
|
4 |
local function inject_items (pos) |
VE |
5 |
local meta=minetest.env:get_meta(pos) |
|
6 |
local inv = meta:get_inventory() |
|
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 |
|
15 |
item0["count"]="1" |
|
16 |
local item1=pipeworks.tube_item({x=pos.x,y=pos.y,z=pos.z},item0) |
|
17 |
item1:get_luaentity().start_pos = {x=pos.x,y=pos.y,z=pos.z} |
|
18 |
item1:setvelocity({x=0, y=-1, z=0}) |
|
19 |
item1:setacceleration({x=0, y=0, z=0}) |
|
20 |
stack:take_item(1); |
|
21 |
inv:set_stack("main", i, stack) |
|
22 |
return |
|
23 |
end |
|
24 |
end |
|
25 |
end |
|
26 |
end |
|
27 |
if mode=="whole stacks" then |
|
28 |
local i=0 |
|
29 |
for _,stack in ipairs(inv:get_list("main")) do |
|
30 |
i=i+1 |
|
31 |
if stack then |
|
32 |
local item0=stack:to_table() |
|
33 |
if item0 then |
|
34 |
local item1=pipeworks.tube_item({x=pos.x,y=pos.y,z=pos.z},item0) |
|
35 |
item1:get_luaentity().start_pos = {x=pos.x,y=pos.y,z=pos.z} |
|
36 |
item1:setvelocity({x=0, y=-1, z=0}) |
|
37 |
item1:setacceleration({x=0, y=0, z=0}) |
|
38 |
stack:clear() |
|
39 |
inv:set_stack("main", i, stack) |
|
40 |
return |
|
41 |
end |
|
42 |
end |
|
43 |
end |
|
44 |
end |
|
45 |
|
|
46 |
end |
|
47 |
|
91cdd1
|
48 |
minetest.register_craft({ |
R |
49 |
output = 'technic:injector 1', |
|
50 |
recipe = { |
|
51 |
{'', 'technic:control_logic_unit',''}, |
|
52 |
{'', 'default:chest',''}, |
749df3
|
53 |
{'', 'pipeworks:tube_1',''}, |
91cdd1
|
54 |
} |
R |
55 |
}) |
|
56 |
|
82cba9
|
57 |
minetest.register_node("technic:injector", { |
354ee6
|
58 |
description = S("Injector"), |
74cf47
|
59 |
tiles = {"technic_injector_top.png", "technic_injector_bottom.png", "technic_injector_side.png", |
R |
60 |
"technic_injector_side.png", "technic_injector_side.png", "technic_injector_side.png"}, |
|
61 |
groups = chest_groups1, |
|
62 |
tube = tubes_properties, |
82cba9
|
63 |
sounds = default.node_sound_wood_defaults(), |
R |
64 |
on_construct = function(pos) |
|
65 |
local meta = minetest.env:get_meta(pos) |
|
66 |
meta:set_string("formspec", |
74cf47
|
67 |
"invsize[8,9;]".. |
354ee6
|
68 |
"label[0,0;"..S("Injector").."]".. |
fd26a8
|
69 |
"button[0,1;.8,.8;mode;]".. |
39c41a
|
70 |
"label[.8,1;"..S("Mode: %s"):format("single items").."]".. |
82cba9
|
71 |
"list[current_name;main;0,2;8,2;]".. |
R |
72 |
"list[current_player;main;0,5;8,4;]") |
354ee6
|
73 |
meta:set_string("infotext", S("Injector")) |
82cba9
|
74 |
local inv = meta:get_inventory() |
R |
75 |
inv:set_size("main", 8*4) |
fd26a8
|
76 |
meta:set_string("mode","single items") |
82cba9
|
77 |
end, |
R |
78 |
can_dig = function(pos,player) |
|
79 |
local meta = minetest.env:get_meta(pos); |
|
80 |
local inv = meta:get_inventory() |
|
81 |
return inv:is_empty("main") |
fd26a8
|
82 |
end, |
R |
83 |
on_receive_fields = function(pos, formanme, fields, sender) |
0809dd
|
84 |
local meta = minetest.env:get_meta(pos) |
S |
85 |
local mode=meta:get_string("mode") |
|
86 |
if fields.mode then |
|
87 |
if mode == "single items" then |
|
88 |
mode = "whole stacks" |
|
89 |
else |
|
90 |
mode = "single items" |
|
91 |
end |
|
92 |
meta:set_string("mode", mode) |
fd26a8
|
93 |
end |
0809dd
|
94 |
meta:set_string("formspec", |
fd26a8
|
95 |
"invsize[8,9;]".. |
354ee6
|
96 |
"label[0,0;"..S("Injector").."]".. |
fd26a8
|
97 |
"button[0,1;.8,.8;mode;]".. |
39c41a
|
98 |
"label[.8,1;"..S("Mode: %s"):format(S(mode)).."]".. |
fd26a8
|
99 |
"list[current_name;main;0,2;8,2;]".. |
R |
100 |
"list[current_player;main;0,5;8,4;]") |
82cba9
|
101 |
end, |
0809dd
|
102 |
allow_metadata_inventory_put = technic.machine_inventory_put, |
S |
103 |
allow_metadata_inventory_take = technic.machine_inventory_take, |
|
104 |
allow_metadata_inventory_move = technic.machine_inventory_move, |
82cba9
|
105 |
}) |
R |
106 |
|
74cf47
|
107 |
minetest.register_abm({ |
R |
108 |
nodenames = {"technic:injector"}, |
|
109 |
interval = 1, |
|
110 |
chance = 1, |
|
111 |
action = function(pos, node, active_object_count, active_object_count_wider) |
|
112 |
local pos1={} |
|
113 |
pos1.x = pos.x |
|
114 |
pos1.y = pos.y-1 |
|
115 |
pos1.z = pos.z |
|
116 |
local meta=minetest.env:get_meta(pos1) |
|
117 |
if meta:get_int("tubelike")==1 then inject_items (pos) end |
82cba9
|
118 |
end, |
R |
119 |
}) |
|
120 |
|