1
0
Fork 0

Fix spawn egg crashes in different dimensions

This commit is contained in:
ancientmarinerdev 2023-03-04 01:38:51 +00:00
parent 48fa2608ed
commit 86a85bb487
2 changed files with 52 additions and 33 deletions

View File

@ -497,14 +497,11 @@ function mcl_mobs.register_egg(mob, desc, background_color, overlay_color, addeg
return def.on_rightclick(pointed_thing.under, under, placer, itemstack) return def.on_rightclick(pointed_thing.under, under, placer, itemstack)
end end
if pos if pos and within_limits(pos, 0) and not minetest.is_protected(pos, placer:get_player_name()) then
and within_limits(pos, 0)
and not minetest.is_protected(pos, placer:get_player_name()) then
local name = placer:get_player_name() local name = placer:get_player_name()
local privs = minetest.get_player_privs(name) local privs = minetest.get_player_privs(name)
local dim = mcl_worlds.pos_to_dimension(placer:get_pos())
local mob_light_lvl = {mcl_mobs:mob_light_lvl(itemstack:get_name(),dim)}
if under.name == "mcl_mobspawners:spawner" then if under.name == "mcl_mobspawners:spawner" then
if minetest.is_protected(pointed_thing.under, name) then if minetest.is_protected(pointed_thing.under, name) then
minetest.record_protection_violation(pointed_thing.under, name) minetest.record_protection_violation(pointed_thing.under, name)
@ -514,6 +511,13 @@ function mcl_mobs.register_egg(mob, desc, background_color, overlay_color, addeg
minetest.chat_send_player(name, S("You need the “maphack” privilege to change the mob spawner.")) minetest.chat_send_player(name, S("You need the “maphack” privilege to change the mob spawner."))
return itemstack return itemstack
end end
local dim = mcl_worlds.pos_to_dimension(placer:get_pos())
local mob_light_lvl = {mcl_mobs:mob_light_lvl(itemstack:get_name(),dim)}
--minetest.log("min light: " .. mob_light_lvl[1])
--minetest.log("max light: " .. mob_light_lvl[2])
mcl_mobspawners.setup_spawner(pointed_thing.under, itemstack:get_name(), mob_light_lvl[1], mob_light_lvl[2]) mcl_mobspawners.setup_spawner(pointed_thing.under, itemstack:get_name(), mob_light_lvl[1], mob_light_lvl[2])
if not minetest.is_creative_enabled(name) then if not minetest.is_creative_enabled(name) then
itemstack:take_item() itemstack:take_item()

View File

@ -482,41 +482,56 @@ end
function mcl_mobs:mob_light_lvl(mob_name, dimension) function mcl_mobs:mob_light_lvl(mob_name, dimension)
local spawn_dictionary_consolidated = {} local spawn_dictionary_consolidated = {}
--see if the mob exists in the nonspawn dictionary, if so then return light values
if non_spawn_dictionary[mob_name] ~= nil then if non_spawn_dictionary[mob_name] then
local mob_dimension = non_spawn_dictionary[mob_name][dimension] local mob_dimension = non_spawn_dictionary[mob_name][dimension]
if mob_name ~= nil then if mob_dimension then
return mob_dimension.min_light,mob_dimension.max_light --minetest.log("Found in non spawn dictionary for dimension")
return mob_dimension.min_light, mob_dimension.max_light
else else
return non_spawn_dictionary[mob_name]["overworld"].min_light, non_spawn_dictionary[mob_name]["overworld"].max_light --minetest.log("Found in non spawn dictionary but not for dimension")
local overworld_non_spawn_def = non_spawn_dictionary[mob_name]["overworld"]
if overworld_non_spawn_def then
return overworld_non_spawn_def.min_light, overworld_non_spawn_def.max_light
end
end
else
--minetest.log("must be in spawning dictionary")
for i,v in pairs(spawn_dictionary) do
local current_mob_name = spawn_dictionary[i].name
local current_mob_dim = spawn_dictionary[i].dimension
if mob_name == current_mob_name then
if not spawn_dictionary_consolidated[current_mob_name] then
spawn_dictionary_consolidated[current_mob_name] = {}
end
-- Should this really be the requested dimenion?
spawn_dictionary_consolidated[current_mob_name][current_mob_dim] = {
["min_light"] = spawn_dictionary[i].min_light,
["max_light"] = spawn_dictionary[i].max_light
}
end
end end
--if the mob doesn't exist in non_spawn, check spawn_dictonary if spawn_dictionary_consolidated[mob_name] then
else --minetest.log("is in consolidated")
for i,v in pairs(spawn_dictionary) do local mob_dimension = spawn_dictionary_consolidated[mob_name][dimension]
if spawn_dictionary[spawn_dictionary[i].name] == nil then if mob_dimension then
spawn_dictionary_consolidated[spawn_dictionary[i].name] = {} --minetest.log("found for dimension")
end
spawn_dictionary_consolidated[spawn_dictionary[i].name][dimension] = {
["min_light"] = spawn_dictionary[i].min_light,
["max_light"] = spawn_dictionary[i].max_light
}
end
if spawn_dictionary_consolidated[mob_name] ~= nil then
mob_dimension = spawn_dictionary_consolidated[mob_name][dimension]
mob_dimension_default = spawn_dictionary_consolidated[mob_name]["overworld"]
if spawn_dictionary_consolidated[mob_name] == mob_name and mob_dimension ~= nil then
return mob_dimension.min_light, mob_dimension.max_light return mob_dimension.min_light, mob_dimension.max_light
else else
return mob_dimension_default.min_light, mob_dimension_default.max_light --minetest.log("not found for dimension, use overworld def")
end local mob_dimension_default = spawn_dictionary_consolidated[mob_name]["overworld"]
else if mob_dimension_default then
minetest.log("error", "There are no light levels for this mob") return mob_dimension_default.min_light, mob_dimension_default.max_light
--default light values if mob's light values don't exist in either dictionary end
return 0, minetest.LIGHT_MAX+1 end
else
--minetest.log("not in consolidated")
end end
end end
minetest.log("action", "There are no light levels for mob (" .. tostring(mob_name) .. ") in dimension (" .. tostring(dimension) .. "). Return defaults")
return 0, minetest.LIGHT_MAX+1
end end
function mcl_mobs:non_spawn_specific(mob_name,dimension,min_light,max_light) function mcl_mobs:non_spawn_specific(mob_name,dimension,min_light,max_light)