now creative bees do not crash the mod

This commit is contained in:
StochasticMouse 2024-10-15 20:14:56 +02:00
parent 4685008ff7
commit 30f1a93f73
2 changed files with 20 additions and 17 deletions

View File

@ -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_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 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_queen then
if (is_princess or is_queen) and (monarchlist[1]:get_meta():get_string("genes") == "") then if monarchlist[1]:get_meta():get_string("genes") == "" then --fix for creative queens
inv:set_stack("monarch",1,forestry_bees.format_bee(monarchlist[1])) 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 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_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) 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 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 local el = elapsed
--if actionable check if things are ready --if actionable check if things are ready
if actionable then if actionable then

View File

@ -67,10 +67,17 @@ function forestry_bees.format_bee(bee)
end end
function forestry_bees.breed_princess_drone(princess,drone) 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 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")) 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 = forestry_bees.Bee("queen",princess_genes)
local queen_meta = queen:get_meta() local queen_meta = queen:get_meta()
queen_meta:set_string("drone_genes",minetest.serialize(drone_genes)) queen_meta:set_string("drone_genes",minetest.serialize(drone_genes))