add nil checks

This commit is contained in:
TenPlus1 2020-03-12 20:36:23 +00:00
parent ff4bb540e1
commit dc3ed1dfe3
1 changed files with 9 additions and 2 deletions

11
api.lua
View File

@ -6,7 +6,7 @@ local use_cmi = minetest.global_exists("cmi")
mobs = {
mod = "redo",
version = "20200306",
version = "20200312",
intllib = S,
invis = minetest.global_exists("invisibility") and invisibility or {}
}
@ -234,9 +234,11 @@ function mob_class:set_velocity(v)
v = v or 0
-- set velocity with hard limit of 10
local vel = self.object:get_velocity()
self.object:set_velocity({
x = max(-10, min((sin(yaw) * -v) + c_x, 10)),
y = max(-10, min((self.object:get_velocity().y or 0), 10)),
y = max(-10, min((vel and vel.y or 0), 10)),
z = max(-10, min((cos(yaw) * v) + c_y, 10))
})
end
@ -838,6 +840,11 @@ function mob_class:is_at_cliff()
return false
end
-- if object no longer exists then return
if not self.object:get_luaentity() then
return false
end
local yaw = self.object:get_yaw()
local dir_x = -sin(yaw) * (self.collisionbox[4] + 0.5)
local dir_z = cos(yaw) * (self.collisionbox[4] + 0.5)