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