From 8180f79d6cd06a6189ebb74a570899771ce63711 Mon Sep 17 00:00:00 2001 From: Alexander Minges Date: Fri, 1 May 2020 22:39:11 +0200 Subject: [PATCH] try to fix mobs stuck forever in water --- mods/ENTITIES/mcl_mobs/api.lua | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index cb936510..0cf10941 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -2044,7 +2044,7 @@ local do_states = function(self, dtime) local is_in_danger = false if lp then - minetest.log(self.name .. ": " .. minetest.get_node(lp).name) + -- minetest.log(self.name .. ": " .. minetest.get_node(lp).name) -- if mob is flying, only check the block it is inside if self.fly then if is_node_dangerous(self, self.standing_in) then @@ -2066,17 +2066,35 @@ local do_states = function(self, dtime) -- is the chosen destination safe and walkable? Retry if not (max 10 iterations) local i = 0 - while i < 10 do + local max_i = 10 + while i < max_i do + local node_above_ok = false if lp then nn = minetest.get_node(lp).name - -- minetest.log("Found solid block: " .. nn) - if not is_node_dangerous(self, nn) and minetest.registered_nodes[nn].walkable then break + local pos = {x = lp.x, y = lp.y + 2, z = lp.z} + local node_above = minetest.get_node(pos) + local nn_above = node_above.name + + minetest.log("Node: " .. nn .. " Node above: " .. nn_above) + if self.breath_max ~= -1 then + -- water-breathing mobs don't have to avoid water, but air + if self.breathes_in_water and minetest.get_item_group(nn_above, "water") then + node_above_ok = true + elseif not self.breathes_in_water and nn_above == "air" then + node_above_ok = true + end + else + node_above_ok = true + end + if not is_node_dangerous(self, nn) and minetest.registered_nodes[nn].walkable and node_above_ok then + minetest.log(self.name .. ": Found solid block: " .. nn .. " Above: " .. nn_above) + break end -- look for solid node 5 blocks around the mob's position - elseif i < 5 then + elseif i < (max_i / 2) then lp = minetest.find_node_near(s, 5, {"group:solid"}) -- after 5 iterations double search radius - elseif i < 10 then + elseif i < max_i then lp = minetest.find_node_near(s, 10, {"group:solid"}) end i = i + 1