From 057a78ed307e9509a5208f44741d94413decb287 Mon Sep 17 00:00:00 2001 From: cora Date: Thu, 17 Nov 2022 05:39:55 +0100 Subject: [PATCH] Fix raid registering as completed when unloading the area --- mods/CORE/mcl_events/init.lua | 8 +++----- mods/ENVIRONMENT/mcl_raids/init.lua | 10 +++++++++- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/mods/CORE/mcl_events/init.lua b/mods/CORE/mcl_events/init.lua index 22a2bcdf6..1e278d80f 100644 --- a/mods/CORE/mcl_events/init.lua +++ b/mods/CORE/mcl_events/init.lua @@ -127,13 +127,11 @@ function check_events(dtime) for idx,ae in pairs(active_events) do local player_near = false for _,pl in pairs(minetest.get_connected_players()) do - if ae.pos and vector.distance(pl:get_pos(),ae.pos) < 256 then player_near = true end + if ae.pos and vector.distance(pl:get_pos(),ae.pos) < 150 then player_near = true end end if ae.pos and not player_near then - if ae.fail and ae:fail() ~= true then - mcl_log("[mcl_events] Event "..e.readable_name.." at "..minetest.pos_to_string(vector.round(p.pos)).." aborted - no players near." ) - active_events[idx] = nil - end + mcl_log("[mcl_events] Event "..ae.readable_name.." at "..minetest.pos_to_string(vector.round(ae.pos)).." aborted - no players near." ) + active_events[idx] = nil end end end diff --git a/mods/ENVIRONMENT/mcl_raids/init.lua b/mods/ENVIRONMENT/mcl_raids/init.lua index 4a4120c9d..4918b6059 100644 --- a/mods/ENVIRONMENT/mcl_raids/init.lua +++ b/mods/ENVIRONMENT/mcl_raids/init.lua @@ -157,7 +157,7 @@ function mcl_raids.spawn_raid(event) local n = 12 local i = math.random(1, n) 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,-5,-50,-5), vector.offset(raid_pos,5,50,5), {"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,-5,-50,-5), vector.offset(raid_pos,5,50,5), {"group:grass_block", "group:grass_block_snow", "group:snow_cover", "group:sand", "mcl_core:ice"}) mcl_bells.ring_once(pos) if sn and #sn > 0 then local spawn_pos = sn[math.random(#sn)] @@ -268,6 +268,14 @@ mcl_events.register_event("raid",{ end, on_stage_begin = mcl_raids.spawn_raid, cond_complete = function(self) + local player_near = false + for _,pl in pairs(minetest.get_connected_players()) do + if self.pos and vector.distance(pl:get_pos(),self.pos) < 72 then player_near = true end + end + if not player_near then return false end + --let the event api handle cancel the event when no players are near + --without this check it would sort out the unloaded mob entities and + --think the raid is defeated. local m = {} for k,o in pairs(self.mobs) do if o and o:get_pos() then