From 8092fd573c91cbdd1f7b6ca6f42a3ad929a4291a Mon Sep 17 00:00:00 2001 From: ancientmarinerdev Date: Mon, 8 May 2023 23:16:04 +0100 Subject: [PATCH 1/3] Cleanup self.acc code and convert to new style vectors --- mods/ENTITIES/mcl_mobs/combat.lua | 20 ++++++++++++++------ mods/ENTITIES/mcl_mobs/physics.lua | 15 +++++++-------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/combat.lua b/mods/ENTITIES/mcl_mobs/combat.lua index 0ec1044f5..3b53e0d1a 100644 --- a/mods/ENTITIES/mcl_mobs/combat.lua +++ b/mods/ENTITIES/mcl_mobs/combat.lua @@ -830,16 +830,18 @@ local function clear_aggro(self) end function mob_class:do_states_attack (dtime) - local yaw = self.object:get_yaw() or 0 - - local s = self.object:get_pos() - local p = self.attack:get_pos() or s - self.timer = self.timer + dtime if self.timer > 100 then self.timer = 1 end + local s = self.object:get_pos() + if not s then return end + + local p = self.attack:get_pos() or s + + local yaw = self.object:get_yaw() or 0 + -- stop attacking if player invisible or out of range if not self.attack or not self.attack:get_pos() @@ -1141,7 +1143,13 @@ function mob_class:do_states_attack (dtime) if math.random(40) == 1 then self.strafe_direction = self.strafe_direction*-1 end - self.acc = vector.add(vector.multiply(vector.rotate_around_axis(vector.direction(s, p), vector.new(0,1,0), self.strafe_direction), 0.3*self.walk_velocity), stay_away_from_player) + + local dir = vector.rotate_around_axis(vector.direction(s, p), vector.new(0,1,0), self.strafe_direction) + local dir2 = vector.multiply(dir, 0.3 * self.walk_velocity) + + if dir2 and stay_away_from_player then + self.acc = vector.add(dir2, stay_away_from_player) + end else self:set_velocity( 0) end diff --git a/mods/ENTITIES/mcl_mobs/physics.lua b/mods/ENTITIES/mcl_mobs/physics.lua index 4ef72eed7..2859cfe98 100644 --- a/mods/ENTITIES/mcl_mobs/physics.lua +++ b/mods/ENTITIES/mcl_mobs/physics.lua @@ -198,6 +198,8 @@ end -- move mob in facing direction function mob_class:set_velocity(v) + if not v then return end + local c_x, c_y = 0, 0 -- can mob be pushed, if so calculate direction @@ -207,18 +209,15 @@ function mob_class:set_velocity(v) -- halt mob if it has been ordered to stay if self.order == "stand" or self.order == "sit" then - self.acc=vector.new(0,0,0) - return + self.acc = vector.zero() + return end local yaw = (self.object:get_yaw() or 0) + self.rotate local vv = self.object:get_velocity() - if vv then - self.acc={ - x = ((math.sin(yaw) * -v) + c_x)*.27, - y = 0, - z = ((math.cos(yaw) * v) + c_y)*.27, - } + + if vv and yaw then + self.acc = vector.new(((math.sin(yaw) * -v) + c_x) * .27, 0, ((math.cos(yaw) * v) + c_y) * .27) end end From 31e6e3801336bd4a6a6855db1ed543e353f27221 Mon Sep 17 00:00:00 2001 From: ancientmarinerdev Date: Mon, 8 May 2023 23:33:58 +0100 Subject: [PATCH 2/3] Clean up is_as_cliff code and convert to new style vector --- mods/ENTITIES/mcl_mobs/movement.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/movement.lua b/mods/ENTITIES/mcl_mobs/movement.lua index 9dedd7e2c..d97584b58 100644 --- a/mods/ENTITIES/mcl_mobs/movement.lua +++ b/mods/ENTITIES/mcl_mobs/movement.lua @@ -262,8 +262,9 @@ function mob_class:is_at_water_danger(can_jump_cliff) local ypos = pos.y + self.collisionbox[2] -- just above floor local free_fall, blocker = minetest.line_of_sight( - {x = pos.x + dir_x, y = ypos, z = pos.z + dir_z}, - {x = pos.x + dir_x, y = ypos - 3, z = pos.z + dir_z}) + vector.new(pos.x + dir_x, ypos, pos.z + dir_z), + vector.new(pos.x + dir_x, ypos - 3, pos.z + dir_z)) + if free_fall then return true else From 09619a62eeae1887c3b4b5c662598d68198ae13d Mon Sep 17 00:00:00 2001 From: ancientmarinerdev Date: Mon, 8 May 2023 23:34:45 +0100 Subject: [PATCH 3/3] Clean up is_as_cliff code and convert to new style vector part 2 --- mods/ENTITIES/mcl_mobs/movement.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/movement.lua b/mods/ENTITIES/mcl_mobs/movement.lua index d97584b58..469ac9e85 100644 --- a/mods/ENTITIES/mcl_mobs/movement.lua +++ b/mods/ENTITIES/mcl_mobs/movement.lua @@ -219,8 +219,9 @@ function mob_class:is_at_cliff_or_danger(can_jump_cliff) local ypos = pos.y + self.collisionbox[2] -- just above floor local free_fall, blocker = minetest.line_of_sight( - {x = pos.x + dir_x, y = ypos, z = pos.z + dir_z}, - {x = pos.x + dir_x, y = ypos - self.fear_height, z = pos.z + dir_z}) + vector.new(pos.x + dir_x, ypos, pos.z + dir_z), + vector.new(pos.x + dir_x, ypos - self.fear_height, pos.z + dir_z)) + if free_fall then return true else