From 53cb7d4edb0087b55252f9f7531e958c69b2e97d Mon Sep 17 00:00:00 2001 From: Alexander Minges Date: Sun, 3 May 2020 17:53:04 +0200 Subject: [PATCH] Revert "simplify code and add comments" This reverts commit 476b36de6d738e2490f8249f23c0ceff39dd8b20. --- mods/ENTITIES/mcl_mobs/api.lua | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index 30955b50..cf3913af 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -2055,29 +2055,34 @@ local do_states = function(self, dtime) -- If mob in or on dangerous block, look for land if is_in_danger then local tab_lp = nil - -- if water breathing, get water blocks around mob position if self.breathes_in_water and self.fly then tab_lp = minetest.find_nodes_in_area({x=s.x-1, y=s.y-1, z=s.z-1}, {x=s.x+1, y=s.y+1, z=s.z+1}, {"group:water"}) - -- if mob is standing in water, it can only escape, if the destination is at water level elseif minetest.get_item_group(self.standing_in, "water") then - tab_lp = minetest.find_nodes_in_area_under_air({x=s.x-1, y=s.y-1, z=s.z-1}, {x=s.x+1, y=s.y-1, z=s.z+1}, {"group:solid"}) - -- if not jumping, destination needs to be on the same level, but we can consider falling down to the destination - elseif not self.jump then tab_lp = minetest.find_nodes_in_area_under_air({x=s.x-1, y=s.y-self.fear_height, z=s.z-1}, {x=s.x+1, y=s.y-1, z=s.z+1}, {"group:solid"}) - -- otherwise mob can also jump up to its destination + elseif not self.jump then + tab_lp = minetest.find_nodes_in_area_under_air({x=s.x-1, y=s.y-1, z=s.z-1}, {x=s.x+1, y=s.y-1, z=s.z+1}, {"group:solid"}) else tab_lp = minetest.find_nodes_in_area_under_air({x=s.x-1, y=s.y-self.fear_height, z=s.z-1}, {x=s.x+1, y=s.y+(self.jump_height - 1), z=s.z+1}, {"group:solid"}) end - -- did we find land? Iterate over results + -- did we find land? if #tab_lp >= 1 then for index, lp in ipairs(tab_lp) do local nn = minetest.get_node(lp).name local node_above_ok = false + local y_difference = lp.y - s.y + local y_difference_ok = false + + if y_difference <= 0 then + y_difference_ok = true + elseif (y_difference <= self.jump_height) and not minetest.get_item_group(nn, "water") then + y_difference_ok = true + end + -- is the chosen destination safe and walkable? - if not is_node_dangerous(self, nn) and minetest.registered_nodes[nn].walkable then + if not is_node_dangerous(self, nn) and minetest.registered_nodes[nn].walkable and y_difference_ok then -- check node at y + 2 above local lp_above = {x = lp.x, y = lp.y + 1, z = lp.z} local nn_above = minetest.get_node(lp_above).name