commit | author | age
|
aa8af0
|
1 |
|
N |
2 |
local S = technic.getter |
|
3 |
|
5d05f5
|
4 |
local fs_helpers = pipeworks.fs_helpers |
VE |
5 |
|
aa8af0
|
6 |
local tube = { |
N |
7 |
insert_object = function(pos, node, stack, direction) |
|
8 |
local meta = minetest.get_meta(pos) |
|
9 |
local inv = meta:get_inventory() |
|
10 |
return inv:add_item("src", stack) |
|
11 |
end, |
|
12 |
can_insert = function(pos, node, stack, direction) |
|
13 |
local meta = minetest.get_meta(pos) |
|
14 |
local inv = meta:get_inventory() |
5d05f5
|
15 |
if meta:get_int("splitstacks") == 1 then |
VE |
16 |
stack = stack:peek_item(1) |
|
17 |
end |
|
18 |
return inv:room_for_item("src", stack) |
aa8af0
|
19 |
end, |
N |
20 |
connect_sides = {left = 1, right = 1, back = 1, top = 1, bottom = 1}, |
|
21 |
} |
|
22 |
|
83c649
|
23 |
local connect_default = {"bottom", "back", "left", "right"} |
S |
24 |
|
814646
|
25 |
local function round(v) |
Z |
26 |
return math.floor(v + 0.5) |
|
27 |
end |
|
28 |
|
aa8af0
|
29 |
function technic.register_base_machine(data) |
N |
30 |
local typename = data.typename |
dd65a6
|
31 |
local input_size = technic.recipes[typename].input_size |
aa8af0
|
32 |
local machine_name = data.machine_name |
N |
33 |
local machine_desc = data.machine_desc |
|
34 |
local tier = data.tier |
|
35 |
local ltier = string.lower(tier) |
|
36 |
|
83c649
|
37 |
local groups = {cracky = 2, technic_machine = 1, ["technic_"..ltier] = 1} |
aa8af0
|
38 |
if data.tube then |
N |
39 |
groups.tubedevice = 1 |
|
40 |
groups.tubedevice_receiver = 1 |
|
41 |
end |
83c649
|
42 |
local active_groups = {not_in_creative_inventory = 1} |
S |
43 |
for k, v in pairs(groups) do active_groups[k] = v end |
aa8af0
|
44 |
|
N |
45 |
local formspec = |
|
46 |
"invsize[8,9;]".. |
dd65a6
|
47 |
"list[current_name;src;"..(4-input_size)..",1;"..input_size..",1;]".. |
aa8af0
|
48 |
"list[current_name;dst;5,1;2,2;]".. |
N |
49 |
"list[current_player;main;0,5;8,4;]".. |
d732c8
|
50 |
"label[0,0;"..machine_desc:format(tier).."]".. |
E |
51 |
"listring[current_name;dst]".. |
|
52 |
"listring[current_player;main]".. |
|
53 |
"listring[current_name;src]".. |
|
54 |
"listring[current_player;main]" |
aa8af0
|
55 |
if data.upgrade then |
N |
56 |
formspec = formspec.. |
|
57 |
"list[current_name;upgrade1;1,3;1,1;]".. |
|
58 |
"list[current_name;upgrade2;2,3;1,1;]".. |
d732c8
|
59 |
"label[1,4;"..S("Upgrade Slots").."]".. |
E |
60 |
"listring[current_name;upgrade1]".. |
|
61 |
"listring[current_player;main]".. |
|
62 |
"listring[current_name;upgrade2]".. |
|
63 |
"listring[current_player;main]" |
aa8af0
|
64 |
end |
N |
65 |
|
563a4c
|
66 |
local run = function(pos, node) |
N |
67 |
local meta = minetest.get_meta(pos) |
|
68 |
local inv = meta:get_inventory() |
|
69 |
local eu_input = meta:get_int(tier.."_EU_input") |
|
70 |
|
|
71 |
local machine_desc_tier = machine_desc:format(tier) |
|
72 |
local machine_node = "technic:"..ltier.."_"..machine_name |
|
73 |
local machine_demand = data.demand |
|
74 |
|
|
75 |
-- Setup meta data if it does not exist. |
|
76 |
if not eu_input then |
|
77 |
meta:set_int(tier.."_EU_demand", machine_demand[1]) |
|
78 |
meta:set_int(tier.."_EU_input", 0) |
|
79 |
return |
|
80 |
end |
|
81 |
|
|
82 |
local EU_upgrade, tube_upgrade = 0, 0 |
|
83 |
if data.upgrade then |
|
84 |
EU_upgrade, tube_upgrade = technic.handle_machine_upgrades(meta) |
|
85 |
end |
|
86 |
if data.tube then |
|
87 |
technic.handle_machine_pipeworks(pos, tube_upgrade) |
|
88 |
end |
|
89 |
|
814646
|
90 |
local powered = eu_input >= machine_demand[EU_upgrade+1] |
Z |
91 |
if powered then |
|
92 |
meta:set_int("src_time", meta:get_int("src_time") + round(data.speed*10)) |
563a4c
|
93 |
end |
814646
|
94 |
while true do |
Z |
95 |
local result = technic.get_recipe(typename, inv:get_list("src")) |
|
96 |
if not result then |
|
97 |
technic.swap_node(pos, machine_node) |
|
98 |
meta:set_string("infotext", S("%s Idle"):format(machine_desc_tier)) |
|
99 |
meta:set_int(tier.."_EU_demand", 0) |
|
100 |
meta:set_int("src_time", 0) |
|
101 |
return |
|
102 |
end |
|
103 |
meta:set_int(tier.."_EU_demand", machine_demand[EU_upgrade+1]) |
563a4c
|
104 |
technic.swap_node(pos, machine_node.."_active") |
N |
105 |
meta:set_string("infotext", S("%s Active"):format(machine_desc_tier)) |
814646
|
106 |
if meta:get_int("src_time") < round(result.time*10) then |
Z |
107 |
if not powered then |
|
108 |
technic.swap_node(pos, machine_node) |
|
109 |
meta:set_string("infotext", S("%s Unpowered"):format(machine_desc_tier)) |
dd65a6
|
110 |
end |
814646
|
111 |
return |
563a4c
|
112 |
end |
814646
|
113 |
local output = result.output |
Z |
114 |
if type(output) ~= "table" then output = { output } end |
|
115 |
local output_stacks = {} |
|
116 |
for _, o in ipairs(output) do |
|
117 |
table.insert(output_stacks, ItemStack(o)) |
|
118 |
end |
|
119 |
local room_for_output = true |
|
120 |
inv:set_size("dst_tmp", inv:get_size("dst")) |
|
121 |
inv:set_list("dst_tmp", inv:get_list("dst")) |
|
122 |
for _, o in ipairs(output_stacks) do |
|
123 |
if not inv:room_for_item("dst_tmp", o) then |
|
124 |
room_for_output = false |
|
125 |
break |
|
126 |
end |
|
127 |
inv:add_item("dst_tmp", o) |
|
128 |
end |
|
129 |
if not room_for_output then |
a529ba
|
130 |
technic.swap_node(pos, machine_node) |
T |
131 |
meta:set_string("infotext", S("%s Idle"):format(machine_desc_tier)) |
|
132 |
meta:set_int(tier.."_EU_demand", 0) |
814646
|
133 |
meta:set_int("src_time", round(result.time*10)) |
Z |
134 |
return |
|
135 |
end |
|
136 |
meta:set_int("src_time", meta:get_int("src_time") - round(result.time*10)) |
|
137 |
inv:set_list("src", result.new_input) |
|
138 |
inv:set_list("dst", inv:get_list("dst_tmp")) |
563a4c
|
139 |
end |
N |
140 |
end |
5d05f5
|
141 |
|
aa8af0
|
142 |
minetest.register_node("technic:"..ltier.."_"..machine_name, { |
N |
143 |
description = machine_desc:format(tier), |
|
144 |
tiles = {"technic_"..ltier.."_"..machine_name.."_top.png", |
5d05f5
|
145 |
"technic_"..ltier.."_"..machine_name.."_bottom.png", |
VE |
146 |
"technic_"..ltier.."_"..machine_name.."_side.png", |
|
147 |
"technic_"..ltier.."_"..machine_name.."_side.png", |
|
148 |
"technic_"..ltier.."_"..machine_name.."_side.png", |
|
149 |
"technic_"..ltier.."_"..machine_name.."_front.png" |
|
150 |
}, |
aa8af0
|
151 |
paramtype2 = "facedir", |
N |
152 |
groups = groups, |
|
153 |
tube = data.tube and tube or nil, |
83c649
|
154 |
connect_sides = data.connect_sides or connect_default, |
aa8af0
|
155 |
legacy_facedir_simple = true, |
N |
156 |
sounds = default.node_sound_wood_defaults(), |
|
157 |
on_construct = function(pos) |
|
158 |
local node = minetest.get_node(pos) |
|
159 |
local meta = minetest.get_meta(pos) |
5d05f5
|
160 |
|
VE |
161 |
local form_buttons = "" |
|
162 |
if not string.find(node.name, ":lv_") then |
|
163 |
form_buttons = fs_helpers.cycling_button( |
|
164 |
meta, |
|
165 |
"image_button[0,4.3;1,0.6", |
|
166 |
"splitstacks", |
|
167 |
{ |
|
168 |
{text="", texture="pipeworks_button_off.png", addopts="false;false;pipeworks_button_interm.png"}, |
|
169 |
{text="", texture="pipeworks_button_on.png", addopts="false;false;pipeworks_button_interm.png"} |
|
170 |
} |
|
171 |
).."label[0.9,4.31;Allow splitting incoming stacks from tubes]" |
|
172 |
end |
|
173 |
|
aa8af0
|
174 |
meta:set_string("infotext", machine_desc:format(tier)) |
N |
175 |
meta:set_int("tube_time", 0) |
5d05f5
|
176 |
meta:set_string("formspec", formspec..form_buttons) |
aa8af0
|
177 |
local inv = meta:get_inventory() |
dd65a6
|
178 |
inv:set_size("src", input_size) |
aa8af0
|
179 |
inv:set_size("dst", 4) |
N |
180 |
inv:set_size("upgrade1", 1) |
|
181 |
inv:set_size("upgrade2", 1) |
|
182 |
end, |
|
183 |
can_dig = technic.machine_can_dig, |
|
184 |
allow_metadata_inventory_put = technic.machine_inventory_put, |
|
185 |
allow_metadata_inventory_take = technic.machine_inventory_take, |
|
186 |
allow_metadata_inventory_move = technic.machine_inventory_move, |
563a4c
|
187 |
technic_run = run, |
011397
|
188 |
after_place_node = data.tube and pipeworks.after_place, |
5d05f5
|
189 |
after_dig_node = technic.machine_after_dig_node, |
VE |
190 |
on_receive_fields = function(pos, formname, fields, sender) |
|
191 |
local node = minetest.get_node(pos) |
|
192 |
if not pipeworks.may_configure(pos, sender) then return end |
|
193 |
fs_helpers.on_receive_fields(pos, fields) |
|
194 |
local meta = minetest.get_meta(pos) |
|
195 |
local form_buttons = "" |
|
196 |
if not string.find(node.name, ":lv_") then |
|
197 |
form_buttons = fs_helpers.cycling_button( |
|
198 |
meta, |
|
199 |
"image_button[0,4.3;1,0.6", |
|
200 |
"splitstacks", |
|
201 |
{ |
|
202 |
{text="", texture="pipeworks_button_off.png", addopts="false;false;pipeworks_button_interm.png"}, |
|
203 |
{text="", texture="pipeworks_button_on.png", addopts="false;false;pipeworks_button_interm.png"} |
|
204 |
} |
|
205 |
).."label[0.9,4.31;Allow splitting incoming stacks from tubes]" |
|
206 |
end |
|
207 |
meta:set_string("formspec", formspec..form_buttons) |
|
208 |
end, |
aa8af0
|
209 |
}) |
N |
210 |
|
|
211 |
minetest.register_node("technic:"..ltier.."_"..machine_name.."_active",{ |
|
212 |
description = machine_desc:format(tier), |
|
213 |
tiles = {"technic_"..ltier.."_"..machine_name.."_top.png", |
5d05f5
|
214 |
"technic_"..ltier.."_"..machine_name.."_bottom.png", |
VE |
215 |
"technic_"..ltier.."_"..machine_name.."_side.png", |
|
216 |
"technic_"..ltier.."_"..machine_name.."_side.png", |
|
217 |
"technic_"..ltier.."_"..machine_name.."_side.png", |
|
218 |
"technic_"..ltier.."_"..machine_name.."_front_active.png" |
|
219 |
}, |
aa8af0
|
220 |
paramtype2 = "facedir", |
N |
221 |
drop = "technic:"..ltier.."_"..machine_name, |
|
222 |
groups = active_groups, |
83c649
|
223 |
connect_sides = data.connect_sides or connect_default, |
aa8af0
|
224 |
legacy_facedir_simple = true, |
N |
225 |
sounds = default.node_sound_wood_defaults(), |
|
226 |
tube = data.tube and tube or nil, |
|
227 |
can_dig = technic.machine_can_dig, |
|
228 |
allow_metadata_inventory_put = technic.machine_inventory_put, |
|
229 |
allow_metadata_inventory_take = technic.machine_inventory_take, |
|
230 |
allow_metadata_inventory_move = technic.machine_inventory_move, |
563a4c
|
231 |
technic_run = run, |
N |
232 |
technic_disabled_machine_name = "technic:"..ltier.."_"..machine_name, |
5d05f5
|
233 |
on_receive_fields = function(pos, formname, fields, sender) |
VE |
234 |
local node = minetest.get_node(pos) |
|
235 |
if not pipeworks.may_configure(pos, sender) then return end |
|
236 |
fs_helpers.on_receive_fields(pos, fields) |
|
237 |
local meta = minetest.get_meta(pos) |
|
238 |
local form_buttons = "" |
|
239 |
if not string.find(node.name, ":lv_") then |
|
240 |
form_buttons = fs_helpers.cycling_button( |
|
241 |
meta, |
|
242 |
"image_button[0,4.3;1,0.6", |
|
243 |
"splitstacks", |
|
244 |
{ |
|
245 |
{text="", texture="pipeworks_button_off.png", addopts="false;false;pipeworks_button_interm.png"}, |
|
246 |
{text="", texture="pipeworks_button_on.png", addopts="false;false;pipeworks_button_interm.png"} |
|
247 |
} |
|
248 |
).."label[0.9,4.31;Allow splitting incoming stacks from tubes]" |
|
249 |
end |
|
250 |
meta:set_string("formspec", formspec..form_buttons) |
|
251 |
end, |
aa8af0
|
252 |
}) |
N |
253 |
|
|
254 |
technic.register_machine(tier, "technic:"..ltier.."_"..machine_name, technic.receiver) |
|
255 |
technic.register_machine(tier, "technic:"..ltier.."_"..machine_name.."_active", technic.receiver) |
|
256 |
|
|
257 |
end -- End registration |
|
258 |
|