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