From d07d0ae31c0d39c526c8418e725b5dce1d120793 Mon Sep 17 00:00:00 2001 From: jordan4ibanez Date: Thu, 15 Apr 2021 15:34:07 -0400 Subject: [PATCH] Make mobs jump properly --- .../mcl_mobs/api/mob_functions/ai.lua | 42 +++++++++++++++++++ .../mcl_mobs/api/mob_functions/movement.lua | 12 ++++++ 2 files changed, 54 insertions(+) diff --git a/mods/ENTITIES/mcl_mobs/api/mob_functions/ai.lua b/mods/ENTITIES/mcl_mobs/api/mob_functions/ai.lua index 1a3066b971..a1f829d848 100644 --- a/mods/ENTITIES/mcl_mobs/api/mob_functions/ai.lua +++ b/mods/ENTITIES/mcl_mobs/api/mob_functions/ai.lua @@ -1,5 +1,14 @@ local math_random = math.random +local vector_multiply = vector.multiply + +local minetest_yaw_to_dir = minetest.yaw_to_dir +local minetest_get_item_group = minetest.get_item_group +local minetest_get_node = minetest.get_node + + + + -- execute current state (stand, walk, run, attacks) -- returns true if mob has died local do_states = function(self, dtime) @@ -17,6 +26,35 @@ local do_states = function(self, dtime) end + + + + +--check if a mob needs to jump +local jump_check = function(self,dtime) + + local pos = self.object:get_pos() + pos.y = pos.y + 0.1 + local dir = minetest_yaw_to_dir(self.yaw) + + local collisionbox = self.object:get_properties().collisionbox + local radius = collisionbox[4] + 0.5 + + vector_multiply(dir, radius) + + + local test_dir = vector.add(pos,dir) + + if minetest_get_item_group(minetest_get_node(test_dir).name, "solid") ~= 0 then + print("jump") + mobs.jump(self) + end +end + + + + + mobs.mob_step = function(self, dtime) --do not continue if non-existent @@ -34,6 +72,8 @@ mobs.mob_step = function(self, dtime) do_states(self, dtime) + jump_check(self) + mobs.movement_rotation_lock(self) @@ -201,4 +241,6 @@ mobs.mob_step = function(self, dtime) end end ]]-- + + self.old_velocity = self.object:get_velocity() end diff --git a/mods/ENTITIES/mcl_mobs/api/mob_functions/movement.lua b/mods/ENTITIES/mcl_mobs/api/mob_functions/movement.lua index 8fb30f76a5..72ee3824d7 100644 --- a/mods/ENTITIES/mcl_mobs/api/mob_functions/movement.lua +++ b/mods/ENTITIES/mcl_mobs/api/mob_functions/movement.lua @@ -51,4 +51,16 @@ mobs.get_velocity = function(self) end return 0 +end + +--make mobs jump +mobs.jump = function(self, velocity) + + if self.object:get_velocity().y ~= 0 or not self.old_velocity or (self.old_velocity and self.old_velocity.y > 0) then + return + end + + velocity = velocity or 5 + + self.object:add_velocity(vector_new(0,velocity,0)) end \ No newline at end of file