1
0
mirror of https://codeberg.org/tenplus1/mobs_redo.git synced 2024-12-24 01:30:22 +01:00

add nil checks

This commit is contained in:
TenPlus1 2020-03-12 20:36:23 +00:00
parent ff4bb540e1
commit dc3ed1dfe3

11
api.lua
View File

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