tweak do_jump for better blockage checks

This commit is contained in:
tenplus1 2023-05-18 08:53:08 +01:00
parent ce53afcfdb
commit 1e3d26937e
1 changed files with 18 additions and 18 deletions

36
api.lua
View File

@ -25,7 +25,7 @@ local use_cmi = minetest.global_exists("cmi")
mobs = { mobs = {
mod = "redo", mod = "redo",
version = "20230517", version = "20230518",
intllib = S, intllib = S,
invis = minetest.global_exists("invisibility") and invisibility or {} invis = minetest.global_exists("invisibility") and invisibility or {}
} }
@ -1213,17 +1213,9 @@ end
-- jump if facing a solid node (not fences or gates) -- jump if facing a solid node (not fences or gates)
function mob_class:do_jump() function mob_class:do_jump()
if not self.jump
or self.jump_height == 0
or self.fly
or self.child
or self.order == "stand" then
return false
end
self.facing_fence = false self.facing_fence = false
-- something stopping us while moving? -- can't jump if already moving in air
if self.state ~= "stand" if self.state ~= "stand"
and self:get_velocity() > 0.5 and self:get_velocity() > 0.5
and self.object:get_velocity().y ~= 0 then and self.object:get_velocity().y ~= 0 then
@ -1273,9 +1265,13 @@ print("on: " .. self.standing_on
self.facing_fence = false self.facing_fence = false
end end
-- jump if standing on solid node (not snow) and not blocked -- jump if possible
if (self.walk_chance == 0 or minetest.registered_items[nod.name].walkable) if self.jump and self.jump_height > 0 and not self.fly and not self.child
and not blocked and not self.facing_fence and nod.name ~= node_snow then and self.order ~= "stand"
and (self.walk_chance == 0 or minetest.registered_items[nod.name].walkable)
and not blocked
and not self.facing_fence
and nod.name ~= node_snow then
local v = self.object:get_velocity() local v = self.object:get_velocity()
@ -3401,6 +3397,10 @@ function mob_class:on_step(dtime, moveresult)
-- has mob expired (0.25 instead of dtime since were in a timer) -- has mob expired (0.25 instead of dtime since were in a timer)
self:mob_expire(pos, 0.25) self:mob_expire(pos, 0.25)
-- check if mob can jump or is blocked facing fence/gate etc.
self:do_jump()
end end
-- check if falling, flying, floating and return if player died -- check if falling, flying, floating and return if player died
@ -3485,9 +3485,9 @@ function mob_class:on_step(dtime, moveresult)
self.timer = 1 self.timer = 1
end end
-- when attacking call do_states live -- when attacking call do_states live (return if dead)
if self.state == "attack" then if self.state == "attack" then
self:do_states(dtime) if self:do_states(dtime) then return end
end end
-- one second timed calls -- one second timed calls
@ -3506,12 +3506,12 @@ function mob_class:on_step(dtime, moveresult)
self:follow_flop() self:follow_flop()
-- when not attacking call do_states every second -- when not attacking call do_states every second (return if dead)
if self.state ~= "attack" then if self.state ~= "attack" then
self:do_states(dtime) if self:do_states(dtime) then return end
end end
self:do_jump() -- self:do_jump()
self:do_runaway_from(self) self:do_runaway_from(self)