1
0
Fork 0

Merge pull request 'Fix spawn egg crashes in different dimensions' (#3504) from fix_spawn_eggs into master

Reviewed-on: MineClone2/MineClone2#3504
This commit is contained in:
ancientmarinerdev 2023-03-04 02:19:26 +00:00
commit 5478c8f44f
2 changed files with 51 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,55 @@ 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
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")
local mob_dimension_default = spawn_dictionary_consolidated[mob_name]["overworld"]
if mob_dimension_default then
return mob_dimension_default.min_light, mob_dimension_default.max_light
end
end end
else else
minetest.log("error", "There are no light levels for this mob") --minetest.log("not in consolidated")
--default light values if mob's light values don't exist in either dictionary
return 0, minetest.LIGHT_MAX+1
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)