forked from VoxeLibre/VoxeLibre
Fix spawn egg crashes in different dimensions
This commit is contained in:
parent
48fa2608ed
commit
86a85bb487
|
@ -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()
|
||||||
|
|
|
@ -482,42 +482,57 @@ 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
|
||||||
|
--minetest.log("Found in non spawn dictionary for dimension")
|
||||||
return mob_dimension.min_light, mob_dimension.max_light
|
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
|
end
|
||||||
|
|
||||||
--if the mob doesn't exist in non_spawn, check spawn_dictonary
|
|
||||||
else
|
else
|
||||||
|
--minetest.log("must be in spawning dictionary")
|
||||||
for i,v in pairs(spawn_dictionary) do
|
for i,v in pairs(spawn_dictionary) do
|
||||||
if spawn_dictionary[spawn_dictionary[i].name] == nil then
|
local current_mob_name = spawn_dictionary[i].name
|
||||||
spawn_dictionary_consolidated[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
|
end
|
||||||
spawn_dictionary_consolidated[spawn_dictionary[i].name][dimension] = {
|
-- Should this really be the requested dimenion?
|
||||||
|
spawn_dictionary_consolidated[current_mob_name][current_mob_dim] = {
|
||||||
["min_light"] = spawn_dictionary[i].min_light,
|
["min_light"] = spawn_dictionary[i].min_light,
|
||||||
["max_light"] = spawn_dictionary[i].max_light
|
["max_light"] = spawn_dictionary[i].max_light
|
||||||
}
|
}
|
||||||
end
|
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
|
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
|
||||||
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)
|
function mcl_mobs:non_spawn_specific(mob_name,dimension,min_light,max_light)
|
||||||
table.insert(non_spawn_dictionary, mob_name)
|
table.insert(non_spawn_dictionary, mob_name)
|
||||||
|
|
Loading…
Reference in New Issue