From 551a3ce829e43453a7f5268619351aeeeac77589 Mon Sep 17 00:00:00 2001 From: ancientmarinerdev Date: Tue, 18 Jun 2024 00:19:10 +0100 Subject: [PATCH] Fix mobs operating when in, above or next to ignore --- mods/CORE/mcl_util/init.lua | 7 ++++++ mods/ENTITIES/mcl_mobs/api.lua | 1 + mods/ENTITIES/mcl_mobs/physics.lua | 35 +++++++++++++++++++++++++----- 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/mods/CORE/mcl_util/init.lua b/mods/CORE/mcl_util/init.lua index b6fd71673..7b03c6aae 100644 --- a/mods/CORE/mcl_util/init.lua +++ b/mods/CORE/mcl_util/init.lua @@ -2,6 +2,13 @@ mcl_util = {} dofile(minetest.get_modpath(minetest.get_current_modname()).."/roman_numerals.lua") +mcl_util.plane_adjacents = { + vector.new(1,0,0), + vector.new(-1,0,0), + vector.new(0,0,1), + vector.new(0,0,-1), +} + -- 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 873d05bf2..e47bea868 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -387,6 +387,7 @@ local function on_step_work (self, dtime) local pos = self.object:get_pos() if not pos then return end + if self:check_in_unloaded_area(pos) then return end if self:check_despawn(pos, dtime) then return true end if self:outside_limits() then return end diff --git a/mods/ENTITIES/mcl_mobs/physics.lua b/mods/ENTITIES/mcl_mobs/physics.lua index 73aefb509..d6e643024 100644 --- a/mods/ENTITIES/mcl_mobs/physics.lua +++ b/mods/ENTITIES/mcl_mobs/physics.lua @@ -679,11 +679,7 @@ function mob_class:do_env_damage() local pos3 = vector.offset(pos, 0, 1, 0) self.standing_under = node_ok(pos3, "air").name - -- don't fall when on ignore, just stand still - if self.standing_in == "ignore" then - self.object:set_velocity({x = 0, y = 0, z = 0}) - -- wither rose effect - elseif self.standing_in == "mcl_flowers:wither_rose" then + if self.standing_in == "mcl_flowers:wither_rose" then mcl_potions.give_effect_by_level("withering", self.object, 2, 2) end @@ -1094,3 +1090,32 @@ function mob_class:check_suspend(player_in_active_range) return true end end + +local plane_adjacents = table.copy(mcl_util.plane_adjacents) +table.insert(plane_adjacents, vector.new(0,-1,0)) + +local function is_node_loaded(pos) + local current_node = minetest.get_node(pos) + if current_node.name == "ignore" then + return false + end + return true +end + +function mob_class:check_in_unloaded_area(pos) + local unloaded = false + if not is_node_loaded(pos) then + unloaded = true + else + for _,v in pairs(plane_adjacents) do + if not is_node_loaded(vector.add(pos, v)) then + unloaded = true + end + end + end + if unloaded then + -- do not fall or walk, or think. just stop it. we aren't ready for you yet + self.object:set_velocity(vector.zero()) + end + return unloaded +end \ No newline at end of file