[mineclone5] [mcl_mobs] Avoid some crashes in `mob_functions/ai/lua`, @jordan4ibanez feel free to revert

This commit is contained in:
kay27 2021-04-25 15:37:01 +04:00
parent 073e7b81f8
commit 7c9d9b1650
1 changed files with 20 additions and 14 deletions

View File

@ -171,15 +171,18 @@ local land_state_execution = function(self,dtime)
--make slow falling mobs fall slow --make slow falling mobs fall slow
if self.fall_slow then if self.fall_slow then
if self.object:get_velocity().y < 0 then local velocity = self.object:get_velocity()
--lua is acting really weird so we have to help it if velocity then
if round2(self.object:get_acceleration().y, 1) == -self.gravity then if velocity.y < 0 then
self.object:set_acceleration(vector_new(0,0,0)) --lua is acting really weird so we have to help it
mobs.mob_fall_slow(self) if round2(self.object:get_acceleration().y, 1) == -self.gravity then
end self.object:set_acceleration(vector_new(0,0,0))
else mobs.mob_fall_slow(self)
if round2(self.object:get_acceleration().y, 1) == 0 then end
self.object:set_acceleration(vector_new(0,-self.gravity,0)) else
if round2(self.object:get_acceleration().y, 1) == 0 then
self.object:set_acceleration(vector_new(0,-self.gravity,0))
end
end end
end end
end end
@ -371,8 +374,11 @@ local land_state_execution = function(self,dtime)
if float_now then if float_now then
mobs.float(self) mobs.float(self)
elseif self.object:get_acceleration().y == 0 then else
self.object:set_acceleration(vector_new(0,-self.gravity,0)) local acceleration = self.object:get_acceleration()
if acceleration and acceleration.y == 0 then
self.object:set_acceleration(vector_new(0,-self.gravity,0))
end
end end
end end
@ -894,7 +900,7 @@ mobs.mob_step = function(self, dtime)
pos.y = pos.y + self.eye_height pos.y = pos.y + self.eye_height
local node = minetest.get_node(pos).name local node = minetest_get_node(pos).name
if minetest_get_item_group(node, "water") ~= 0 then if minetest_get_item_group(node, "water") ~= 0 then
self.breath = self.breath - dtime self.breath = self.breath - dtime
@ -1106,7 +1112,7 @@ mobs.mob_step = function(self, dtime)
if not self.ignores_cobwebs then if not self.ignores_cobwebs then
local pos = self.object:get_pos() local pos = self.object:get_pos()
local node = minetest_get_node(pos).name local node = pos and minetest_get_node(pos).name
if node == "mcl_core:cobweb" then if node == "mcl_core:cobweb" then
@ -1131,6 +1137,6 @@ mobs.mob_step = function(self, dtime)
end end
end end
self.old_velocity = self.object:get_velocity() self.old_velocity = self.object:get_velocity()
self.old_pos = self.object:get_pos() self.old_pos = self.object:get_pos()
end end