Maciej Kasatkin
2012-09-11 ed818fe0ac735fb11e0d1bc27980271a7add32fa
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)
7c04fb 27 register_alloy_recipe ("default:sand",2, "technic:coal_dust",2, "technic:silicon_wafer",1)
MK 28 register_alloy_recipe ("technic:silicon_wafer",1, "technic:mithril_dust",3, "technic:doped_silicon_wafer",1)
1f1562 29
MK 30 minetest.register_alias("alloy_furnace", "technic:alloy_furnace")
31
32
33 minetest.register_craft({
34     output = 'technic:alloy_furnace',
35     recipe = {
36         {'default:stone', 'default:stone', 'default:stone'},
37         {'default:stone', '', 'default:stone'},
38         {'moreores:gold_ingot', 'moreores:copper_ingot', 'moreores:gold_ingot'},
39     }
40 })
41
42
43 alloy_furnace_formspec =
44     "invsize[8,9;]"..
45     "image[1,1;1,2;technic_power_meter_bg.png]"..
46     "list[current_name;src;3,1;1,1;]"..
47     "list[current_name;src2;3,2;1,1;]"..
48     "list[current_name;dst;5,1;2,2;]"..
49     "list[current_player;main;0,5;8,4;]"..
50     "label[0,0;Alloy Furnace]"..
51     "label[1,3;Power level]"
52     
53 minetest.register_node("technic:alloy_furnace", {
54     description = "Electric alloy furnace",
55     tiles = {"technic_alloy_furnace_top.png", "technic_machine_bottom.png", "technic_alloy_furnace_side.png",
56         "technic_alloy_furnace_side.png", "technic_alloy_furnace_side.png", "technic_alloy_furnace_front.png"},
57     paramtype2 = "facedir",
58     groups = {cracky=2},
59     legacy_facedir_simple = true,
60     sounds = default.node_sound_stone_defaults(),
61     technic_power_machine=1,
62     internal_EU_buffer=0;
63     interal_EU_buffer_size=2000;
64     on_construct = function(pos)
65         local meta = minetest.env:get_meta(pos)
66         meta:set_float("technic_power_machine", 1)
67         meta:set_string("formspec", alloy_furnace_formspec)
68         meta:set_string("infotext", "Alloy furnace")
69         local inv = meta:get_inventory()
70         inv:set_size("src", 1)
71         inv:set_size("src2", 1)
72         inv:set_size("dst", 4)
73         local EU_used  = 0
74         local furnace_is_cookin = 0
75         local cooked = nil
76         meta:set_float("internal_EU_buffer",0)
77         meta:set_float("internal_EU_buffer_size",2000)
78
79     end,
80     can_dig = function(pos,player)
81         local meta = minetest.env:get_meta(pos);
82         local inv = meta:get_inventory()
83         if not inv:is_empty("dst") then
84             return false end
85         if not inv:is_empty("src") then
86             return false end
87         if not inv:is_empty("src2") then
88             return false end
89         return true
90     end,
91 })
92
93 minetest.register_node("technic:alloy_furnace_active", {
94     description = "Alloy Furnace",
95     tiles = {"technic_alloy_furnace_top.png", "technic_machine_bottom.png", "technic_alloy_furnace_side.png",
96         "technic_alloy_furnace_side.png", "technic_alloy_furnace_side.png", "technic_alloy_furnace_front_active.png"},
97     paramtype2 = "facedir",
98     light_source = 8,
99     drop = "technic:alloy_furnace",
100     groups = {cracky=2, not_in_creative_inventory=1},
101     legacy_facedir_simple = true,
102     sounds = default.node_sound_stone_defaults(),
103     internal_EU_buffer=0;
104     interal_EU_buffer_size=2000;
105     technic_power_machine=1,
106     on_construct = function(pos)
107         local meta = minetest.env:get_meta(pos)
108         meta:set_float("technic_power_machine", 1)
109         meta:set_string("formspec", alloy_furnace_formspec)
110         meta:set_string("infotext", "Alloy furnace");
111         local inv = meta:get_inventory()
112         inv:set_size("src", 1)
113         inv:set_size("dst", 4)
114         local EU_used  = 0
115         local furnace_is_cookin = 0
116         local cooked = nil
117     end,
118     can_dig = function(pos,player)
119         local meta = minetest.env:get_meta(pos);
120         local inv = meta:get_inventory()
121         if not inv:is_empty("dst") then
122             return false
123         elseif not inv:is_empty("src") then
124             return false
125         end
126         return true
127     end,
128 })
129
130 minetest.register_abm({
131     nodenames = {"technic:alloy_furnace","technic:alloy_furnace_active"},
132     interval = 1,
133     chance = 1,
134     
135     action = function(pos, node, active_object_count, active_object_count_wider)
136
137         local meta = minetest.env:get_meta(pos)
138         internal_EU_buffer=meta:get_float("internal_EU_buffer")
139         internal_EU_buffer_size=meta:get_float("internal_EU_buffer")
140         local load = math.floor(internal_EU_buffer/2000 * 100)
141         meta:set_string("formspec",
142                 "invsize[8,9;]"..
143                 "image[1,1;1,2;technic_power_meter_bg.png^[lowpart:"..
144                         (load)..":technic_power_meter_fg.png]"..
145                 "list[current_name;src;3,1;1,1;]"..
146                 "list[current_name;src2;3,2;1,1;]"..
147                 "list[current_name;dst;5,1;2,2;]"..
148                 "list[current_player;main;0,5;8,4;]"..
149                 "label[0,0;Alloy Furnace]"..
150                 "label[1,3;Power level]")
151
152         local inv = meta:get_inventory()
153         
154         local furnace_is_cookin = meta:get_int("furnace_is_cookin")
155         
156         
157         local srclist = inv:get_list("src")
158         local srclist2 = inv:get_list("src2")
159         
160         srcstack = inv:get_stack("src", 1)
161         if srcstack then src_item1=srcstack:to_table() end
162         srcstack = inv:get_stack("src2", 1)
163         if srcstack then src_item2=srcstack:to_table() end
164         dst_index=nil
165
166         if src_item1 and src_item2 then 
167                 dst_index=get_cook_result(src_item1,src_item2) 
168                 end
169         
170         
171         if (furnace_is_cookin == 1) then
172             if internal_EU_buffer>=150 then
173             internal_EU_buffer=internal_EU_buffer-150;
174             meta:set_float("internal_EU_buffer",internal_EU_buffer)
175             meta:set_float("src_time", meta:get_float("src_time") + 1)
176             if dst_index and meta:get_float("src_time") >= 4 then
177                 -- check if there's room for output in "dst" list
178                 dst_stack={}
179                 dst_stack["name"]=alloy_recipes[dst_index].dst_name
180                 dst_stack["count"]=alloy_recipes[dst_index].dst_count
181                 if inv:room_for_item("dst",dst_stack) then
182                     -- Put result in "dst" list
183                     inv:add_item("dst",dst_stack)
184                     -- take stuff from "src" list
185                     for i=1,alloy_recipes[dst_index].src1_count,1 do
186                         srcstack = inv:get_stack("src", 1)
187                         srcstack:take_item()
188                         inv:set_stack("src", 1, srcstack)
189                         end
190                     for i=1,alloy_recipes[dst_index].src2_count,1 do
191                         srcstack = inv:get_stack("src2", 1)
192                         srcstack:take_item()
193                         inv:set_stack("src2", 1, srcstack)
194                         end
195
196
197                 else
198                     print("Furnace inventory full!")
199                 end
200                 meta:set_string("src_time", 0)
201             end
202             end        
203         end
204         
205         
206
207         
208         if dst_index and meta:get_int("furnace_is_cookin")==0 then
209             hacky_swap_node(pos,"technic:alloy_furnace_active")
210             meta:set_string("infotext","Alloy Furnace active")
211             meta:set_int("furnace_is_cookin",1)
212             meta:set_string("src_time", 0)
213             return
214             end
215
216             
217         if meta:get_int("furnace_is_cookin")==0 or dst_index==nil then
218             hacky_swap_node(pos,"technic:alloy_furnace")
219             meta:set_string("infotext","Alloy Furnace inactive")
220             meta:set_int("furnace_is_cookin",0)
221             meta:set_string("src_time", 0)
222         end
223     
224 end,        
225 })
226
227 function get_cook_result(src_item1, src_item2)
228 local counter=registered_recipes_count-1
229 for i=1, counter,1 do
230 if    alloy_recipes[i].src1_name==src_item1["name"] and
231     alloy_recipes[i].src2_name==src_item2["name"] and
232     alloy_recipes[i].src1_count<=src_item1["count"] and
233     alloy_recipes[i].src2_count<=src_item2["count"] 
234     then return i end
235 end
236 return nil
237 end