RealBadAngel
2013-02-03 6123493fd73a9c70210eb89274b5690caf562823
commit | author | age
5d799e 1 -- MV alloy furnace
R 2
3 minetest.register_craft({
4     output = 'technic:mv_alloy_furnace',
5     recipe = {
6         {'technic:stainless_steel_ingot', 'technic:alloy_furnace', 'technic:stainless_steel_ingot'},
7         {'pipeworks:tube_000000', 'technic:mv_transformer', 'pipeworks:tube_000000'},
8         {'technic:stainless_steel_ingot', 'technic:mv_cable', 'technic:stainless_steel_ingot'},
9     }
10 })
11
12 MV_alloy_furnace_formspec =
13     "invsize[8,10;]"..
14     "label[0,0;MV Alloy Furnace]"..
15     "image[1,1;1,2;technic_power_meter_bg.png]"..
16     "label[1,2.8;Power level]"..
17     "list[current_name;src;3,1;1,2;]"..
18     "list[current_name;dst;5,1;2,2;]"..
19     "list[current_player;main;0,6;8,4;]"..
20     "list[current_name;upgrade1;1,4;1,1;]"..
21     "list[current_name;upgrade2;2,4;1,1;]"..
22     "label[1,5;Upgrade Slots]"
23     
24 minetest.register_node("technic:mv_alloy_furnace", {
25     description = "MV Alloy Furnace",
26     tiles = {"technic_mv_alloy_furnace_top.png", "technic_mv_alloy_furnace_bottom.png", "technic_mv_alloy_furnace_side_tube.png",
27         "technic_mv_alloy_furnace_side_tube.png", "technic_mv_alloy_furnace_side.png", "technic_mv_alloy_furnace_front.png"},
28     paramtype2 = "facedir",
29     groups = {cracky=2, tubedevice=1,tubedevice_receiver=1},
30     tube={insert_object=function(pos,node,stack,direction)
31             local meta=minetest.env:get_meta(pos)
32             local inv=meta:get_inventory()
33                 return inv:add_item("src",stack)
34         end,
35         can_insert=function(pos,node,stack,direction)
36             local meta=minetest.env:get_meta(pos)
37             local inv=meta:get_inventory()
38             return inv:room_for_item("src",stack)
39         end,
40         },
41     legacy_facedir_simple = true,
42     sounds = default.node_sound_stone_defaults(),
43     technic_power_machine=1,
44     internal_EU_buffer=0;
45     interal_EU_buffer_size=2000;
46     on_construct = function(pos)
47         local meta = minetest.env:get_meta(pos)
48         meta:set_float("technic_power_machine", 1)
49         meta:set_string("formspec", mv_alloy_furnace_formspec)
50         meta:set_string("infotext", "MV Electric Alloy furnace")
51         local inv = meta:get_inventory()
52         inv:set_size("src", 2)
53         inv:set_size("dst", 4)
54         inv:set_size("upgrade1", 1)
55         inv:set_size("upgrade2", 1)
56         local EU_used  = 0
57         local furnace_is_cookin = 0
58         local cooked = nil
59         meta:set_float("internal_EU_buffer",0)
60         meta:set_float("internal_EU_buffer_size",2000)
61
62     end,
63     can_dig = function(pos,player)
64         local meta = minetest.env:get_meta(pos);
65         local inv = meta:get_inventory()
66         if not inv:is_empty("dst") then
67             return false end
68         if not inv:is_empty("src") then
69             return false end
70         if not inv:is_empty("upgrade1") then
71             return false end
72         if not inv:is_empty("upgrade2") then
73             return false end
74         return true
75     end,
76 })
77
78 minetest.register_node("technic:mv_alloy_furnace_active", {
79     description = "MV Alloy Furnace",
80     tiles = {"technic_mv_alloy_furnace_top.png", "technic_mv_alloy_furnace_bottom.png", "technic_mv_alloy_furnace_side_tube.png",
81         "technic_mv_alloy_furnace_side_tube.png", "technic_mv_alloy_furnace_side.png", "technic_mv_alloy_furnace_front_active.png"},
82     paramtype2 = "facedir",
83     light_source = 8,
84     drop = "technic:mv_alloy_furnace",
85     groups = {cracky=2, tubedevice=1,tubedevice_receiver=1,not_in_creative_inventory=1},
86     tube={insert_object=function(pos,node,stack,direction)
87             local meta=minetest.env:get_meta(pos)
88             local inv=meta:get_inventory()
89                 return inv:add_item("src",stack)
90         end,
91         can_insert=function(pos,node,stack,direction)
92             local meta=minetest.env:get_meta(pos)
93             local inv=meta:get_inventory()
94             return inv:room_for_item("src",stack)
95         end,
96         },
97     legacy_facedir_simple = true,
98     sounds = default.node_sound_stone_defaults(),
99     internal_EU_buffer=0;
100     interal_EU_buffer_size=2000;
101     technic_power_machine=1,
102     can_dig = function(pos,player)
103         local meta = minetest.env:get_meta(pos);
104         local inv = meta:get_inventory()
105         if not inv:is_empty("dst") then
106             return false end
107         if not inv:is_empty("src") then
108             return false end
109         if not inv:is_empty("upgrade1") then
110             return false end
111         if not inv:is_empty("upgrade2") then
112             return false end
113         return true
114     end,
115 })
116
117 minetest.register_abm({
118     nodenames = {"technic:mv_alloy_furnace","technic:mv_alloy_furnace_active"},
119     interval = 1,
120     chance = 1,
121
122     action = function(pos, node, active_object_count, active_object_count_wider)
123         local pos1={}
124         pos1.x=pos.x
125         pos1.y=pos.y
126         pos1.z=pos.z
127         local x_velocity=0
128         local z_velocity=0
129
130         -- output is on the left side of the furnace
131         if node.param2==3 then pos1.z=pos1.z-1 z_velocity =-1 end
132         if node.param2==2 then pos1.x=pos1.x-1 x_velocity =-1 end
133         if node.param2==1 then pos1.z=pos1.z+1 z_velocity = 1 end
134         if node.param2==0 then pos1.x=pos1.x+1 x_velocity = 1 end
135
136         local output_tube_connected = false
137         local meta=minetest.env:get_meta(pos1) 
138         if meta:get_int("tubelike")==1 then output_tube_connected=true end
139         meta = minetest.env:get_meta(pos)
140         local inv = meta:get_inventory()
141         local upg_item1
142         local upg_item1_name=""
143         local upg_item2
144         local upg_item2_name=""
145         local srcstack = inv:get_stack("upgrade1", 1)
146         if srcstack then upg_item1=srcstack:to_table() end
147         srcstack = inv:get_stack("upgrade2", 1)
148         if srcstack then upg_item2=srcstack:to_table() end
149         if upg_item1 then upg_item1_name=upg_item1.name end
150         if upg_item2 then upg_item2_name=upg_item2.name end
151
152         local speed=0
153         if upg_item1_name=="technic:control_logic_unit" then speed=speed+1 end
154         if upg_item2_name=="technic:control_logic_unit" then speed=speed+1 end
155         tube_time=meta:get_float("tube_time")
156         tube_time=tube_time+speed
157         if tube_time>3 then 
158             tube_time=0
159             if output_tube_connected then send_cooked_alloys(pos,x_velocity,z_velocity) end
160         end
161         meta:set_float("tube_time", tube_time)
162
163         local extra_buffer_size = 0
164         if upg_item1_name=="technic:battery" then extra_buffer_size =extra_buffer_size + 10000 end
165         if upg_item2_name=="technic:battery" then extra_buffer_size =extra_buffer_size + 10000 end
166         local internal_EU_buffer_size=2000+extra_buffer_size
167         meta:set_float("internal_EU_buffer_size",internal_EU_buffer_size)
168
169         internal_EU_buffer=meta:get_float("internal_EU_buffer")
170         if internal_EU_buffer > internal_EU_buffer_size then internal_EU_buffer = internal_EU_buffer_size end
171         local meta = minetest.env:get_meta(pos)
172         local load = math.floor(internal_EU_buffer/internal_EU_buffer_size * 100)
173         meta:set_string("formspec",
174                 MV_alloy_furnace_formspec..
175                 "image[1,1;1,2;technic_power_meter_bg.png^[lowpart:"..
176                         (load)..":technic_power_meter_fg.png]")
177
178         local inv = meta:get_inventory()
179
180         local furnace_is_cookin = meta:get_int("furnace_is_cookin")
181
182         local srclist = inv:get_list("src")
183         local srclist2 = inv:get_list("src2")
184         
185         srcstack = inv:get_stack("src", 1)
186         if srcstack then src_item1=srcstack:to_table() end
187         srcstack = inv:get_stack("src", 2)
188         if srcstack then src_item2=srcstack:to_table() end
189         dst_index=nil
190
191         if src_item1 and src_item2 then 
192                 dst_index=get_cook_result(src_item1,src_item2) 
193                 end
194
195
196         if (furnace_is_cookin == 1) then
197             if internal_EU_buffer>=150 then
198             internal_EU_buffer=internal_EU_buffer-150;
199             meta:set_float("internal_EU_buffer",internal_EU_buffer)
200             meta:set_float("src_time", meta:get_float("src_time") + 1)
201             if dst_index and meta:get_float("src_time") >= 4 then
202                 -- check if there's room for output in "dst" list
203                 dst_stack={}
204                 dst_stack["name"]=alloy_recipes[dst_index].dst_name
205                 dst_stack["count"]=alloy_recipes[dst_index].dst_count
206                 if inv:room_for_item("dst",dst_stack) then
207                     -- Put result in "dst" list
208                     inv:add_item("dst",dst_stack)
209                     -- take stuff from "src" list
210                     for i=1,alloy_recipes[dst_index].src1_count,1 do
211                         srcstack = inv:get_stack("src", 1)
212                         srcstack:take_item()
213                         inv:set_stack("src", 1, srcstack)
214                         end
215                     for i=1,alloy_recipes[dst_index].src2_count,1 do
216                         srcstack = inv:get_stack("src", 2)
217                         srcstack:take_item()
218                         inv:set_stack("src", 2, srcstack)
219                         end
220
221                 else
222                     print("Furnace inventory full!")
223                 end
224                 meta:set_string("src_time", 0)
225             end
226             end
227         end
228
229         if dst_index and meta:get_int("furnace_is_cookin")==0 then
230             hacky_swap_node(pos,"technic:mv_alloy_furnace_active")
231             meta:set_string("infotext","MV Alloy Furnace active")
232             meta:set_int("furnace_is_cookin",1)
233             meta:set_string("src_time", 0)
234             return
235             end
236
237         if meta:get_int("furnace_is_cookin")==0 or dst_index==nil then
238             hacky_swap_node(pos,"technic:mv_alloy_furnace")
239             meta:set_string("infotext","MV Alloy Furnace inactive")
240             meta:set_int("furnace_is_cookin",0)
241             meta:set_string("src_time", 0)
242         end
243
244 end,
245 })
246
247 function send_cooked_alloys (pos,x_velocity,z_velocity)
248         local meta=minetest.env:get_meta(pos) 
249         local inv = meta:get_inventory()
250         local i=0
251         for _,stack in ipairs(inv:get_list("dst")) do
252         i=i+1
253             if stack then
254             local item0=stack:to_table()
255             if item0 then 
256                 item0["count"]="1"
257                 local item1=tube_item({x=pos.x,y=pos.y,z=pos.z},item0)
258                 item1:get_luaentity().start_pos = {x=pos.x,y=pos.y,z=pos.z}
259                 item1:setvelocity({x=x_velocity, y=0, z=z_velocity})
260                 item1:setacceleration({x=0, y=0, z=0})
261                 stack:take_item(1);
262                 inv:set_stack("dst", i, stack)
263                 return
264                 end
265             end
266         end
267 end
612349 268
R 269 register_MV_machine ("technic:mv_alloy_furnace","RE")
270 register_MV_machine ("technic:mv_alloy_furnace_active","RE")