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