Add in random sounds/hurt/death sounds and stop mobs from reviving on server restart again

This commit is contained in:
jordan4ibanez 2021-04-25 01:14:48 -04:00
parent 0a380265c8
commit 7733e05a12
10 changed files with 53 additions and 12 deletions

View File

@ -264,7 +264,6 @@ function mobs:register_mob(name, def)
tamed = false,
pause_timer = 0,
gotten = false,
health = 0,
reach = def.reach or 3,
htimer = 0,
texture_list = def.textures,
@ -362,6 +361,10 @@ function mobs:register_mob(name, def)
ignores_cobwebs = def.ignores_cobwebs,
breath = def.breath_max or 6,
--random_sound_timer = 0,
random_sound_timer_min = 3,
random_sound_timer_max = 10,
--end j4i stuff
-- MCL2 extensions

View File

@ -829,9 +829,18 @@ mobs.mob_step = function(self, dtime)
end
end
--do death logic (animation, poof, explosion, etc)
if self.health <= 0 then
--color modifier which coincides with the pause_timer
if self.old_health and self.health < self.old_health then
self.object:set_texture_mod("^[colorize:red:120")
--fix double death sound
if self.health > 0 then
mobs.play_sound(self,"damage")
end
end
self.old_health = self.health
--do death logic (animation, poof, explosion, etc)
if self.health <= 0 or self.dead then
--play death sound once
if not self.played_death_sound then
self.dead = true
@ -855,12 +864,9 @@ mobs.mob_step = function(self, dtime)
return
end
--color modifier which coincides with the pause_timer
if self.old_health and self.health < self.old_health then
self.object:set_texture_mod("^[colorize:red:120")
mobs.play_sound(self,"damage")
end
self.old_health = self.health
mobs.random_sound_handling(self,dtime)
--mobs drowning mechanic

View File

@ -137,10 +137,17 @@ mobs.mob_activate = function(self, staticdata, def, dtime)
}
end
if not self.dead and self.health == 0 then
--stop mobs from reviving
if not self.dead and not self.health then
self.health = math_random (self.hp_min, self.hp_max)
end
if not self.random_sound_timer then
self.random_sound_timer = math_random(self.random_sound_timer_min,self.random_sound_timer_max)
end
if self.breath == nil then
self.breath = self.breath_max
end
@ -178,13 +185,21 @@ mobs.mob_activate = function(self, staticdata, def, dtime)
self.opinion_sound_cooloff = 0 -- used to prevent sound spam of particular sound types
self.texture_mods = {}
self.object:set_texture_mod("")
self.v_start = false
self.timer = 0
self.blinktimer = 0
self.blinkstatus = false
--continue mob effect on server restart
if self.dead or self.health <= 0 then
self.object:set_texture_mod("^[colorize:red:120")
else
self.object:set_texture_mod("")
end
-- check existing nametag
if not self.nametag then
self.nametag = def.nametag

View File

@ -22,11 +22,26 @@ end
--generic sound handler for mobs
mobs.play_sound_handler = function(self, sound)
local pitch = (100 + math_random(-15,15) + math_random()) / 100
local distance = self.sounds.distance or 16
minetest.sound_play(sound, {
object = self.object,
gain = 1.0,
max_hear_distance = self.sounds.distance,
max_hear_distance = distance,
pitch = pitch,
}, true)
end
--random sound timing handler
mobs.random_sound_handling = function(self,dtime)
self.random_sound_timer = self.random_sound_timer - dtime
--play sound and reset timer
if self.random_sound_timer <= 0 then
mobs.play_sound(self,"random")
self.random_sound_timer = math_random(self.random_sound_timer_min,self.random_sound_timer_max)
end
end

View File

@ -971,6 +971,8 @@ mobs:register_mob("mobs_mc:villager", {
-- TODO: sounds
sounds = {
random = "mobs_mc_villager",
damage = "mobs_mc_villager_hurt",
death = "mobs_mc_villager_hurt",
distance = 10,
},
animation = {