Enable mob drowning

This commit is contained in:
jordan4ibanez 2021-04-25 00:06:12 -04:00
parent 56086bf02b
commit 8d3eff0c16
2 changed files with 39 additions and 6 deletions

View File

@ -215,7 +215,7 @@ function mobs:register_mob(name, def)
hp_max = scale_difficulty(def.hp_max, 10, 1), hp_max = scale_difficulty(def.hp_max, 10, 1),
xp_min = def.xp_min or 1, xp_min = def.xp_min or 1,
xp_max = def.xp_max or 5, xp_max = def.xp_max or 5,
breath_max = def.breath_max or 15, breath_max = def.breath_max or 6,
breathes_in_water = def.breathes_in_water or false, breathes_in_water = def.breathes_in_water or false,
physical = true, physical = true,
collisionbox = collisionbox, collisionbox = collisionbox,
@ -361,6 +361,7 @@ function mobs:register_mob(name, def)
burn_timer = 0, burn_timer = 0,
ignores_cobwebs = def.ignores_cobwebs, ignores_cobwebs = def.ignores_cobwebs,
breath = def.breath_max or 6,
--end j4i stuff --end j4i stuff
-- MCL2 extensions -- MCL2 extensions

View File

@ -829,6 +829,42 @@ mobs.mob_step = function(self, dtime)
end end
end 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")
end
self.old_health = self.health
--mobs drowning mechanic
if not self.breathes_in_water then
local pos = self.object:get_pos()
pos.y = pos.y + self.eye_height
local node = minetest.get_node(pos).name
if minetest_get_item_group(node, "water") ~= 0 then
self.breath = self.breath - dtime
--reset breath when drowning
if self.breath <= 0 then
self.health = self.health - 4
self.breath = 1
self.pause_timer = 0.5
end
elseif self.breath < self.breath_max then
self.breath = self.breath + dtime
--clean timer reset
if self.breath > self.breath_max then
self.breath = self.breath_max
end
end
end
--set mobs on fire when burned by sunlight --set mobs on fire when burned by sunlight
if self.ignited_by_sunlight then if self.ignited_by_sunlight then
local pos = self.object:get_pos() local pos = self.object:get_pos()
@ -850,11 +886,7 @@ mobs.mob_step = function(self, dtime)
end end
end 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")
end
self.old_health = self.health
--do death logic (animation, poof, explosion, etc) --do death logic (animation, poof, explosion, etc)
if self.health <= 0 then if self.health <= 0 then