From 7d803e174c0ec16f064ea228c1eb1314a65b3623 Mon Sep 17 00:00:00 2001 From: ancientmarinerdev Date: Thu, 26 Jan 2023 21:35:41 +0000 Subject: [PATCH 1/5] Set freeze and warning when mobs too close to boundary of world --- mods/CORE/mcl_util/init.lua | 6 ++++++ mods/ENTITIES/mcl_mobs/api.lua | 28 ++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/mods/CORE/mcl_util/init.lua b/mods/CORE/mcl_util/init.lua index f37b34444..d55ec0430 100644 --- a/mods/CORE/mcl_util/init.lua +++ b/mods/CORE/mcl_util/init.lua @@ -1,5 +1,11 @@ mcl_util = {} +local MAPGEN_LIMIT = 32000 + +function mcl_util.get_mapgen_limit() + return MAPGEN_LIMIT +end + -- Updates all values in t using values from to*. function table.update(t, ...) for _, to in ipairs {...} do diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index f5e50ba2a..1a7982ece 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -24,6 +24,10 @@ local spawn_protected = minetest.settings:get_bool("mobs_spawn_protected") ~= fa local mobs_debug = minetest.settings:get_bool("mobs_debug", false) -- Shows helpful debug info above each mob local spawn_logging = minetest.settings:get_bool("mcl_logging_mobs_spawn",true) +local MAPGEN_LIMIT = mcl_util.get_mapgen_limit() +local MAPGEN_MOB_LIMIT = mcl_util.get_mapgen_limit() - 50 + + -- Peaceful mode message so players will know there are no monsters if minetest.settings:get_bool("only_peaceful_mobs", false) then minetest.register_on_joinplayer(function(player) @@ -328,6 +332,26 @@ local function update_timers (self, dtime) end end +function mob_class:outside_limits() + local pos = self.object:get_pos() + if pos then + local posx = math.abs(pos.x) + local posy = math.abs(pos.y) + local posz = math.abs(pos.z) + if posx > MAPGEN_MOB_LIMIT or posy > MAPGEN_MOB_LIMIT or posz > MAPGEN_MOB_LIMIT then + if posx > MAPGEN_LIMIT or posy > MAPGEN_LIMIT or posz > MAPGEN_LIMIT then + minetest.log("action", "Warning mob past limits of worldgen: " .. minetest.pos_to_string(pos)) + else + minetest.log("action", "Warning mob close to limits of worldgen: " .. minetest.pos_to_string(pos)) + self:set_velocity(0) + self.state = "stand" + self:set_animation( "stand") + end + return true + end + end +end + -- main mob function function mob_class:on_step(dtime) local pos = self.object:get_pos() @@ -335,6 +359,10 @@ function mob_class:on_step(dtime) if self:check_despawn(pos, dtime) then return true end + if self:outside_limits() then + return + end + if self:check_death_and_slow_mob() then --minetest.log("action", "Mob is dying: ".. tostring(self.name)) -- Do we abandon out of here now? From d583ccb986322fac20942626a985e4feb26d13d3 Mon Sep 17 00:00:00 2001 From: ancientmarinerdev Date: Thu, 26 Jan 2023 22:01:41 +0000 Subject: [PATCH 2/5] Oooops, wrong number --- mods/CORE/mcl_util/init.lua | 2 +- mods/ENTITIES/mcl_mobs/api.lua | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/mods/CORE/mcl_util/init.lua b/mods/CORE/mcl_util/init.lua index d55ec0430..5fe97850f 100644 --- a/mods/CORE/mcl_util/init.lua +++ b/mods/CORE/mcl_util/init.lua @@ -1,6 +1,6 @@ mcl_util = {} -local MAPGEN_LIMIT = 32000 +local MAPGEN_LIMIT = 31000 function mcl_util.get_mapgen_limit() return MAPGEN_LIMIT diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index 1a7982ece..531673609 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -25,7 +25,8 @@ local mobs_debug = minetest.settings:get_bool("mobs_debug", false) -- Shows help local spawn_logging = minetest.settings:get_bool("mcl_logging_mobs_spawn",true) local MAPGEN_LIMIT = mcl_util.get_mapgen_limit() -local MAPGEN_MOB_LIMIT = mcl_util.get_mapgen_limit() - 50 +local MAPGEN_MOB_LIMIT = mcl_util.get_mapgen_limit() - 100 +-- 30927 seems to be the edge of the world, so could be closer, but this is safer -- Peaceful mode message so players will know there are no monsters @@ -339,13 +340,16 @@ function mob_class:outside_limits() local posy = math.abs(pos.y) local posz = math.abs(pos.z) if posx > MAPGEN_MOB_LIMIT or posy > MAPGEN_MOB_LIMIT or posz > MAPGEN_MOB_LIMIT then + minetest.log("action", "Getting close to limits of worldgen: " .. minetest.pos_to_string(pos)) if posx > MAPGEN_LIMIT or posy > MAPGEN_LIMIT or posz > MAPGEN_LIMIT then minetest.log("action", "Warning mob past limits of worldgen: " .. minetest.pos_to_string(pos)) else minetest.log("action", "Warning mob close to limits of worldgen: " .. minetest.pos_to_string(pos)) - self:set_velocity(0) self.state = "stand" self:set_animation( "stand") + + self.object:set_acceleration(vector.zero()) + self.object:set_velocity(vector.zero()) end return true end From c209537cfe5a111ba88581c301b289e5d1d4f33b Mon Sep 17 00:00:00 2001 From: ancientmarinerdev Date: Thu, 26 Jan 2023 22:08:50 +0000 Subject: [PATCH 3/5] Make it a bit less chatty for logging --- mods/ENTITIES/mcl_mobs/api.lua | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index 531673609..9f47de185 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -340,16 +340,17 @@ function mob_class:outside_limits() local posy = math.abs(pos.y) local posz = math.abs(pos.z) if posx > MAPGEN_MOB_LIMIT or posy > MAPGEN_MOB_LIMIT or posz > MAPGEN_MOB_LIMIT then - minetest.log("action", "Getting close to limits of worldgen: " .. minetest.pos_to_string(pos)) + --minetest.log("action", "Getting close to limits of worldgen: " .. minetest.pos_to_string(pos)) if posx > MAPGEN_LIMIT or posy > MAPGEN_LIMIT or posz > MAPGEN_LIMIT then minetest.log("action", "Warning mob past limits of worldgen: " .. minetest.pos_to_string(pos)) else - minetest.log("action", "Warning mob close to limits of worldgen: " .. minetest.pos_to_string(pos)) - self.state = "stand" - self:set_animation( "stand") - - self.object:set_acceleration(vector.zero()) - self.object:set_velocity(vector.zero()) + if self.state ~= "stand" then + minetest.log("action", "Warning mob close to limits of worldgen: " .. minetest.pos_to_string(pos)) + self.state = "stand" + self:set_animation("stand") + self.object:set_acceleration(vector.zero()) + self.object:set_velocity(vector.zero()) + end end return true end From 1f107ec0c73c1210dd0d61662e46790249368760 Mon Sep 17 00:00:00 2001 From: ancientmarinerdev Date: Thu, 26 Jan 2023 22:10:49 +0000 Subject: [PATCH 4/5] Tidy --- mods/ENTITIES/mcl_mobs/api.lua | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index 9f47de185..05fe2f4f7 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -363,10 +363,7 @@ function mob_class:on_step(dtime) if not pos then return end if self:check_despawn(pos, dtime) then return true end - - if self:outside_limits() then - return - end + if self:outside_limits() then return end if self:check_death_and_slow_mob() then --minetest.log("action", "Mob is dying: ".. tostring(self.name)) From 245ce9922373dccd2663961c701248e4f3847db5 Mon Sep 17 00:00:00 2001 From: ancientmarinerdev Date: Mon, 30 Jan 2023 20:52:33 +0000 Subject: [PATCH 5/5] Using mcl_vars --- mods/CORE/mcl_util/init.lua | 6 ------ mods/ENTITIES/mcl_mobs/api.lua | 4 ++-- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/mods/CORE/mcl_util/init.lua b/mods/CORE/mcl_util/init.lua index 5fe97850f..f37b34444 100644 --- a/mods/CORE/mcl_util/init.lua +++ b/mods/CORE/mcl_util/init.lua @@ -1,11 +1,5 @@ mcl_util = {} -local MAPGEN_LIMIT = 31000 - -function mcl_util.get_mapgen_limit() - return MAPGEN_LIMIT -end - -- Updates all values in t using values from to*. function table.update(t, ...) for _, to in ipairs {...} do diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index 05fe2f4f7..1e7c9168b 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -24,8 +24,8 @@ local spawn_protected = minetest.settings:get_bool("mobs_spawn_protected") ~= fa local mobs_debug = minetest.settings:get_bool("mobs_debug", false) -- Shows helpful debug info above each mob local spawn_logging = minetest.settings:get_bool("mcl_logging_mobs_spawn",true) -local MAPGEN_LIMIT = mcl_util.get_mapgen_limit() -local MAPGEN_MOB_LIMIT = mcl_util.get_mapgen_limit() - 100 +local MAPGEN_LIMIT = mcl_vars.mapgen_limit +local MAPGEN_MOB_LIMIT = MAPGEN_LIMIT - 90 -- 30927 seems to be the edge of the world, so could be closer, but this is safer