From 3d1fb8cf4af394e42263ccb3f994a14988740584 Mon Sep 17 00:00:00 2001 From: ancientmarinerdev Date: Fri, 12 May 2023 20:17:13 +0100 Subject: [PATCH] Clean up and optimise falling --- mods/ENTITIES/mcl_mobs/physics.lua | 37 +++++++++++------------------- 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/physics.lua b/mods/ENTITIES/mcl_mobs/physics.lua index 2859cfe98..55199d9f3 100644 --- a/mods/ENTITIES/mcl_mobs/physics.lua +++ b/mods/ENTITIES/mcl_mobs/physics.lua @@ -903,47 +903,36 @@ function mob_class:falling(pos) -- floating in water (or falling) local v = self.object:get_velocity() if v then + local new_acceleration + if v.y > 0 then -- apply gravity when moving up - self.object:set_acceleration({ - x = 0, - y = DEFAULT_FALL_SPEED, - z = 0 - }) - + new_acceleration = vector.new(0, DEFAULT_FALL_SPEED, 0) elseif v.y <= 0 and v.y > self.fall_speed then -- fall downwards at set speed - self.object:set_acceleration({ - x = 0, - y = self.fall_speed, - z = 0 - }) + new_acceleration = vector.new(0, self.fall_speed, 0) else -- stop accelerating once max fall speed hit - self.object:set_acceleration({x = 0, y = 0, z = 0}) + new_acceleration =vector.zero() end + + self.object:set_acceleration(new_acceleration) end local acc = self.object:get_acceleration() - if minetest.registered_nodes[node_ok(pos).name].groups.lava then + local registered_node = minetest.registered_nodes[node_ok(pos).name] + + if registered_node.groups.lava then if acc and self.floats_on_lava == 1 then - self.object:set_acceleration({ - x = 0, - y = -self.fall_speed / (math.max(1, v.y) ^ 2), - z = 0 - }) + self.object:set_acceleration(vector.new(0, -self.fall_speed / (math.max(1, v.y) ^ 2), 0)) end end -- in water then float up - if minetest.registered_nodes[node_ok(pos).name].groups.water then + if registered_node.groups.water then if acc and self.floats == 1 then - self.object:set_acceleration({ - x = 0, - y = -self.fall_speed / (math.max(1, v.y) ^ 2), - z = 0 - }) + self.object:set_acceleration(vector.new(0, -self.fall_speed / (math.max(1, v.y) ^ 2), 0)) end else -- fall damage onto solid ground