Make unconnected generators burn the fuel they still have.
authorNovatux <nathanael.courant@laposte.net>
Sat, 12 Jul 2014 07:50:50 +0000 (09:50 +0200)
committerNovatux <nathanael.courant@laposte.net>
Sat, 12 Jul 2014 07:50:50 +0000 (09:50 +0200)
technic/machines/HV/nuclear_reactor.lua
technic/machines/register/generator.lua
technic/machines/switching_station.lua

index 580bd581829bc6e1eee842eef524ccd766858f3c..3f573bf23b2884d5b25a60b4540605c2b90ad175 100644 (file)
@@ -236,7 +236,29 @@ minetest.register_node("technic:hv_nuclear_reactor_core_active", {
        allow_metadata_inventory_take = technic.machine_inventory_take,
        allow_metadata_inventory_move = technic.machine_inventory_move,
        technic_run = run,
-       technic_disabled_machine_name = "technic:hv_nuclear_reactor_core",
+       technic_on_disable = function(pos, node)
+               local timer = minetest.get_node_timer(pos)
+               timer:start(1)
+        end,
+       on_timer = function(pos, node)
+               local meta = minetest.get_meta(pos)
+               
+               -- Connected back?
+               if meta:get_int("HV_EU_timeout") > 0 then return end    
+               
+               local burn_time = meta:get_int("burn_time") or 0
+
+               if burn_time >= burn_ticks or burn_time == 0 then
+                       meta:set_int("HV_EU_supply", 0)
+                       meta:set_int("burn_time", 0)
+                       technic.swap_node(pos, "technic:hv_nuclear_reactor_core")
+                       return
+               end
+               
+               meta:set_int("burn_time", burn_time + 1)
+               local timer = minetest.get_node_timer(pos)
+               timer:start(1)
+       end,
 })
 
 technic.register_machine("HV", "technic:hv_nuclear_reactor_core",        technic.producer)
index d481242e46ed847d1a648e2fde16dbb9256b4f6f..ec1ea796331ab9f7e40a74677cbe1aa09e39ca54 100644 (file)
@@ -126,7 +126,40 @@ function technic.register_generator(data)
                allow_metadata_inventory_take = technic.machine_inventory_take,
                allow_metadata_inventory_move = technic.machine_inventory_move,
                technic_run = run,
-               technic_disabled_machine_name = "technic:"..ltier.."_generator",
+               technic_on_disable = function(pos, node)
+                       local timer = minetest.get_node_timer(pos)
+                       timer:start(1)
+               end,
+               on_timer = function(pos, node)
+                       local meta = minetest.get_meta(pos)
+                       
+                       -- Connected back?
+                       if meta:get_int(tier.."_EU_timeout") > 0 then return end
+                       
+                       local burn_time = meta:get_int("burn_time") or 0
+
+                       if burn_time <= 0 then
+                               meta:set_int(tier.."_EU_supply", 0)
+                               meta:set_int("burn_time", 0)
+                               technic.swap_node(pos, "technic:"..ltier.."_generator")
+                               return
+                       end
+
+                       local burn_totaltime = meta:get_int("burn_totaltime") or 0
+                       if burn_totaltime == 0 then burn_totaltime = 1 end
+                       burn_time = burn_time - 1
+                       meta:set_int("burn_time", burn_time)
+                       local percent = math.floor(burn_time / burn_totaltime * 100)
+                       meta:set_string("formspec", 
+                               "size[8, 9]"..
+                               "label[0, 0;"..minetest.formspec_escape(desc).."]"..
+                               "list[current_name;src;3, 1;1, 1;]"..
+                               "image[4, 1;1, 1;default_furnace_fire_bg.png^[lowpart:"..
+                               (percent)..":default_furnace_fire_fg.png]"..
+                               "list[current_player;main;0, 5;8, 4;]")
+                       local timer = minetest.get_node_timer(pos)
+                       timer:start(1)
+               end,
        })
 
        technic.register_machine(tier, "technic:"..ltier.."_generator",        technic.producer)
index 8c31d5a3201ca39fa334a9f5b7b33df8e2f8c2fd..0040f13066d80e1cc9d440d23013fe1517e04cb3 100644 (file)
@@ -359,9 +359,10 @@ minetest.register_abm({
                        if machines[node.name] and switching_station_timeout_count(pos, tier) then
                                local nodedef = minetest.registered_nodes[node.name]
                                if nodedef and nodedef.technic_disabled_machine_name then
-                                       print(nodedef.technic_disabled_machine_name)
                                        node.name = nodedef.technic_disabled_machine_name
                                        minetest.swap_node(pos, node)
+                               elseif nodedef and nodedef.technic_on_disable then
+                                       nodedef.technic_on_disable(pos, node)
                                end
                                if nodedef then
                                        local meta = minetest.get_meta(pos)