Add Village Checks
This commit is contained in:
parent
96ac31bec3
commit
1b6d778dd1
|
@ -82,6 +82,47 @@ mcl_raids.spawn_raid = function(pos, wave)
|
|||
end
|
||||
end
|
||||
|
||||
mcl_raids.find_villager = function(pos)
|
||||
local obj = minetest.get_objects_inside_radius(pos, 16)
|
||||
for _, objects in pairs(obj) do
|
||||
object = objects:get_luaentity()
|
||||
if object and object.name == "mobs_mc:villager" then
|
||||
minetest.log("action", "[mcl_raids] Villager Found.")
|
||||
return true
|
||||
else
|
||||
minetest.log("action", "[mcl_raids] No Villager Found.")
|
||||
return false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
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")
|
||||
if beds then
|
||||
minetest.log("action", "[mcl_raids] Bed Found.")
|
||||
return true
|
||||
else
|
||||
minetest.log("action", "[mcl_raids] No Bed Found.")
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
mcl_raids.find_village = function(pos)
|
||||
local bed = mcl_raids.find_bed(pos)
|
||||
local villager = mcl_raids.find_villager(pos)
|
||||
local raid_started = false
|
||||
|
||||
if (bed and villager) and raid_started == false then
|
||||
mcl_raids.spawn_raid(pos, 1)
|
||||
raid_started = true
|
||||
minetest.log("action", "[mcl_raids] Village found, starting raid.")
|
||||
return true
|
||||
else
|
||||
minetest.log("action", "[mcl_raids] Village not found, raid is not starting.")
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_chatcommand("spawn_raid", {
|
||||
privs = {
|
||||
server = true,
|
||||
|
@ -93,3 +134,17 @@ minetest.register_chatcommand("spawn_raid", {
|
|||
mcl_raids.spawn_raid(pos, wave)
|
||||
end
|
||||
})
|
||||
|
||||
local etime = 0
|
||||
minetest.register_globalstep(function(dtime)
|
||||
etime = dtime + etime
|
||||
if etime < 10 then return end
|
||||
etime = 0
|
||||
for _,pl in pairs(minetest.get_connected_players()) do
|
||||
if pl:get_meta():get_string("_has_bad_omen") then
|
||||
mcl_raids.find_village(pl:get_pos())
|
||||
else
|
||||
return
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
|
|
@ -355,7 +355,6 @@ minetest.register_globalstep(function(dtime)
|
|||
for player, vals in pairs(EF.bad_omen) do
|
||||
|
||||
is_player = player:is_player()
|
||||
entity = player:get_luaentity()
|
||||
|
||||
EF.bad_omen[player].timer = EF.bad_omen[player].timer + dtime
|
||||
|
||||
|
@ -363,10 +362,9 @@ minetest.register_globalstep(function(dtime)
|
|||
|
||||
if EF.bad_omen[player] and EF.bad_omen[player].timer >= EF.bad_omen[player].dur then
|
||||
EF.bad_omen[player] = nil
|
||||
mcl_raids.spawn_raid(player:get_pos(), 1)
|
||||
if is_player then
|
||||
meta = player:get_meta()
|
||||
meta:set_string("_had_bad_omen", minetest.serialize(EF.bad_omen[player]))
|
||||
meta:set_string("_has_bad_omen", minetest.serialize(EF.bad_omen[player]))
|
||||
potions_set_hud(player)
|
||||
end
|
||||
end
|
||||
|
@ -505,7 +503,7 @@ function mcl_potions._load_player_effects(player)
|
|||
EF.fire_proof[player] = minetest.deserialize(meta:get_string("_is_fire_proof"))
|
||||
end
|
||||
|
||||
if minetest.deserialize(meta:get_string("_had_bad_omen")) then
|
||||
if minetest.deserialize(meta:get_string("_has_bad_omen")) then
|
||||
EF.bad_omen[player] = minetest.deserialize(meta:get_string("_has_bad_omen"))
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue