From 8d3eff0c16abeff9fbce2f9d4af2b64931765696 Mon Sep 17 00:00:00 2001 From: jordan4ibanez Date: Sun, 25 Apr 2021 00:06:12 -0400 Subject: [PATCH] Enable mob drowning --- mods/ENTITIES/mcl_mobs/api/api.lua | 3 +- .../mcl_mobs/api/mob_functions/ai.lua | 42 ++++++++++++++++--- 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/api/api.lua b/mods/ENTITIES/mcl_mobs/api/api.lua index f1497c4741..9f4ec17875 100644 --- a/mods/ENTITIES/mcl_mobs/api/api.lua +++ b/mods/ENTITIES/mcl_mobs/api/api.lua @@ -215,7 +215,7 @@ function mobs:register_mob(name, def) hp_max = scale_difficulty(def.hp_max, 10, 1), xp_min = def.xp_min or 1, 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, physical = true, collisionbox = collisionbox, @@ -361,6 +361,7 @@ function mobs:register_mob(name, def) burn_timer = 0, ignores_cobwebs = def.ignores_cobwebs, + breath = def.breath_max or 6, --end j4i stuff -- MCL2 extensions diff --git a/mods/ENTITIES/mcl_mobs/api/mob_functions/ai.lua b/mods/ENTITIES/mcl_mobs/api/mob_functions/ai.lua index b79eaf665d..5d619a7d33 100644 --- a/mods/ENTITIES/mcl_mobs/api/mob_functions/ai.lua +++ b/mods/ENTITIES/mcl_mobs/api/mob_functions/ai.lua @@ -829,6 +829,42 @@ mobs.mob_step = function(self, dtime) 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 if self.ignited_by_sunlight then local pos = self.object:get_pos() @@ -850,11 +886,7 @@ mobs.mob_step = function(self, dtime) 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) if self.health <= 0 then