mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2024-11-26 04:21:07 +01:00
[mcl_mobs] Replace goto
to repeat-break-until true
in spawning.lua
This commit is contained in:
parent
b14ca5a843
commit
a76fe2b487
1 changed files with 82 additions and 82 deletions
|
@ -535,21 +535,22 @@ end
|
||||||
|
|
||||||
--todo mob limiting
|
--todo mob limiting
|
||||||
--MAIN LOOP
|
--MAIN LOOP
|
||||||
|
|
||||||
if mobs_spawn then
|
if mobs_spawn then
|
||||||
local timer = 0
|
local timer = 0
|
||||||
minetest.register_globalstep(function(dtime)
|
minetest.register_globalstep(function(dtime)
|
||||||
timer = timer + dtime
|
timer = timer + dtime
|
||||||
if timer >= 8 then
|
if timer >= 8 then
|
||||||
timer = 0
|
timer = 0
|
||||||
for _,player in ipairs(minetest.get_connected_players()) do
|
for _,player in pairs(minetest.get_connected_players()) do
|
||||||
for i = 1,math.random(3,8) do
|
for i = 1,math_random(3,8) do
|
||||||
|
repeat -- after this line each "break" means "continue"
|
||||||
local player_pos = player:get_pos()
|
local player_pos = player:get_pos()
|
||||||
|
|
||||||
local _,dimension = mcl_worlds.y_to_layer(player_pos.y)
|
local _,dimension = mcl_worlds.y_to_layer(player_pos.y)
|
||||||
|
|
||||||
if dimension == "void" or dimension == "default" then
|
if dimension == "void" or dimension == "default" then
|
||||||
goto continue -- ignore void and unloaded area
|
break -- ignore void and unloaded area
|
||||||
end
|
end
|
||||||
|
|
||||||
local min,max = decypher_limits(player_pos.y)
|
local min,max = decypher_limits(player_pos.y)
|
||||||
|
@ -560,26 +561,26 @@ if mobs_spawn then
|
||||||
|
|
||||||
--couldn't find node
|
--couldn't find node
|
||||||
if #spawning_position_list <= 0 then
|
if #spawning_position_list <= 0 then
|
||||||
goto continue
|
break
|
||||||
end
|
end
|
||||||
|
|
||||||
local spawning_position = spawning_position_list[math_random(1,#spawning_position_list)]
|
local spawning_position = spawning_position_list[math_random(1,#spawning_position_list)]
|
||||||
|
|
||||||
--Prevent strange behavior/too close to player
|
--Prevent strange behavior/too close to player
|
||||||
if not spawning_position or vector_distance(player_pos, spawning_position) < 15 then
|
if not spawning_position or vector_distance(player_pos, spawning_position) < 15 then
|
||||||
goto continue
|
break
|
||||||
end
|
end
|
||||||
|
|
||||||
local gotten_node = get_node(spawning_position).name
|
local gotten_node = get_node(spawning_position).name
|
||||||
|
|
||||||
if not gotten_node or gotten_node == "air" then --skip air nodes
|
if not gotten_node or gotten_node == "air" then --skip air nodes
|
||||||
goto continue
|
break
|
||||||
end
|
end
|
||||||
|
|
||||||
local gotten_biome = minetest.get_biome_data(spawning_position)
|
local gotten_biome = minetest.get_biome_data(spawning_position)
|
||||||
|
|
||||||
if not gotten_biome then
|
if not gotten_biome then
|
||||||
goto continue --skip if in unloaded area
|
break --skip if in unloaded area
|
||||||
end
|
end
|
||||||
|
|
||||||
gotten_biome = get_biome_name(gotten_biome.biome) --makes it easier to work with
|
gotten_biome = get_biome_name(gotten_biome.biome) --makes it easier to work with
|
||||||
|
@ -588,24 +589,24 @@ if mobs_spawn then
|
||||||
local mob_def = spawn_dictionary[math.random(1,#spawn_dictionary)]
|
local mob_def = spawn_dictionary[math.random(1,#spawn_dictionary)]
|
||||||
|
|
||||||
if not mob_def then
|
if not mob_def then
|
||||||
goto continue --skip if something ridiculous happens (nil mob def)
|
break --skip if something ridiculous happens (nil mob def)
|
||||||
end
|
end
|
||||||
|
|
||||||
--skip if not correct dimension
|
--skip if not correct dimension
|
||||||
if mob_def.dimension ~= dimension then
|
if mob_def.dimension ~= dimension then
|
||||||
goto continue
|
break
|
||||||
end
|
end
|
||||||
|
|
||||||
--skip if not in correct biome
|
--skip if not in correct biome
|
||||||
if not biome_check(mob_def.biomes, gotten_biome) then
|
if not biome_check(mob_def.biomes, gotten_biome) then
|
||||||
goto continue
|
break
|
||||||
end
|
end
|
||||||
|
|
||||||
--add this so mobs don't spawn inside nodes
|
--add this so mobs don't spawn inside nodes
|
||||||
spawning_position.y = spawning_position.y + 1
|
spawning_position.y = spawning_position.y + 1
|
||||||
|
|
||||||
if spawning_position.y < mob_def.min_height or spawning_position.y > mob_def.max_height then
|
if spawning_position.y < mob_def.min_height or spawning_position.y > mob_def.max_height then
|
||||||
goto continue
|
break
|
||||||
end
|
end
|
||||||
|
|
||||||
--only need to poll for node light if everything else worked
|
--only need to poll for node light if everything else worked
|
||||||
|
@ -613,23 +614,23 @@ if mobs_spawn then
|
||||||
|
|
||||||
--don't spawn if not in light limits
|
--don't spawn if not in light limits
|
||||||
if gotten_light < mob_def.min_light or gotten_light > mob_def.max_light then
|
if gotten_light < mob_def.min_light or gotten_light > mob_def.max_light then
|
||||||
goto continue
|
break
|
||||||
end
|
end
|
||||||
|
|
||||||
local is_water = get_item_group(gotten_node, "water") ~= 0
|
local is_water = get_item_group(gotten_node, "water") ~= 0
|
||||||
local is_lava = get_item_group(gotten_node, "lava") ~= 0
|
local is_lava = get_item_group(gotten_node, "lava") ~= 0
|
||||||
|
|
||||||
if mob_def.type_of_spawning == "ground" and is_water then
|
if mob_def.type_of_spawning == "ground" and is_water then
|
||||||
goto continue
|
break
|
||||||
end
|
end
|
||||||
|
|
||||||
if mob_def.type_of_spawning == "ground" and is_lava then
|
if mob_def.type_of_spawning == "ground" and is_lava then
|
||||||
goto continue
|
break
|
||||||
end
|
end
|
||||||
|
|
||||||
--finally do the heavy check (for now) of mobs in area
|
--finally do the heavy check (for now) of mobs in area
|
||||||
if count_mobs(spawning_position, mob_def.spawn_class) >= mob_def.aoc then
|
if count_mobs(spawning_position, mob_def.spawn_class) >= mob_def.aoc then
|
||||||
goto continue
|
break
|
||||||
end
|
end
|
||||||
|
|
||||||
--adjust the position for water and lava mobs
|
--adjust the position for water and lava mobs
|
||||||
|
@ -639,8 +640,7 @@ if mobs_spawn then
|
||||||
|
|
||||||
--everything is correct, spawn mob
|
--everything is correct, spawn mob
|
||||||
minetest.add_entity(spawning_position, mob_def.name)
|
minetest.add_entity(spawning_position, mob_def.name)
|
||||||
|
until true --this is a safety catch
|
||||||
::continue:: --this is a safety catch
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue