From f11b774c95683cc4df3b10c94feb26d524b330c9 Mon Sep 17 00:00:00 2001 From: TenPlus1 Date: Thu, 30 Apr 2020 09:33:46 +0100 Subject: [PATCH] tweaked jumping and turning when blocked in front --- api.lua | 46 +++++++++++++++++++++------------------------- readme.MD | 2 +- 2 files changed, 22 insertions(+), 26 deletions(-) diff --git a/api.lua b/api.lua index f17f4fe..d2c38bf 100644 --- a/api.lua +++ b/api.lua @@ -6,7 +6,7 @@ local use_cmi = minetest.global_exists("cmi") mobs = { mod = "redo", - version = "20200429", + version = "20200430", intllib = S, invis = minetest.global_exists("invisibility") and invisibility or {} } @@ -1086,20 +1086,14 @@ function mob_class:do_jump() z = pos.z + dir_z }) - -- is there space to jump up? - if minetest.registered_nodes[nodt.name].walkable == true then - return false - end - - -- thin blocks that do not need to be jumped - if nod.name == node_snow then - return false - end - --print ("in front:", nod.name, pos.y + 0.5) +--print ("in front above:", nodt.name, pos.y + 1.5) - if self.walk_chance == 0 - or minetest.registered_items[nod.name].walkable then + -- jump if standing on solid node (not snow) and not blocked above + if (self.walk_chance == 0 + or minetest.registered_items[nod.name].walkable) + and minetest.registered_nodes[nodt.name].walkable ~= true + and nod.name ~= node_snow then if not nod.name:find("fence") and not nod.name:find("gate") @@ -1129,27 +1123,29 @@ function mob_class:do_jump() if self:get_velocity() > 0 then self:mob_sound(self.sounds.jump) end + + return true else self.facing_fence = true end + end - -- if we jumped against a block/wall 4 times then turn - if self.object:get_velocity().x ~= 0 - or self.object:get_velocity().z ~= 0 then + -- if blocked against a block/wall for 5 counts then turn + if not self.following + and (self.object:get_velocity().x == 0 + or self.object:get_velocity().z == 0) then - self.jump_count = (self.jump_count or 0) + 1 + self.jump_count = (self.jump_count or 0) + 1 --print ("----", self.jump_count) - if self.jump_count == 4 then + if self.jump_count > 4 then - local yaw = self.object:get_yaw() or 0 + local yaw = self.object:get_yaw() or 0 + local turn = random(0, 2) + 1.35 - yaw = self:set_yaw(yaw + 1.35, 8) ---print ("---- turn") - self.jump_count = 0 - end + yaw = self:set_yaw(yaw + turn, 12) +--print ("---- turn", turn) + self.jump_count = 0 end - - return true end return false diff --git a/readme.MD b/readme.MD index cb26894..ae6dfb2 100644 --- a/readme.MD +++ b/readme.MD @@ -23,7 +23,7 @@ Lucky Blocks: 9 Changelog: -- 1.51 - Added some node checks for dangerous nodes, jumping and falling (thx for idea wuzzy) +- 1.51 - Added some node checks for dangerous nodes, jumping and falling tweaks (thx for idea wuzzy) - 1.50 - Added new line_of_sight function that uses raycasting if mt5.0 is found, (thanks Astrobe), dont spawn mobs if world anchor nearby (technic or simple_anchor mods), chinese local added - 1.49- Added mobs:force_capture(self, player) function, api functions now use metatables thanks to bell07 - 1.48- Add mobs:set_velocity(self, velocity) global function