Added fully functional MV electric furnace
authorRealBadAngel <mk@realbadangel.pl>
Sun, 3 Feb 2013 01:17:22 +0000 (02:17 +0100)
committerRealBadAngel <mk@realbadangel.pl>
Sun, 3 Feb 2013 01:17:22 +0000 (02:17 +0100)
technic/deployer.lua
technic/electric_furnace.lua
technic/electric_furnace_mv.lua

index 9fbef07e0079731975e8d6984dfe09d2d788399e..c5dba2a4778ac718bd7168eefbfd4c213b579733 100644 (file)
@@ -34,8 +34,8 @@ deployer_signal_on = function(pos, node)
                                stack:take_item(1);
                                inv:set_stack("main", i, stack)
                                return
+                               end
                        end
-               end
        end
        end
 end
index 135880227608b7f1fd50df8d49128150f2c65a96..22e053bdc14c36b94ee998535e03145b7dd1b273 100644 (file)
@@ -1,5 +1,3 @@
-minetest.register_alias("electric_furnace", "technic:electric_furnace")
-
 minetest.register_craft({
        output = 'technic:electric_furnace',
        recipe = {
@@ -103,8 +101,8 @@ minetest.register_abm({
 
                local meta = minetest.env:get_meta(pos)
                internal_EU_buffer=meta:get_float("internal_EU_buffer")
-               internal_EU_buffer_size=meta:get_float("internal_EU_buffer")
-               local load = math.floor(internal_EU_buffer/2000 * 100)
+               internal_EU_buffer_size=meta:get_float("internal_EU_buffer_size")
+               local load = math.floor(internal_EU_buffer/internal_EU_buffer_size * 100)
                meta:set_string("formspec",
                                "invsize[8,9;]"..
                                "image[1,1;1,2;technic_power_meter_bg.png^[lowpart:"..
@@ -159,7 +157,6 @@ minetest.register_abm({
                        hacky_swap_node(pos,"technic:electric_furnace_active")
                        meta:set_string("infotext","Furnace active")
                        meta:set_string("furnace_is_cookin",1)
-               --      meta:set_string("formspec", electric_furnace_formspec)
                        meta:set_string("src_time", 0)
                        return
                        end
@@ -169,7 +166,6 @@ minetest.register_abm({
                                hacky_swap_node(pos,"technic:electric_furnace")
                                meta:set_string("infotext","Furnace inactive")
                                meta:set_string("furnace_is_cookin",0)
-               --              meta:set_string("formspec", electric_furnace_formspec)
                                meta:set_string("src_time", 0)
                
        
index 5ee63fbc48d826b08bf307201c63130deec61c23..c3e7eff8532c154cb7541bb450b70289a5f25afe 100644 (file)
@@ -9,18 +9,21 @@ minetest.register_craft({
 
 
 mv_electric_furnace_formspec =
-       "invsize[8,9;]"..
+       "invsize[8,10;]"..
        "image[1,1;1,2;technic_power_meter_bg.png]"..
        "list[current_name;src;3,1;1,1;]"..
        "list[current_name;dst;5,1;2,2;]"..
-       "list[current_player;main;0,5;8,4;]"..
+       "list[current_player;main;0,6;8,4;]"..
        "label[0,0;MV Electric Furnace]"..
-       "label[1,3;Power level]"
-       
+       "label[1,2.8;Power level]"..
+       "list[current_name;upgrade1;1,4;1,1;]"..
+       "list[current_name;upgrade2;2,4;1,1;]"..
+       "label[1,5;Upgrade Slots]"
+
 minetest.register_node("technic:mv_electric_furnace", {
        description = "MV Electric furnace",
-       tiles = {"technic_mv_electric_furnace_top.png", "technic_mv_electric_furnace_bottom.png", "technic_mv_electric_furnace_side.png",
-               "technic_mv_electric_furnace_side_tube.png", "technic_mv_electric_furnace_side_tube.png", "technic_mv_electric_furnace_front.png"},
+       tiles = {"technic_mv_electric_furnace_top.png", "technic_mv_electric_furnace_bottom.png", "technic_mv_electric_furnace_side_tube.png",
+               "technic_mv_electric_furnace_side_tube.png", "technic_mv_electric_furnace_side.png", "technic_mv_electric_furnace_front.png"},
        paramtype2 = "facedir",
        groups = {cracky=2, tubedevice=1,tubedevice_receiver=1,},
                tube={insert_object=function(pos,node,stack,direction)
@@ -47,12 +50,14 @@ minetest.register_node("technic:mv_electric_furnace", {
                local inv = meta:get_inventory()
                inv:set_size("src", 1)
                inv:set_size("dst", 4)
+               inv:set_size("upgrade1", 1)
+               inv:set_size("upgrade2", 1)
                local EU_used  = 0
                local furnace_is_cookin = 0
                local cooked = nil
                meta:set_float("internal_EU_buffer",0)
                meta:set_float("internal_EU_buffer_size",2000)
-
+               meta:set_float("tube_time", 0)
        end,
        can_dig = function(pos,player)
                local meta = minetest.env:get_meta(pos);
@@ -61,6 +66,10 @@ minetest.register_node("technic:mv_electric_furnace", {
                        return false
                elseif not inv:is_empty("src") then
                        return false
+               elseif not inv:is_empty("upgrade1") then
+                       return false
+               elseif not inv:is_empty("upgrade2") then
+                       return false
                end
                return true
        end,
@@ -68,8 +77,8 @@ minetest.register_node("technic:mv_electric_furnace", {
 
 minetest.register_node("technic:mv_electric_furnace_active", {
        description = "MV Electric Furnace",
-       tiles = {"technic_mv_electric_furnace_top.png", "technic_mv_electric_furnace_bottom.png", "technic_mv_electric_furnace_side.png",
-               "technic_mv_electric_furnace_side.png", "technic_mv_electric_furnace_side_tube.png", "technic_mv_electric_furnace_front_active.png"},
+       tiles = {"technic_mv_electric_furnace_top.png", "technic_mv_electric_furnace_bottom.png", "technic_mv_electric_furnace_side_tube.png",
+               "technic_mv_electric_furnace_side_tube.png", "technic_mv_electric_furnace_side.png", "technic_mv_electric_furnace_front_active.png"},
        paramtype2 = "facedir",
        light_source = 8,
        drop = "technic:mv_electric_furnace",
@@ -98,6 +107,8 @@ minetest.register_node("technic:mv_electric_furnace_active", {
                local inv = meta:get_inventory()
                inv:set_size("src", 1)
                inv:set_size("dst", 4)
+               inv:set_size("upgrade1", 1)
+               inv:set_size("upgrade2", 1)
                local EU_used  = 0
                local furnace_is_cookin = 0
                local cooked = nil
@@ -109,6 +120,10 @@ minetest.register_node("technic:mv_electric_furnace_active", {
                        return false
                elseif not inv:is_empty("src") then
                        return false
+               elseif not inv:is_empty("upgrade1") then
+                       return false
+               elseif not inv:is_empty("upgrade2") then
+                       return false
                end
                return true
        end,
@@ -121,22 +136,68 @@ minetest.register_abm({
 
        action = function(pos, node, active_object_count, active_object_count_wider)
 
-               local meta = minetest.env:get_meta(pos)
+               local pos1={}
+               pos1.x=pos.x
+               pos1.y=pos.y
+               pos1.z=pos.z
+               local x_velocity=0
+               local z_velocity=0
+               
+               -- output is on the left side of the furnace
+               if node.param2==3 then pos1.z=pos1.z-1 z_velocity =-1 end
+               if node.param2==2 then pos1.x=pos1.x-1 x_velocity =-1 end
+               if node.param2==1 then pos1.z=pos1.z+1 z_velocity = 1 end
+               if node.param2==0 then pos1.x=pos1.x+1 x_velocity = 1 end
+               
+               local output_tube_connected = false
+               local meta=minetest.env:get_meta(pos1) 
+               if meta:get_int("tubelike")==1 then output_tube_connected=true end
+               meta = minetest.env:get_meta(pos)
+               local inv = meta:get_inventory()
+               local upg_item1
+               local upg_item1_name=""
+               local upg_item2
+               local upg_item2_name=""
+               local srcstack = inv:get_stack("upgrade1", 1)
+               if srcstack then upg_item1=srcstack:to_table() end
+               srcstack = inv:get_stack("upgrade2", 1)
+               if srcstack then upg_item2=srcstack:to_table() end
+               if upg_item1 then upg_item1_name=upg_item1.name end
+               if upg_item2 then upg_item2_name=upg_item2.name end
+               
+               local speed=0
+               if upg_item1_name=="technic:control_logic_unit" then speed=speed+1 end
+               if upg_item2_name=="technic:control_logic_unit" then speed=speed+1 end
+               tube_time=meta:get_float("tube_time")
+               tube_time=tube_time+speed
+               if tube_time>3 then 
+                       tube_time=0
+                       if output_tube_connected then send_cooked_items(pos,x_velocity,z_velocity) end
+               end
+               meta:set_float("tube_time", tube_time)
+                       
+               local extra_buffer_size = 0
+               if upg_item1_name=="technic:battery" then extra_buffer_size =extra_buffer_size + 10000 end
+               if upg_item2_name=="technic:battery" then extra_buffer_size =extra_buffer_size + 10000 end
+               local internal_EU_buffer_size=2000+extra_buffer_size
+               meta:set_float("internal_EU_buffer_size",internal_EU_buffer_size)
+               
                internal_EU_buffer=meta:get_float("internal_EU_buffer")
-               internal_EU_buffer_size=meta:get_float("internal_EU_buffer")
-               local load = math.floor(internal_EU_buffer/2000 * 100)
+               if internal_EU_buffer > internal_EU_buffer_size then internal_EU_buffer = internal_EU_buffer_size end
+               local load = math.floor(internal_EU_buffer/(internal_EU_buffer_size) * 100)
                meta:set_string("formspec",
-                               "invsize[8,9;]"..
+                               "invsize[8,10;]"..
                                "image[1,1;1,2;technic_power_meter_bg.png^[lowpart:"..
                                        (load)..":technic_power_meter_fg.png]"..
                                "list[current_name;src;3,1;1,1;]"..
                                "list[current_name;dst;5,1;2,2;]"..
-                               "list[current_player;main;0,5;8,4;]"..
+                               "list[current_player;main;0,6;8,4;]"..
                                "label[0,0;MV Electric Furnace]"..
-                               "label[1,3;Power level]")
+                               "label[1,2.8;Power level]"..
+                               "list[current_name;upgrade1;1,4;1,1;]"..
+                               "list[current_name;upgrade2;2,4;1,1;]"..
+                               "label[1,5;Upgrade Slots]")
 
-               local inv = meta:get_inventory()
-               
                local furnace_is_cookin = meta:get_float("furnace_is_cookin")
                
                
@@ -191,3 +252,26 @@ minetest.register_abm({
 
 end,
 })
+
+function send_cooked_items (pos,x_velocity,z_velocity)
+               local meta=minetest.env:get_meta(pos) 
+               local inv = meta:get_inventory()
+               local i=0
+               for _,stack in ipairs(inv:get_list("dst")) do
+               i=i+1
+                       if stack then
+                       local item0=stack:to_table()
+                       if item0 then 
+                               print (dump(item0))
+                               item0["count"]="1"
+                               local item1=tube_item({x=pos.x,y=pos.y,z=pos.z},item0)
+                               item1:get_luaentity().start_pos = {x=pos.x,y=pos.y,z=pos.z}
+                               item1:setvelocity({x=x_velocity, y=0, z=z_velocity})
+                               item1:setacceleration({x=0, y=0, z=0})
+                               stack:take_item(1);
+                               inv:set_stack("dst", i, stack)
+                               return
+                               end
+                       end
+               end
+end