Village Finder Tweaks

This commit is contained in:
PrairieWind 2022-10-22 16:41:53 -06:00 committed by cora
parent 1b6d778dd1
commit 5dc1a3d456

@ -56,7 +56,7 @@ mcl_raids.spawn_raid = function(pos, wave)
local raid_pos = vector.offset(pos,r * math.cos(((i-1)/n) * (2*math.pi)),0, r * math.sin(((i-1)/n) * (2*math.pi))) local raid_pos = vector.offset(pos,r * math.cos(((i-1)/n) * (2*math.pi)),0, r * math.sin(((i-1)/n) * (2*math.pi)))
local sn = minetest.find_nodes_in_area_under_air(vector.offset(raid_pos,0,100,0), vector.offset(raid_pos,0,-100,0), {"group:grass_block", "group:grass_block_snow", "group:snow_cover", "group:sand"}) local sn = minetest.find_nodes_in_area_under_air(vector.offset(raid_pos,0,100,0), vector.offset(raid_pos,0,-100,0), {"group:grass_block", "group:grass_block_snow", "group:snow_cover", "group:sand"})
if sn and #sn > 0 then if sn and #sn > 0 then
spawn_pos = sn[1] local spawn_pos = sn[1]
if spawn_pos then if spawn_pos then
minetest.log("action", "[mcl_raids] Raid Spawn Position chosen at " .. minetest.pos_to_string(spawn_pos) .. ".") minetest.log("action", "[mcl_raids] Raid Spawn Position chosen at " .. minetest.pos_to_string(spawn_pos) .. ".")
spawnable = true spawnable = true
@ -83,10 +83,13 @@ mcl_raids.spawn_raid = function(pos, wave)
end end
mcl_raids.find_villager = function(pos) mcl_raids.find_villager = function(pos)
local obj = minetest.get_objects_inside_radius(pos, 16) local obj = minetest.get_objects_inside_radius(pos, 8)
for _, objects in pairs(obj) do for _, objects in ipairs(obj) do
object = objects:get_luaentity() local object = objects:get_luaentity()
if object and object.name == "mobs_mc:villager" then if object then
if object.name ~= "mobs_mc:villager" then
return
elseif object.name == "mobs_mc:villager" then
minetest.log("action", "[mcl_raids] Villager Found.") minetest.log("action", "[mcl_raids] Villager Found.")
return true return true
else else
@ -94,11 +97,12 @@ mcl_raids.find_villager = function(pos)
return false return false
end end
end end
end
end end
mcl_raids.find_bed = function(pos) mcl_raids.find_bed = function(pos)
local beds = minetest.find_nodes_in_area(vector.offset(pos, -8, -8, -8), vector.offset(pos, 8, 8, 8), "mcl_beds:bed_red_bottom") local beds = minetest.find_nodes_in_area(vector.offset(pos, -8, -8, -8), vector.offset(pos, 8, 8, 8), "mcl_beds:bed_red_bottom")
if beds then if beds[1] then
minetest.log("action", "[mcl_raids] Bed Found.") minetest.log("action", "[mcl_raids] Bed Found.")
return true return true
else else
@ -113,10 +117,17 @@ mcl_raids.find_village = function(pos)
local raid_started = false local raid_started = false
if (bed and villager) and raid_started == false then if (bed and villager) and raid_started == false then
mcl_raids.spawn_raid(pos, 1) local raid = mcl_raids.spawn_raid(pos, 1)
raid_started = true if raid then
minetest.log("action", "[mcl_raids] Village found, starting raid.") minetest.log("action", "[mcl_raids] Village found, starting raid.")
raid_started = true
else
minetest.log("action", "[mcl_raids] Village found.")
end
return true return true
elseif raid_started == true then
minetest.log("action", "[mcl_raids] Raid already started.")
return
else else
minetest.log("action", "[mcl_raids] Village not found, raid is not starting.") minetest.log("action", "[mcl_raids] Village not found, raid is not starting.")
return false return false