forked from VoxeLibre/VoxeLibre
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:
commit
5478c8f44f
|
@ -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)
|
||||
end
|
||||
|
||||
if pos
|
||||
and within_limits(pos, 0)
|
||||
and not minetest.is_protected(pos, placer:get_player_name()) then
|
||||
|
||||
if pos and within_limits(pos, 0) and not minetest.is_protected(pos, placer:get_player_name()) then
|
||||
local name = placer:get_player_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 minetest.is_protected(pointed_thing.under, name) then
|
||||
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."))
|
||||
return itemstack
|
||||
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])
|
||||
if not minetest.is_creative_enabled(name) then
|
||||
itemstack:take_item()
|
||||
|
|
|
@ -482,41 +482,55 @@ end
|
|||
|
||||
function mcl_mobs:mob_light_lvl(mob_name, dimension)
|
||||
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
|
||||
local mob_dimension = non_spawn_dictionary[mob_name][dimension]
|
||||
if mob_name ~= nil then
|
||||
return mob_dimension.min_light,mob_dimension.max_light
|
||||
else
|
||||
return non_spawn_dictionary[mob_name]["overworld"].min_light, non_spawn_dictionary[mob_name]["overworld"].max_light
|
||||
end
|
||||
|
||||
--if the mob doesn't exist in non_spawn, check spawn_dictonary
|
||||
if non_spawn_dictionary[mob_name] then
|
||||
local mob_dimension = non_spawn_dictionary[mob_name][dimension]
|
||||
if mob_dimension then
|
||||
--minetest.log("Found in non spawn dictionary for dimension")
|
||||
return mob_dimension.min_light, mob_dimension.max_light
|
||||
else
|
||||
for i,v in pairs(spawn_dictionary) do
|
||||
if spawn_dictionary[spawn_dictionary[i].name] == nil then
|
||||
spawn_dictionary_consolidated[spawn_dictionary[i].name] = {}
|
||||
--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
|
||||
spawn_dictionary_consolidated[spawn_dictionary[i].name][dimension] = {
|
||||
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
|
||||
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
|
||||
else
|
||||
return mob_dimension_default.min_light, mob_dimension_default.max_light
|
||||
end
|
||||
else
|
||||
minetest.log("error", "There are no light levels for this mob")
|
||||
--default light values if mob's light values don't exist in either dictionary
|
||||
return 0, minetest.LIGHT_MAX+1
|
||||
end
|
||||
|
||||
if spawn_dictionary_consolidated[mob_name] then
|
||||
--minetest.log("is in consolidated")
|
||||
local mob_dimension = spawn_dictionary_consolidated[mob_name][dimension]
|
||||
if mob_dimension then
|
||||
--minetest.log("found for dimension")
|
||||
return mob_dimension.min_light, mob_dimension.max_light
|
||||
else
|
||||
--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
|
||||
else
|
||||
--minetest.log("not in consolidated")
|
||||
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
|
||||
|
||||
function mcl_mobs:non_spawn_specific(mob_name,dimension,min_light,max_light)
|
||||
|
|
Loading…
Reference in New Issue