small code cleanups

This commit is contained in:
kno10 2024-09-26 17:32:17 +02:00
parent de60029d1a
commit 9b2d0d1b32
4 changed files with 7 additions and 29 deletions

View File

@ -250,9 +250,7 @@ end
-- set defined animation
function mob_class:set_animation(anim, fixed_frame)
if not self.animation or not anim then
return
end
if not self.animation or not anim then return end
if self.jockey and self.object:get_attach() then
anim = "jockey"
@ -260,11 +258,7 @@ function mob_class:set_animation(anim, fixed_frame)
self.jockey = nil
end
if self.state == "die" and anim ~= "die" and anim ~= "stand" then
return
end
if self.state == "die" and anim ~= "die" and anim ~= "stand" then return end
if self.fly and self:flight_check() and anim == "walk" then anim = "fly" end
@ -279,12 +273,7 @@ function mob_class:set_animation(anim, fixed_frame)
self._current_animation = anim
local a_start = self.animation[anim .. "_start"]
local a_end
if fixed_frame then
a_end = a_start
else
a_end = self.animation[anim .. "_end"]
end
local a_end = fixed_frame and a_start or self.animation[anim .. "_end"]
if a_start and a_end then
self.object:set_animation({
x = a_start,
@ -294,11 +283,6 @@ function mob_class:set_animation(anim, fixed_frame)
end
end
-- above function exported for mount.lua
function mcl_mobs:set_animation(self, anim)
self:set_animation(anim)
end
local function who_are_you_looking_at (self, dtime)
if self.order == "sleep" then
self._locked_object = nil

View File

@ -142,10 +142,10 @@ function mcl_mobs.drive(entity, moving_anim, stand_anim, can_fly, dtime)
-- if not moving then set animation and return
if v == 0 and velo.x == 0 and velo.y == 0 and velo.z == 0 then
if stand_anim then mcl_mobs:set_animation(entity, stand_anim) end
entity:set_animation(stand_anim)
return
else
if moving_anim then mcl_mobs:set_animation(entity, moving_anim) end
entity:set_animation(moving_anim)
end
-- enforce speed limit forward and reverse
@ -254,9 +254,9 @@ function mcl_mobs.fly(entity, dtime, speed, shoots, arrow, moving_anim, stand_an
-- change animation if stopped
if velo.x == 0 and velo.y == 0 and velo.z == 0 then
if stand_anim then mcl_mobs:set_animation(entity, stand_anim) end
entity:set_animation(stand_anim)
else
if moving_anim then mcl_mobs:set_animation(entity, moving_anim) end
entity:set_animation(moving_anim)
end
end

View File

@ -295,11 +295,6 @@ function mob_class:check_smooth_rotation(dtime)
self:update_roll()
end
-- global function to set mob yaw
function mcl_mobs.yaw(self, yaw, delay, dtime)
return mob_class.set_yaw(self, yaw, delay, dtime)
end
-- are we flying in what we are suppose to? (taikedz)
function mob_class:flight_check()

View File

@ -83,7 +83,6 @@ mcl_mobs.register_mob("mobs_mc:shulker", {
local pos = self.object:get_pos()
if math.floor(self.object:get_yaw()) ~=0 then
self.object:set_yaw(0)
mcl_mobs:yaw(self, 0, 0, dtime)
end
if self.state == "attack" then
self:set_animation("run")