1
0
Fork 0

Add Village Checks

release/0.81.1
PrairieWind 2022-10-22 16:04:58 -06:00 committed by cora
parent 96ac31bec3
commit 1b6d778dd1
2 changed files with 57 additions and 4 deletions

View File

@ -82,6 +82,47 @@ mcl_raids.spawn_raid = function(pos, wave)
end end
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", { minetest.register_chatcommand("spawn_raid", {
privs = { privs = {
server = true, server = true,
@ -93,3 +134,17 @@ minetest.register_chatcommand("spawn_raid", {
mcl_raids.spawn_raid(pos, wave) mcl_raids.spawn_raid(pos, wave)
end 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)

View File

@ -355,7 +355,6 @@ minetest.register_globalstep(function(dtime)
for player, vals in pairs(EF.bad_omen) do for player, vals in pairs(EF.bad_omen) do
is_player = player:is_player() is_player = player:is_player()
entity = player:get_luaentity()
EF.bad_omen[player].timer = EF.bad_omen[player].timer + dtime 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 if EF.bad_omen[player] and EF.bad_omen[player].timer >= EF.bad_omen[player].dur then
EF.bad_omen[player] = nil EF.bad_omen[player] = nil
mcl_raids.spawn_raid(player:get_pos(), 1)
if is_player then if is_player then
meta = player:get_meta() 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) potions_set_hud(player)
end end
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")) EF.fire_proof[player] = minetest.deserialize(meta:get_string("_is_fire_proof"))
end 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")) EF.bad_omen[player] = minetest.deserialize(meta:get_string("_has_bad_omen"))
end end