diff --git a/forestry_bees/apiary.lua b/forestry_bees/apiary.lua index 60302fc..75b8a1f 100644 --- a/forestry_bees/apiary.lua +++ b/forestry_bees/apiary.lua @@ -118,27 +118,23 @@ local function apiary_node_timer(pos,elapsed) is_princess = minetest.get_item_group(monarchlist[1]:get_name(),"bee_princess") == 1 is_drone = minetest.get_item_group(dronelist[1]:get_name(),"bee_drone") == 1 - --------------------fix for bees taken from creative (where the genes are not created by default) - if (is_princess or is_queen) and (monarchlist[1]:get_meta():get_string("genes") == "") then - inv:set_stack("monarch",1,forestry_bees.format_bee(monarchlist[1])) + if is_queen then + if monarchlist[1]:get_meta():get_string("genes") == "" then --fix for creative queens + minetest.chat_send_all("prova") + local new_queen = forestry_bees.format_bee(monarchlist[1]) + local drone_genes = forestry_bees.return_all_genes_double(string.sub(string.match(string.match(new_queen:get_name(),":.*"),".*_"),2,-2)) + new_queen:get_meta():set_string("drone_genes", minetest.serialize(drone_genes)) + inv:set_stack("monarch",1,new_queen) + monarchlist = inv:get_list("monarch") + end + queentime = monarchlist[1]:get_meta():get_float("queentime") or 0 + src_time = queentime end - if is_drone and (dronelist[1]:get_meta():get_string("genes") == "") then - local count = dronelist[1]:get_count() - local bee = forestry_bees.format_bee(dronelist[1]) - bee:set_count(count) - inv:set_stack("drone",1,bee) - end - --------------------- can_breed = is_princess and is_drone can_live = is_queen and forestry_bees.can_queen_work(monarchlist[1], pos) --these two event are disjoint (there are no queen & princess) actionable = can_breed or can_live - if is_queen then - queentime = monarchlist[1]:get_meta():get_float("queentime") or 0 - src_time = queentime - end - local el = elapsed --if actionable check if things are ready if actionable then diff --git a/forestry_bees/helper.lua b/forestry_bees/helper.lua index 4ec0602..af14b8d 100644 --- a/forestry_bees/helper.lua +++ b/forestry_bees/helper.lua @@ -67,10 +67,17 @@ function forestry_bees.format_bee(bee) end function forestry_bees.breed_princess_drone(princess,drone) - --local princess_meta = princess:get_meta() local princess_genes = minetest.deserialize(princess:get_meta():get_string("genes")) --princess_meta["genes"] - --local drone_meta = drone:get_meta() local drone_genes = minetest.deserialize(drone:get_meta():get_string("genes")) + --fix for missing genes in bees, if we have bees with missing genes we just give them the default ones + if princess_genes == nil then + local princess_type = string.sub(string.match(string.match(princess:get_name(),":.*"),".*_"),2,-2) + princess_genes = forestry_bees.return_all_genes_double(princess_type) + end + if drone_genes == nil then + local drone_type = string.sub(string.match(string.match(drone:get_name(),":.*"),".*_"),2,-2) + drone_genes = forestry_bees.return_all_genes_double(drone_type) + end local queen = forestry_bees.Bee("queen",princess_genes) local queen_meta = queen:get_meta() queen_meta:set_string("drone_genes",minetest.serialize(drone_genes))