1
0
Fork 0

various mob improvments

This commit is contained in:
epCode 2022-10-15 11:25:26 -07:00
parent 210496b615
commit 22e6731261
2 changed files with 57 additions and 42 deletions

View File

@ -556,13 +556,14 @@ local set_animation = function(self, anim, fixed_frame)
else else
a_end = self.animation[anim .. "_end"] a_end = self.animation[anim .. "_end"]
end end
if a_start and a_end then
self.object:set_animation({ self.object:set_animation({
x = a_start, x = a_start,
y = a_end}, y = a_end},
self.animation[anim .. "_speed"] or self.animation.speed_normal or 15, self.animation[anim .. "_speed"] or self.animation.speed_normal or 15,
0, self.animation[anim .. "_loop"] ~= false) 0, self.animation[anim .. "_loop"] ~= false)
end end
end
-- above function exported for mount.lua -- above function exported for mount.lua
@ -909,10 +910,10 @@ local check_for_death = function(self, cause, cmi_cause)
-- play damage sound if health was reduced and make mob flash red. -- play damage sound if health was reduced and make mob flash red.
if damaged then if damaged then
add_texture_mod(self, "^[colorize:red:130") add_texture_mod(self, "^[colorize:#d42222:175")
minetest.after(.2, function(self) minetest.after(1, function(self)
if self and self.object then if self and self.object then
remove_texture_mod(self, "^[colorize:red:130") remove_texture_mod(self, "^[colorize:#d42222:175")
end end
end, self) end, self)
mob_sound(self, "damage") mob_sound(self, "damage")
@ -3453,23 +3454,26 @@ local mob_punch = function(self, hitter, tflp, tool_capabilities, dir)
end end
end end
-- knock back effect (only on full punch) -- knock back effect (only on full punch)
if not die if self.knock_back
and self.knock_back
and tflp >= punch_interval then and tflp >= punch_interval then
-- direction error check
dir = dir or {x = 0, y = 0, z = 0}
local v = self.object:get_velocity() local v = self.object:get_velocity()
local r = 1.4 - min(punch_interval, 1.4) local r = 1.4 - min(punch_interval, 1.4)
local kb = r * 2.0 local kb = r * (abs(v.x)+abs(v.z))
local up = 2 local up = 2
if die==true then
kb=kb*2
end
-- if already in air then dont go up anymore when hit -- if already in air then dont go up anymore when hit
if v.y ~= 0 if abs(v.y) > 0.1
or self.fly then or self.fly then
up = 0 up = 0
end end
-- direction error check
dir = dir or {x = 0, y = 0, z = 0}
-- check if tool already has specific knockback value -- check if tool already has specific knockback value
if tool_capabilities.damage_groups["knockback"] then if tool_capabilities.damage_groups["knockback"] then
@ -3490,16 +3494,22 @@ local mob_punch = function(self, hitter, tflp, tool_capabilities, dir)
kb = kb + luaentity._knockback kb = kb + luaentity._knockback
end end
--self._kb_turn = false --self._kb_turn = false
self._turn_to=self.object:get_yaw()+0.85 self._turn_to=self.object:get_yaw()+1.57
self.frame_speed_multiplier=2.3
if self.animation.run_end then
set_animation(self, "run")
elseif self.animation.walk_end then
set_animation(self, "walk")
end
minetest.after(0.2, function() minetest.after(0.2, function()
if self and self.object then if self and self.object then
self.frame_speed_multiplier=1
self._kb_turn = true self._kb_turn = true
end end
end) end)
self.object:add_velocity({
self.object:set_velocity({
x = dir.x * kb, x = dir.x * kb,
y = dir.y * kb + up * 2, y = up*2,
z = dir.z * kb z = dir.z * kb
}) })
@ -3510,21 +3520,13 @@ local mob_punch = function(self, hitter, tflp, tool_capabilities, dir)
-- if skittish then run away -- if skittish then run away
if not die and self.runaway == true and self.state ~= "flop" then if not die and self.runaway == true and self.state ~= "flop" then
local lp = hitter:get_pos() yaw = set_yaw(self, minetest.dir_to_yaw(vector.direction(hitter:get_pos(), self.object:get_pos())))
local s = self.object:get_pos() minetest.after(0.2,function()
local vec = { if self and self.object then
x = lp.x - s.x, yaw = set_yaw(self, minetest.dir_to_yaw(vector.direction(hitter:get_pos(), self.object:get_pos())))
y = lp.y - s.y, set_velocity(self, self.run_velocity)
z = lp.z - s.z
}
local yaw = (atan(vec.z / vec.x) + 3 * pi / 2) - self.rotate
if lp.x > s.x then
yaw = yaw + pi
end end
end)
yaw = set_yaw(self, yaw, 6)
self.state = "runaway" self.state = "runaway"
self.runaway_timer = 0 self.runaway_timer = 0
self.following = nil self.following = nil
@ -3854,12 +3856,22 @@ local mob_step = function(self, dtime)
end end
end end
if self.state and self.state=="die" or check_for_death(self) then local v = self.object:get_velocity()
local d = 0.85
if self.state and self.state=="die" or check_for_death(self) and not self.animation.die_end then
d = 0.92
local rot = self.object:get_rotation() local rot = self.object:get_rotation()
rot.z = ((pi/2-rot.z)*.2)+rot.z rot.z = ((pi/2-rot.z)*.2)+rot.z
self.object:set_rotation(rot) self.object:set_rotation(rot)
end end
if v then
--diffuse object velocity
self.object:set_velocity({x = v.x*d, y = v.y, z = v.z*d})
end
if not player_in_active_range(self) then if not player_in_active_range(self) then
set_animation(self, "stand", true) set_animation(self, "stand", true)
self.object:set_velocity(vector.new(0,0,0)) self.object:set_velocity(vector.new(0,0,0))
@ -3901,12 +3913,13 @@ local mob_step = function(self, dtime)
--set animation speed relitive to velocity --set animation speed relitive to velocity
local v = self.object:get_velocity() local v = self.object:get_velocity()
if v then if v then
if self.frame_speed_multiplier then
local v2 = abs(v.x)+abs(v.z)*.833 local v2 = abs(v.x)+abs(v.z)*.833
self.object:set_animation_frame_speed((v2/self.walk_velocity)*25) if not self.animation.walk_speed then
self.animation.walk_speed = 25
end
--diffuse object velocity self.object:set_animation_frame_speed((v2/self.walk_velocity)*self.animation.walk_speed*self.frame_speed_multiplier)
self.object:set_velocity({x = v.x*.85, y = v.y, z = v.z*.85}) end
--set_speed --set_speed
if self.acc then if self.acc then
@ -4299,7 +4312,7 @@ minetest.register_entity(name, {
arrow = def.arrow, arrow = def.arrow,
shoot_interval = def.shoot_interval, shoot_interval = def.shoot_interval,
sounds = def.sounds or {}, sounds = def.sounds or {},
animation = def.animation, animation = def.animation or {},
follow = def.follow, follow = def.follow,
nofollow = def.nofollow, nofollow = def.nofollow,
can_open_doors = def.can_open_doors, can_open_doors = def.can_open_doors,
@ -4325,6 +4338,7 @@ minetest.register_entity(name, {
hornytimer = 0, hornytimer = 0,
gotten = false, gotten = false,
health = 0, health = 0,
frame_speed_multiplier = 1,
reach = def.reach or 3, reach = def.reach or 3,
htimer = 0, htimer = 0,
texture_list = def.textures, texture_list = def.textures,

View File

@ -1239,6 +1239,7 @@ mcl_mobs:register_mob("mobs_mc:villager", {
bone_eye_height = 6.3, bone_eye_height = 6.3,
head_eye_height = 2.2, head_eye_height = 2.2,
curiosity = 10, curiosity = 10,
runaway = true,
collisionbox = {-0.3, -0.01, -0.3, 0.3, 1.94, 0.3}, collisionbox = {-0.3, -0.01, -0.3, 0.3, 1.94, 0.3},
visual = "mesh", visual = "mesh",
mesh = "mobs_mc_villager.b3d", mesh = "mobs_mc_villager.b3d",