From 56958ab0c993253021f02fc1eaec1d3e5213567c Mon Sep 17 00:00:00 2001 From: MysticTempest Date: Fri, 24 Jul 2020 21:15:40 -0500 Subject: [PATCH] Fix mobs getting stuck in water, fix mobs falling off cliffs, and lower spider speed so cliff_danger check is properly applied. --- mods/ENTITIES/mcl_mobs/api.lua | 31 ++++++++++++++++++++++--------- mods/ENTITIES/mobs_mc/spider.lua | 6 ++++-- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index 34fe0ef42..ec691c624 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -298,11 +298,6 @@ end -- Returns true is node can deal damage to self local is_node_dangerous = function(self, nodename) local nn = nodename - if self.water_damage > 0 then - if minetest.get_item_group(nn, "water") ~= 0 then - return true - end - end if self.lava_damage > 0 then if minetest.get_item_group(nn, "lava") ~= 0 then return true @@ -313,6 +308,21 @@ local is_node_dangerous = function(self, nodename) return true end end + if minetest.registered_nodes[nn].damage_per_second > 0 then + return true + end + return false +end + + +-- Returns true if node is a water hazard +local is_node_waterhazard = function(self, nodename) + local nn = nodename + if self.water_damage > 0 then + if minetest.get_item_group(nn, "water") ~= 0 then + return true + end + end if minetest.registered_nodes[nn].drowning > 0 then if self.breath_max ~= -1 then -- check if the mob is water-breathing _and_ the block is water; only return true if neither is the case @@ -322,9 +332,6 @@ local is_node_dangerous = function(self, nodename) end end end - if minetest.registered_nodes[nn].damage_per_second > 0 then - return true - end return false end @@ -2049,7 +2056,7 @@ local do_states = function(self, dtime) if flight_check(self) then is_in_danger = is_node_dangerous(self, self.standing_in) elseif (is_node_dangerous(self, self.standing_in) or - is_node_dangerous(self, self.standing_on)) then + is_node_dangerous(self, self.standing_on)) or (is_node_waterhazard(self, self.standing_in) or is_node_waterhazard(self, self.standing_on)) then is_in_danger = true end @@ -3221,6 +3228,12 @@ local mob_step = function(self, dtime) runaway_from(self) + if is_at_cliff_or_danger(self) then + set_velocity(self, 0) + self.state = "stand" + set_animation(self, "stand") + end + end diff --git a/mods/ENTITIES/mobs_mc/spider.lua b/mods/ENTITIES/mobs_mc/spider.lua index f9d584075..5c92657af 100644 --- a/mods/ENTITIES/mobs_mc/spider.lua +++ b/mods/ENTITIES/mobs_mc/spider.lua @@ -37,7 +37,8 @@ local spider = { -- TODO: sounds: walk, death distance = 16, }, - walk_velocity = 3.9, + walk_velocity = 1.3, + run_velocity = 2.8, jump = true, jump_height = 4, view_range = 16, @@ -72,7 +73,8 @@ cave_spider.hp_min = 1 cave_spider.hp_max = 12 cave_spider.collisionbox = {-0.35, -0.01, -0.35, 0.35, 0.49, 0.35} cave_spider.visual_size = {x=1.66666, y=1.5} -cave_spider.walk_velocity = 4.1 +cave_spider.walk_velocity = 1.3 +cave_spider.run_velocity = 3.2 mobs:register_mob("mobs_mc:cave_spider", cave_spider)