Merge pull request 'Various mob improvments' (#2791) from various_mob_improvments into master

Reviewed-on: https://git.minetest.land/MineClone2/MineClone2/pulls/2791
Reviewed-by: cora <cora@noreply.git.minetest.land>
This commit is contained in:
cora 2022-10-15 22:52:10 +00:00
commit 678bf661d2
2 changed files with 75 additions and 60 deletions

View File

@ -7,8 +7,8 @@ local HORNY_TIME = 30
local HORNY_AGAIN_TIME = 300 local HORNY_AGAIN_TIME = 300
local CHILD_GROW_TIME = 60*20 local CHILD_GROW_TIME = 60*20
local DEATH_DELAY = 0.5 local DEATH_DELAY = 0.5
local DEFAULT_FALL_SPEED = -10 local DEFAULT_FALL_SPEED = -9.81*1.5
local FLOP_HEIGHT = 5.0 local FLOP_HEIGHT = 6
local FLOP_HOR_SPEED = 1.5 local FLOP_HOR_SPEED = 1.5
local ENTITY_CRAMMING_MAX = 24 local ENTITY_CRAMMING_MAX = 24
local CRAMMING_DAMAGE = 3 local CRAMMING_DAMAGE = 3
@ -187,7 +187,7 @@ local enable_physics = function(object, luaentity, ignore_check)
physical = true physical = true
}) })
object:set_velocity({x=0,y=0,z=0}) object:set_velocity({x=0,y=0,z=0})
object:set_acceleration({x=0,y=-9.81,z=0}) object:set_acceleration({x=0,y=DEFAULT_FALL_SPEED,z=0})
end end
end end
@ -514,9 +514,6 @@ local flight_check = function(self)
for _,checknode in pairs(fly_in) do for _,checknode in pairs(fly_in) do
if nod == checknode then if nod == checknode then
return true return true
elseif checknode == "__airlike" or def.walkable == false and
(def.liquidtype == "none" or minetest.get_item_group(nod, "fake_liquid") == 1) then
return true
end end
end end
@ -556,12 +553,13 @@ 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
@ -686,7 +684,7 @@ local effect = function(pos, amount, texture, min_size, max_size, radius, gravit
radius = radius or 2 radius = radius or 2
min_size = min_size or 0.5 min_size = min_size or 0.5
max_size = max_size or 1 max_size = max_size or 1
gravity = gravity or -10 gravity = gravity or DEFAULT_FALL_SPEED
glow = glow or 0 glow = glow or 0
go_down = go_down or false go_down = go_down or false
@ -909,10 +907,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")
@ -1454,7 +1452,7 @@ local do_jump = function(self)
local v = self.object:get_velocity() local v = self.object:get_velocity()
v.y = self.jump_height + 0.1 v.y = self.jump_height + 0.1 * 3
set_animation(self, "jump") -- only when defined set_animation(self, "jump") -- only when defined
@ -1467,7 +1465,7 @@ local do_jump = function(self)
end end
self.object:set_acceleration({ self.object:set_acceleration({
x = v.x * 2, x = v.x * 2,
y = -10, y = DEFAULT_FALL_SPEED,
z = v.z * 2, z = v.z * 2,
}) })
end, self, v) end, self, v)
@ -1590,7 +1588,7 @@ local breed = function(self)
-- jump when fully grown so as not to fall into ground -- jump when fully grown so as not to fall into ground
self.object:set_velocity({ self.object:set_velocity({
x = 0, x = 0,
y = self.jump_height, y = self.jump_height*3,
z = 0 z = 0
}) })
end end
@ -2384,9 +2382,11 @@ local follow_flop = function(self)
self.state = "flop" self.state = "flop"
self.object:set_acceleration({x = 0, y = DEFAULT_FALL_SPEED, z = 0}) self.object:set_acceleration({x = 0, y = DEFAULT_FALL_SPEED, z = 0})
local sdef = minetest.registered_nodes[self.standing_on] local p = self.object:get_pos()
local sdef = minetest.registered_nodes[node_ok(vector.add(p, vector.new(0,self.collisionbox[2]-0.2,0))).name]
-- Flop on ground -- Flop on ground
if sdef and sdef.walkable then if sdef and sdef.walkable then
if self.object:get_velocity().y < 0.1 then
mob_sound(self, "flop") mob_sound(self, "flop")
self.object:set_velocity({ self.object:set_velocity({
x = random(-FLOP_HOR_SPEED, FLOP_HOR_SPEED), x = random(-FLOP_HOR_SPEED, FLOP_HOR_SPEED),
@ -2394,6 +2394,7 @@ local follow_flop = function(self)
z = random(-FLOP_HOR_SPEED, FLOP_HOR_SPEED), z = random(-FLOP_HOR_SPEED, FLOP_HOR_SPEED),
}) })
end end
end
set_animation(self, "stand", true) set_animation(self, "stand", true)
@ -3232,7 +3233,7 @@ local falling = function(self, pos)
-- apply gravity when moving up -- apply gravity when moving up
self.object:set_acceleration({ self.object:set_acceleration({
x = 0, x = 0,
y = -10, y = DEFAULT_FALL_SPEED,
z = 0 z = 0
}) })
@ -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",