diff --git a/forestry_bees/apiary.lua b/forestry_bees/apiary.lua index db06313..4c0de88 100644 --- a/forestry_bees/apiary.lua +++ b/forestry_bees/apiary.lua @@ -105,7 +105,9 @@ local function apiary_node_timer(pos,elapsed) local can_breed, can_live local actionable - local breedtime = 5 --hardcoded for now + local breedtime = 1 --hardcoded for now + local lifetime = 10 + local needed_time = 200 --just so that the formspecs doesnt make an error while elapsed > 0 and update do update = false @@ -116,18 +118,26 @@ local function apiary_node_timer(pos,elapsed) is_drone = minetest.get_item_group(dronelist[1]:get_name(),"bee_drone") == 1 can_breed = is_princess and is_drone - can_live = is_queen + can_live = is_queen --these two event are disjoint (there are no queen & princess) actionable = can_breed or can_live - local el = elapsed - if actionable then -- adjust el to action duration - el = math.min(el, breedtime - src_time) - end + --if can_breed then -- adjust el to action duration + -- el = math.min(el, breedtime - src_time) + --end + --if can_live then -- adjust el to action duration + -- el = math.min(el, lifetime - src_time) + --end + + local el = elapsed --if actionable check if things are ready if actionable then + --ternary expression if can_breed it evals to breedtime else lifetime + needed_time = (can_breed and {breedtime} or {lifetime})[1] + el = math.min(el, needed_time - src_time) src_time = src_time + el - if src_time >= breedtime then + + if src_time >= needed_time then --if possible act accordingly to breed or live if can_breed then local queen = forestry_bees.breed_princess_drone(monarchlist[1],dronelist[1]) @@ -141,7 +151,7 @@ local function apiary_node_timer(pos,elapsed) end inv:set_stack("monarch",1,queen) inv:set_stack("drone",1,final_drone) - src_time = src_time - breedtime + src_time = src_time - needed_time else --if actionable but not can_breed we have can_live local queen = monarchlist[1] local princess, dronelistout = forestry_bees.apiary_result(queen) @@ -152,7 +162,7 @@ local function apiary_node_timer(pos,elapsed) inv:add_item("dst",drone) end inv:set_stack("monarch",1,ItemStack()) - src_time = src_time - breedtime + src_time = src_time - needed_time update = true else dst_full = true @@ -171,15 +181,15 @@ local function apiary_node_timer(pos,elapsed) -- local formspec local item_state - local queen_percent = 0 + local percent = 0 --by default timer doesnt restart local result = false if actionable then - queen_percent = math.floor(src_time / breedtime * 100) + percent = math.floor(src_time / needed_time * 100) if dst_full then item_state = "100% (output full)" else - item_state = tostring(item_percent).."%" + item_state = tostring(percent).."%" end --make sure timer restarts result = true @@ -191,7 +201,7 @@ local function apiary_node_timer(pos,elapsed) end end - formspec = forestry_bees.get_apiary_active_formspec(queen_percent) + formspec = forestry_bees.get_apiary_active_formspec(percent) meta:set_float("src_time", src_time) meta:set_string("formspec", formspec)