generator bugfix
some logic items added
This commit is contained in:
parent
a65aefbc36
commit
e52cd2295c
@ -233,6 +233,9 @@ techage.register_node({"techage:generator", "techage:generator_on"}, {
|
|||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
on_node_load = function(pos)
|
on_node_load = function(pos)
|
||||||
|
local mem = tubelib2.get_mem(pos)
|
||||||
|
-- bug workaround, TODO: remove
|
||||||
|
mem.generating = mem.techage_state == techage.RUNNING
|
||||||
State:on_node_load(pos)
|
State:on_node_load(pos)
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
@ -120,6 +120,8 @@ local function node_timer(pos, elapsed)
|
|||||||
mem.trigger = (mem.trigger or 1) - 1
|
mem.trigger = (mem.trigger or 1) - 1
|
||||||
if mem.trigger <= 0 then
|
if mem.trigger <= 0 then
|
||||||
power_switched(pos)
|
power_switched(pos)
|
||||||
|
mem.generating = false
|
||||||
|
mem.provided = 0
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
else
|
else
|
||||||
|
@ -145,8 +145,8 @@ local function determine_master(pos)
|
|||||||
local hash = 0
|
local hash = 0
|
||||||
local master = nil
|
local master = nil
|
||||||
connection_walk(pos, function(pos, mem)
|
connection_walk(pos, function(pos, mem)
|
||||||
if mem.generating and mem.could_be_master then
|
mem.generator_available = (mem.generator_available or 1) - 1
|
||||||
mem.could_be_master = false
|
if mem.generating and mem.generator_available > 0 then
|
||||||
local new = minetest.hash_node_position(pos)
|
local new = minetest.hash_node_position(pos)
|
||||||
if hash <= new then
|
if hash <= new then
|
||||||
hash = new
|
hash = new
|
||||||
@ -186,6 +186,8 @@ local function on_power_switch(pos)
|
|||||||
local mem = tubelib2.get_mem(pos)
|
local mem = tubelib2.get_mem(pos)
|
||||||
mem.master_pos = nil
|
mem.master_pos = nil
|
||||||
mem.is_master = nil
|
mem.is_master = nil
|
||||||
|
-- used to check if generator is active
|
||||||
|
mem.generator_available = 2
|
||||||
|
|
||||||
local mpos = determine_master(pos)
|
local mpos = determine_master(pos)
|
||||||
store_master(pos, mpos)
|
store_master(pos, mpos)
|
||||||
@ -323,9 +325,8 @@ end
|
|||||||
-- Called from every generator every 2 seconds
|
-- Called from every generator every 2 seconds
|
||||||
function techage.power.power_distribution(pos)
|
function techage.power.power_distribution(pos)
|
||||||
local mem = tubelib2.get_mem(pos)
|
local mem = tubelib2.get_mem(pos)
|
||||||
--print("power_distribution", S(pos), mem.is_master)
|
-- used to check if generator is active
|
||||||
-- timer is running, which is needed to be master
|
mem.generator_available = 2
|
||||||
mem.could_be_master = true
|
|
||||||
if mem.is_master then
|
if mem.is_master then
|
||||||
-- reset values for nect cycle
|
-- reset values for nect cycle
|
||||||
mem.needed1 = 0
|
mem.needed1 = 0
|
||||||
|
Loading…
Reference in New Issue
Block a user