commit | author | age
|
5d799e
|
1 |
minetest.register_craft({ |
R |
2 |
output = 'technic:coal_alloy_furnace', |
82cba9
|
3 |
recipe = { |
5d799e
|
4 |
{'default:brick', 'default:brick', 'default:brick'}, |
R |
5 |
{'default:brick', '', 'default:brick'}, |
|
6 |
{'default:brick', 'default:brick', 'default:brick'}, |
|
7 |
} |
|
8 |
}) |
82cba9
|
9 |
|
R |
10 |
minetest.register_craft({ |
|
11 |
output = 'technic:alloy_furnace', |
|
12 |
recipe = { |
|
13 |
{'default:brick', 'default:brick', 'default:brick'}, |
|
14 |
{'default:brick', '', 'default:brick'}, |
|
15 |
{'default:steel_ingot', 'moreores:copper_ingot', 'default:steel_ingot'}, |
|
16 |
} |
|
17 |
}) |
|
18 |
|
5d799e
|
19 |
-- LV alloy furnace |
82cba9
|
20 |
|
R |
21 |
alloy_furnace_formspec = |
|
22 |
"invsize[8,9;]".. |
|
23 |
"image[1,1;1,2;technic_power_meter_bg.png]".. |
|
24 |
"list[current_name;src;3,1;1,1;]".. |
|
25 |
"list[current_name;src2;3,2;1,1;]".. |
|
26 |
"list[current_name;dst;5,1;2,2;]".. |
|
27 |
"list[current_player;main;0,5;8,4;]".. |
|
28 |
"label[0,0;Electric Alloy Furnace]".. |
|
29 |
"label[1,3;Power level]" |
|
30 |
|
|
31 |
minetest.register_node("technic:alloy_furnace", { |
|
32 |
description = "Electric alloy furnace", |
|
33 |
tiles = {"technic_alloy_furnace_top.png", "technic_machine_bottom.png", "technic_alloy_furnace_side.png", |
|
34 |
"technic_alloy_furnace_side.png", "technic_alloy_furnace_side.png", "technic_alloy_furnace_front.png"}, |
|
35 |
paramtype2 = "facedir", |
|
36 |
groups = {cracky=2}, |
|
37 |
legacy_facedir_simple = true, |
|
38 |
sounds = default.node_sound_stone_defaults(), |
|
39 |
technic_power_machine=1, |
|
40 |
internal_EU_buffer=0; |
|
41 |
interal_EU_buffer_size=2000; |
|
42 |
on_construct = function(pos) |
|
43 |
local meta = minetest.env:get_meta(pos) |
|
44 |
meta:set_float("technic_power_machine", 1) |
|
45 |
meta:set_string("formspec", alloy_furnace_formspec) |
|
46 |
meta:set_string("infotext", "Electric Alloy furnace") |
|
47 |
local inv = meta:get_inventory() |
|
48 |
inv:set_size("src", 1) |
|
49 |
inv:set_size("src2", 1) |
|
50 |
inv:set_size("dst", 4) |
|
51 |
local EU_used = 0 |
|
52 |
local furnace_is_cookin = 0 |
|
53 |
local cooked = nil |
|
54 |
meta:set_float("internal_EU_buffer",0) |
|
55 |
meta:set_float("internal_EU_buffer_size",2000) |
5d799e
|
56 |
meta:set_float("tube_time", 0) |
82cba9
|
57 |
end, |
5d799e
|
58 |
|
82cba9
|
59 |
can_dig = function(pos,player) |
R |
60 |
local meta = minetest.env:get_meta(pos); |
|
61 |
local inv = meta:get_inventory() |
|
62 |
if not inv:is_empty("dst") then |
|
63 |
return false end |
|
64 |
if not inv:is_empty("src") then |
|
65 |
return false end |
|
66 |
if not inv:is_empty("src2") then |
|
67 |
return false end |
|
68 |
return true |
|
69 |
end, |
|
70 |
}) |
|
71 |
|
|
72 |
minetest.register_node("technic:alloy_furnace_active", { |
|
73 |
description = "Alloy Furnace", |
|
74 |
tiles = {"technic_alloy_furnace_top.png", "technic_machine_bottom.png", "technic_alloy_furnace_side.png", |
|
75 |
"technic_alloy_furnace_side.png", "technic_alloy_furnace_side.png", "technic_alloy_furnace_front_active.png"}, |
|
76 |
paramtype2 = "facedir", |
|
77 |
light_source = 8, |
|
78 |
drop = "technic:alloy_furnace", |
5d799e
|
79 |
groups = {cracky=2,not_in_creative_inventory=1}, |
82cba9
|
80 |
legacy_facedir_simple = true, |
R |
81 |
sounds = default.node_sound_stone_defaults(), |
|
82 |
internal_EU_buffer=0; |
|
83 |
interal_EU_buffer_size=2000; |
|
84 |
technic_power_machine=1, |
|
85 |
can_dig = function(pos,player) |
|
86 |
local meta = minetest.env:get_meta(pos); |
|
87 |
local inv = meta:get_inventory() |
|
88 |
if not inv:is_empty("dst") then |
|
89 |
return false |
|
90 |
elseif not inv:is_empty("src") then |
|
91 |
return false |
|
92 |
end |
|
93 |
return true |
|
94 |
end, |
|
95 |
}) |
|
96 |
|
|
97 |
minetest.register_abm({ |
|
98 |
nodenames = {"technic:alloy_furnace","technic:alloy_furnace_active"}, |
|
99 |
interval = 1, |
|
100 |
chance = 1, |
|
101 |
|
|
102 |
action = function(pos, node, active_object_count, active_object_count_wider) |
|
103 |
|
|
104 |
local meta = minetest.env:get_meta(pos) |
|
105 |
internal_EU_buffer=meta:get_float("internal_EU_buffer") |
|
106 |
internal_EU_buffer_size=meta:get_float("internal_EU_buffer") |
|
107 |
local load = math.floor(internal_EU_buffer/2000 * 100) |
|
108 |
meta:set_string("formspec", |
|
109 |
"invsize[8,9;]".. |
|
110 |
"image[1,1;1,2;technic_power_meter_bg.png^[lowpart:".. |
|
111 |
(load)..":technic_power_meter_fg.png]".. |
|
112 |
"list[current_name;src;3,1;1,1;]".. |
|
113 |
"list[current_name;src2;3,2;1,1;]".. |
|
114 |
"list[current_name;dst;5,1;2,2;]".. |
|
115 |
"list[current_player;main;0,5;8,4;]".. |
|
116 |
"label[0,0;Electric Alloy Furnace]".. |
|
117 |
"label[1,3;Power level]") |
|
118 |
|
|
119 |
local inv = meta:get_inventory() |
5d799e
|
120 |
|
82cba9
|
121 |
local furnace_is_cookin = meta:get_int("furnace_is_cookin") |
5d799e
|
122 |
|
82cba9
|
123 |
local srclist = inv:get_list("src") |
R |
124 |
local srclist2 = inv:get_list("src2") |
5d799e
|
125 |
|
82cba9
|
126 |
srcstack = inv:get_stack("src", 1) |
R |
127 |
if srcstack then src_item1=srcstack:to_table() end |
|
128 |
srcstack = inv:get_stack("src2", 1) |
|
129 |
if srcstack then src_item2=srcstack:to_table() end |
|
130 |
dst_index=nil |
|
131 |
|
|
132 |
if src_item1 and src_item2 then |
|
133 |
dst_index=get_cook_result(src_item1,src_item2) |
|
134 |
end |
5d799e
|
135 |
|
R |
136 |
|
82cba9
|
137 |
if (furnace_is_cookin == 1) then |
R |
138 |
if internal_EU_buffer>=150 then |
|
139 |
internal_EU_buffer=internal_EU_buffer-150; |
|
140 |
meta:set_float("internal_EU_buffer",internal_EU_buffer) |
|
141 |
meta:set_float("src_time", meta:get_float("src_time") + 1) |
|
142 |
if dst_index and meta:get_float("src_time") >= 4 then |
|
143 |
-- check if there's room for output in "dst" list |
|
144 |
dst_stack={} |
|
145 |
dst_stack["name"]=alloy_recipes[dst_index].dst_name |
|
146 |
dst_stack["count"]=alloy_recipes[dst_index].dst_count |
|
147 |
if inv:room_for_item("dst",dst_stack) then |
|
148 |
-- Put result in "dst" list |
|
149 |
inv:add_item("dst",dst_stack) |
|
150 |
-- take stuff from "src" list |
|
151 |
for i=1,alloy_recipes[dst_index].src1_count,1 do |
|
152 |
srcstack = inv:get_stack("src", 1) |
|
153 |
srcstack:take_item() |
|
154 |
inv:set_stack("src", 1, srcstack) |
|
155 |
end |
|
156 |
for i=1,alloy_recipes[dst_index].src2_count,1 do |
|
157 |
srcstack = inv:get_stack("src2", 1) |
|
158 |
srcstack:take_item() |
|
159 |
inv:set_stack("src2", 1, srcstack) |
|
160 |
end |
|
161 |
|
|
162 |
|
|
163 |
else |
|
164 |
print("Furnace inventory full!") |
|
165 |
end |
|
166 |
meta:set_string("src_time", 0) |
|
167 |
end |
5d799e
|
168 |
end |
82cba9
|
169 |
end |
R |
170 |
|
|
171 |
if dst_index and meta:get_int("furnace_is_cookin")==0 then |
|
172 |
hacky_swap_node(pos,"technic:alloy_furnace_active") |
|
173 |
meta:set_string("infotext","Electric Alloy Furnace active") |
|
174 |
meta:set_int("furnace_is_cookin",1) |
|
175 |
meta:set_string("src_time", 0) |
|
176 |
return |
|
177 |
end |
|
178 |
|
|
179 |
if meta:get_int("furnace_is_cookin")==0 or dst_index==nil then |
|
180 |
hacky_swap_node(pos,"technic:alloy_furnace") |
|
181 |
meta:set_string("infotext","Electric Alloy Furnace inactive") |
|
182 |
meta:set_int("furnace_is_cookin",0) |
|
183 |
meta:set_string("src_time", 0) |
|
184 |
end |
|
185 |
|
|
186 |
end, |
|
187 |
}) |
|
188 |
|
|
189 |
function get_cook_result(src_item1, src_item2) |
|
190 |
local counter=registered_recipes_count-1 |
|
191 |
for i=1, counter,1 do |
|
192 |
if alloy_recipes[i].src1_name==src_item1["name"] and |
|
193 |
alloy_recipes[i].src2_name==src_item2["name"] and |
|
194 |
alloy_recipes[i].src1_count<=src_item1["count"] and |
|
195 |
alloy_recipes[i].src2_count<=src_item2["count"] |
|
196 |
then return i end |
|
197 |
end |
|
198 |
return nil |
|
199 |
end |
|
200 |
|
612349
|
201 |
register_LV_machine ("technic:alloy_furnace","RE") |
R |
202 |
register_LV_machine ("technic:alloy_furnace_active","RE") |
|
203 |
|
82cba9
|
204 |
--coal driven alloy furnace: |
R |
205 |
|
|
206 |
coal_alloy_furnace_formspec = |
|
207 |
"size[8,9]".. |
|
208 |
"label[0,0;Alloy Furnace]".. |
|
209 |
"image[2,2;1,1;default_furnace_fire_bg.png]".. |
|
210 |
"list[current_name;fuel;2,3;1,1;]".. |
|
211 |
"list[current_name;src;2,1;1,1;]".. |
|
212 |
"list[current_name;src2;3,1;1,1;]".. |
|
213 |
"list[current_name;dst;5,1;2,2;]".. |
|
214 |
"list[current_player;main;0,5;8,4;]" |
|
215 |
|
|
216 |
minetest.register_node("technic:coal_alloy_furnace", { |
|
217 |
description = "Alloy Furnace", |
|
218 |
tiles = {"technic_coal_alloy_furnace_top.png", "technic_coal_alloy_furnace_bottom.png", "technic_coal_alloy_furnace_side.png", |
|
219 |
"technic_coal_alloy_furnace_side.png", "technic_coal_alloy_furnace_side.png", "technic_coal_alloy_furnace_front.png"}, |
|
220 |
paramtype2 = "facedir", |
|
221 |
groups = {cracky=2}, |
|
222 |
legacy_facedir_simple = true, |
|
223 |
sounds = default.node_sound_stone_defaults(), |
|
224 |
on_construct = function(pos) |
|
225 |
local meta = minetest.env:get_meta(pos) |
|
226 |
meta:set_string("formspec", coal_alloy_furnace_formspec) |
|
227 |
meta:set_string("infotext", "Alloy Furnace") |
|
228 |
local inv = meta:get_inventory() |
|
229 |
inv:set_size("fuel", 1) |
|
230 |
inv:set_size("src", 1) |
|
231 |
inv:set_size("src2", 1) |
|
232 |
inv:set_size("dst", 4) |
|
233 |
local furnace_is_cookin = 0 |
|
234 |
local dst_index = nil |
|
235 |
|
|
236 |
end, |
|
237 |
can_dig = function(pos,player) |
|
238 |
local meta = minetest.env:get_meta(pos); |
|
239 |
local inv = meta:get_inventory() |
|
240 |
if not (inv:is_empty("fuel") or inv:is_empty("dst") or inv:is_empty("src") or inv:is_empty("src2") )then |
|
241 |
return false |
|
242 |
end |
|
243 |
return true |
|
244 |
end, |
|
245 |
}) |
|
246 |
|
|
247 |
minetest.register_node("technic:coal_alloy_furnace_active", { |
|
248 |
description = "Alloy Furnace", |
|
249 |
tiles = {"technic_coal_alloy_furnace_top.png", "technic_coal_alloy_furnace_bottom.png", "technic_coal_alloy_furnace_side.png", |
|
250 |
"technic_coal_alloy_furnace_side.png", "technic_coal_alloy_furnace_side.png", "technic_coal_alloy_furnace_front_active.png"}, |
|
251 |
paramtype2 = "facedir", |
|
252 |
light_source = 8, |
|
253 |
drop = "technic:coal_alloy_furnace", |
|
254 |
groups = {cracky=2, not_in_creative_inventory=1}, |
|
255 |
legacy_facedir_simple = true, |
|
256 |
sounds = default.node_sound_stone_defaults(), |
|
257 |
can_dig = function(pos,player) |
|
258 |
local meta = minetest.env:get_meta(pos); |
|
259 |
local inv = meta:get_inventory() |
|
260 |
if not (inv:is_empty("fuel") or inv:is_empty("dst") or inv:is_empty("src") or inv:is_empty("src2") )then |
|
261 |
return false |
|
262 |
end |
|
263 |
return true |
|
264 |
end, |
|
265 |
}) |
|
266 |
|
|
267 |
minetest.register_abm({ |
|
268 |
nodenames = {"technic:coal_alloy_furnace","technic:coal_alloy_furnace_active"}, |
|
269 |
interval = 1, |
|
270 |
chance = 1, |
|
271 |
|
|
272 |
action = function(pos, node, active_object_count, active_object_count_wider) |
|
273 |
local meta = minetest.env:get_meta(pos) |
|
274 |
for i, name in ipairs({ |
|
275 |
"fuel_totaltime", |
|
276 |
"fuel_time", |
|
277 |
"src_totaltime", |
|
278 |
"src_time" |
|
279 |
}) do |
|
280 |
if meta:get_string(name) == "" then |
|
281 |
meta:set_float(name, 0.0) |
|
282 |
end |
|
283 |
end |
|
284 |
|
|
285 |
local inv = meta:get_inventory() |
|
286 |
|
|
287 |
srcstack = inv:get_stack("src", 1) |
|
288 |
if srcstack then src_item1=srcstack:to_table() end |
|
289 |
srcstack = inv:get_stack("src2", 1) |
|
290 |
if srcstack then src_item2=srcstack:to_table() end |
|
291 |
dst_index=nil |
|
292 |
|
|
293 |
if src_item1 and src_item2 then |
|
294 |
dst_index=get_cook_result(src_item1,src_item2) |
|
295 |
end |
|
296 |
|
|
297 |
local was_active = false |
|
298 |
|
|
299 |
if meta:get_float("fuel_time") < meta:get_float("fuel_totaltime") then |
|
300 |
was_active = true |
|
301 |
meta:set_float("fuel_time", meta:get_float("fuel_time") + 1) |
|
302 |
meta:set_float("src_time", meta:get_float("src_time") + 1) |
|
303 |
if dst_index and meta:get_float("src_time") >= 5 then |
|
304 |
-- check if there's room for output in "dst" list |
|
305 |
dst_stack={} |
|
306 |
dst_stack["name"]=alloy_recipes[dst_index].dst_name |
|
307 |
dst_stack["count"]=alloy_recipes[dst_index].dst_count |
|
308 |
if inv:room_for_item("dst",dst_stack) then |
|
309 |
-- Put result in "dst" list |
|
310 |
inv:add_item("dst", dst_stack) |
|
311 |
-- take stuff from "src" list |
|
312 |
for i=1,alloy_recipes[dst_index].src1_count,1 do |
|
313 |
srcstack = inv:get_stack("src", 1) |
|
314 |
srcstack:take_item() |
|
315 |
inv:set_stack("src", 1, srcstack) |
|
316 |
end |
|
317 |
for i=1,alloy_recipes[dst_index].src2_count,1 do |
|
318 |
srcstack = inv:get_stack("src2", 1) |
|
319 |
srcstack:take_item() |
|
320 |
inv:set_stack("src2", 1, srcstack) |
|
321 |
end |
|
322 |
else |
|
323 |
print("Furnace inventory full!") |
|
324 |
end |
|
325 |
meta:set_string("src_time", 0) |
|
326 |
end |
|
327 |
end |
|
328 |
|
|
329 |
if meta:get_float("fuel_time") < meta:get_float("fuel_totaltime") then |
|
330 |
local percent = math.floor(meta:get_float("fuel_time") / |
|
331 |
meta:get_float("fuel_totaltime") * 100) |
|
332 |
meta:set_string("infotext","Furnace active: "..percent.."%") |
|
333 |
hacky_swap_node(pos,"technic:coal_alloy_furnace_active") |
|
334 |
meta:set_string("formspec", |
|
335 |
"size[8,9]".. |
|
336 |
"label[0,0;Electric Alloy Furnace]".. |
|
337 |
"image[2,2;1,1;default_furnace_fire_bg.png^[lowpart:".. |
|
338 |
(100-percent)..":default_furnace_fire_fg.png]".. |
|
339 |
"list[current_name;fuel;2,3;1,1;]".. |
|
340 |
"list[current_name;src;2,1;1,1;]".. |
|
341 |
"list[current_name;src2;3,1;1,1;]".. |
|
342 |
"list[current_name;dst;5,1;2,2;]".. |
|
343 |
"list[current_player;main;0,5;8,4;]") |
|
344 |
return |
|
345 |
end |
|
346 |
|
|
347 |
local fuel = nil |
|
348 |
local fuellist = inv:get_list("fuel") |
|
349 |
|
|
350 |
srcstack = inv:get_stack("src", 1) |
|
351 |
if srcstack then src_item1=srcstack:to_table() end |
|
352 |
srcstack = inv:get_stack("src2", 1) |
|
353 |
if srcstack then src_item2=srcstack:to_table() end |
|
354 |
dst_index=nil |
|
355 |
|
|
356 |
if src_item1 and src_item2 then |
|
357 |
dst_index=get_cook_result(src_item1,src_item2) |
|
358 |
end |
|
359 |
|
|
360 |
|
|
361 |
if fuellist then |
|
362 |
fuel = minetest.get_craft_result({method = "fuel", width = 1, items = fuellist}) |
|
363 |
end |
|
364 |
|
|
365 |
if fuel.time <= 0 then |
|
366 |
meta:set_string("infotext","Furnace out of fuel") |
|
367 |
hacky_swap_node(pos,"technic:coal_alloy_furnace") |
|
368 |
meta:set_string("formspec", coal_alloy_furnace_formspec) |
|
369 |
return |
|
370 |
end |
|
371 |
|
|
372 |
if dst_index==nil then |
|
373 |
if was_active then |
|
374 |
meta:set_string("infotext","Furnace is empty") |
|
375 |
hacky_swap_node(pos,"technic:coal_alloy_furnace") |
|
376 |
meta:set_string("formspec", coal_alloy_furnace_formspec) |
|
377 |
end |
|
378 |
return |
|
379 |
end |
|
380 |
|
|
381 |
meta:set_string("fuel_totaltime", fuel.time) |
|
382 |
meta:set_string("fuel_time", 0) |
|
383 |
|
|
384 |
local stack = inv:get_stack("fuel", 1) |
|
385 |
stack:take_item() |
|
386 |
inv:set_stack("fuel", 1, stack) |
|
387 |
|
|
388 |
end, |
|
389 |
}) |