Compare commits

...

2 Commits

2 changed files with 101 additions and 102 deletions

View File

@ -535,114 +535,114 @@ 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
break -- ignore void and unloaded area
end
if dimension == "void" or dimension == "default" then local min,max = decypher_limits(player_pos.y)
goto continue -- ignore void and unloaded area
end
local min,max = decypher_limits(player_pos.y) local goal_pos = position_calculation(player_pos)
local goal_pos = position_calculation(player_pos) local spawning_position_list = find_nodes_in_area_under_air(new_vector(goal_pos.x,min,goal_pos.z), vector.new(goal_pos.x,max,goal_pos.z), {"group:solid", "group:water", "group:lava"})
local spawning_position_list = find_nodes_in_area_under_air(new_vector(goal_pos.x,min,goal_pos.z), vector.new(goal_pos.x,max,goal_pos.z), {"group:solid", "group:water", "group:lava"}) --couldn't find node
if #spawning_position_list <= 0 then
break
end
--couldn't find node local spawning_position = spawning_position_list[math_random(1,#spawning_position_list)]
if #spawning_position_list <= 0 then
goto continue
end
local spawning_position = spawning_position_list[math_random(1,#spawning_position_list)] --Prevent strange behavior/too close to player
if not spawning_position or vector_distance(player_pos, spawning_position) < 15 then
break
end
--Prevent strange behavior/too close to player local gotten_node = get_node(spawning_position).name
if not spawning_position or vector_distance(player_pos, spawning_position) < 15 then
goto continue
end
local gotten_node = get_node(spawning_position).name if not gotten_node or gotten_node == "air" then --skip air nodes
break
end
if not gotten_node or gotten_node == "air" then --skip air nodes local gotten_biome = minetest.get_biome_data(spawning_position)
goto continue
end
local gotten_biome = minetest.get_biome_data(spawning_position) if not gotten_biome then
break --skip if in unloaded area
end
if not gotten_biome then gotten_biome = get_biome_name(gotten_biome.biome) --makes it easier to work with
goto continue --skip if in unloaded area
end
gotten_biome = get_biome_name(gotten_biome.biome) --makes it easier to work with --grab random mob
local mob_def = spawn_dictionary[math.random(1,#spawn_dictionary)]
--grab random mob if not mob_def then
local mob_def = spawn_dictionary[math.random(1,#spawn_dictionary)] break --skip if something ridiculous happens (nil mob def)
end
if not mob_def then --skip if not correct dimension
goto continue --skip if something ridiculous happens (nil mob def) if mob_def.dimension ~= dimension then
end break
end
--skip if not correct dimension --skip if not in correct biome
if mob_def.dimension ~= dimension then if not biome_check(mob_def.biomes, gotten_biome) then
goto continue break
end end
--skip if not in correct biome --add this so mobs don't spawn inside nodes
if not biome_check(mob_def.biomes, gotten_biome) then spawning_position.y = spawning_position.y + 1
goto continue
end
--add this so mobs don't spawn inside nodes if spawning_position.y < mob_def.min_height or spawning_position.y > mob_def.max_height then
spawning_position.y = spawning_position.y + 1 break
end
if spawning_position.y < mob_def.min_height or spawning_position.y > mob_def.max_height then --only need to poll for node light if everything else worked
goto continue local gotten_light = get_node_light(spawning_position)
end
--only need to poll for node light if everything else worked --don't spawn if not in light limits
local gotten_light = get_node_light(spawning_position) if gotten_light < mob_def.min_light or gotten_light > mob_def.max_light then
break
end
--don't spawn if not in light limits local is_water = get_item_group(gotten_node, "water") ~= 0
if gotten_light < mob_def.min_light or gotten_light > mob_def.max_light then local is_lava = get_item_group(gotten_node, "lava") ~= 0
goto continue
end
local is_water = get_item_group(gotten_node, "water") ~= 0 if mob_def.type_of_spawning == "ground" and is_water then
local is_lava = get_item_group(gotten_node, "lava") ~= 0 break
end
if mob_def.type_of_spawning == "ground" and is_water then if mob_def.type_of_spawning == "ground" and is_lava then
goto continue break
end end
if mob_def.type_of_spawning == "ground" and is_lava then --finally do the heavy check (for now) of mobs in area
goto continue if count_mobs(spawning_position, mob_def.spawn_class) >= mob_def.aoc then
end break
end
--finally do the heavy check (for now) of mobs in area --adjust the position for water and lava mobs
if count_mobs(spawning_position, mob_def.spawn_class) >= mob_def.aoc then if mob_def.type_of_spawning == "water" or mob_def.type_of_spawning == "lava" then
goto continue spawning_position.y = spawning_position.y - 1
end end
--adjust the position for water and lava mobs --everything is correct, spawn mob
if mob_def.type_of_spawning == "water" or mob_def.type_of_spawning == "lava" then minetest.add_entity(spawning_position, mob_def.name)
spawning_position.y = spawning_position.y - 1 until true --this is a safety catch
end end
end
--everything is correct, spawn mob end
minetest.add_entity(spawning_position, mob_def.name) end)
::continue:: --this is a safety catch
end
end
end
end)
end end

View File

@ -346,29 +346,28 @@ mobs:register_mob("mobs_mc:enderman", {
--skip player if they have no data - log it --skip player if they have no data - log it
if not player_eye_height then if not player_eye_height then
minetest.log("error", "Enderman at location: ".. dump(enderpos).." has indexed a null player!") minetest.log("error", "Enderman at location: ".. dump(enderpos).." has indexed a null player!")
goto continue else
end
--calculate very quickly the exact location the player is looking --calculate very quickly the exact location the player is looking
--within the distance between the two "heads" (player and enderman) --within the distance between the two "heads" (player and enderman)
local look_pos = vector.new(player_pos.x, player_pos.y + player_eye_height, player_pos.z) local look_pos = vector.new(player_pos.x, player_pos.y + player_eye_height, player_pos.z)
local look_pos_base = look_pos local look_pos_base = look_pos
local ender_eye_pos = vector.new(enderpos.x, enderpos.y + 2.75, enderpos.z) local ender_eye_pos = vector.new(enderpos.x, enderpos.y + 2.75, enderpos.z)
local eye_distance_from_player = vector.distance(ender_eye_pos, look_pos) local eye_distance_from_player = vector.distance(ender_eye_pos, look_pos)
look_pos = vector.add(look_pos, vector.multiply(look_dir, eye_distance_from_player)) look_pos = vector.add(look_pos, vector.multiply(look_dir, eye_distance_from_player))
--if looking in general head position, turn hostile --if looking in general head position, turn hostile
if minetest.line_of_sight(ender_eye_pos, look_pos_base) and vector.distance(look_pos, ender_eye_pos) <= 0.4 then if minetest.line_of_sight(ender_eye_pos, look_pos_base) and vector.distance(look_pos, ender_eye_pos) <= 0.4 then
self.provoked = "staring" self.provoked = "staring"
self.attack = minetest.get_player_by_name(obj:get_player_name()) self.attack = minetest.get_player_by_name(obj:get_player_name())
break break
else -- I'm not sure what this part does, but I don't want to break anything - jordan4ibanez else -- I'm not sure what this part does, but I don't want to break anything - jordan4ibanez
if self.provoked == "staring" then if self.provoked == "staring" then
self.provoked = "broke_contact" self.provoked = "broke_contact"
end
end end
end
::continue:: -- this is a sweep over statement, this can be used to continue even when errors occurred end
end end
end end
end end