From 5062d56a5d89346234f6125848799f32915b31a4 Mon Sep 17 00:00:00 2001 From: jordan4ibanez Date: Wed, 21 Apr 2021 11:00:02 -0400 Subject: [PATCH] Implement neutral mob mechanics and partial implement of zombie pigmen --- mods/ENTITIES/mcl_mobs/api/api.lua | 1 + mods/ENTITIES/mcl_mobs/api/mob_functions/ai.lua | 14 +++++++++++++- .../mcl_mobs/api/mob_functions/interaction.lua | 2 +- mods/ENTITIES/mobs_mc/creeper.lua | 1 - mods/ENTITIES/mobs_mc/zombiepig.lua | 1 + 5 files changed, 16 insertions(+), 3 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/api/api.lua b/mods/ENTITIES/mcl_mobs/api/api.lua index bafad3651..37676f476 100644 --- a/mods/ENTITIES/mcl_mobs/api/api.lua +++ b/mods/ENTITIES/mcl_mobs/api/api.lua @@ -347,6 +347,7 @@ function mobs:register_mob(name, def) ignited_by_sunlight = def.ignited_by_sunlight or false, eye_height = def.eye_height or 1.5, defuse_reach = def.defuse_reach or 4, + hostile_cooldown = def.hostile_cooldown or 15, -- End of MCL2 extensions on_spawn = def.on_spawn, diff --git a/mods/ENTITIES/mcl_mobs/api/mob_functions/ai.lua b/mods/ENTITIES/mcl_mobs/api/mob_functions/ai.lua index 8dbe49a97..f735576ce 100644 --- a/mods/ENTITIES/mcl_mobs/api/mob_functions/ai.lua +++ b/mods/ENTITIES/mcl_mobs/api/mob_functions/ai.lua @@ -571,10 +571,11 @@ mobs.mob_step = function(self, dtime) return false end + local attacking = nil if self.hostile then --true for line_of_sight is debug - local attacking = mobs.detect_closest_player_within_radius(self,true,self.view_range,self.eye_height) + attacking = mobs.detect_closest_player_within_radius(self,true,self.view_range,self.eye_height) --go get the closest player ROAR >:O if attacking then @@ -599,6 +600,17 @@ mobs.mob_step = function(self, dtime) end end + --count down hostile cooldown timer when no players in range + if self.neutral and self.hostile and not attacking and self.hostile_cooldown_timer then + + self.hostile_cooldown_timer = self.hostile_cooldown_timer - dtime + + if self.hostile_cooldown_timer <= 0 then + self.hostile = false + self.hostile_cooldown_timer = 0 + end + end + --jump only (like slimes) if self.jump_only then diff --git a/mods/ENTITIES/mcl_mobs/api/mob_functions/interaction.lua b/mods/ENTITIES/mcl_mobs/api/mob_functions/interaction.lua index 17a48e931..ed87710b7 100644 --- a/mods/ENTITIES/mcl_mobs/api/mob_functions/interaction.lua +++ b/mods/ENTITIES/mcl_mobs/api/mob_functions/interaction.lua @@ -47,7 +47,7 @@ mobs.mob_punch = function(self, hitter, tflp, tool_capabilities, dir) if self.neutral then self.hostile = true --hostile_cooldown timer is initialized here - self.hostile_cooldown_timer + self.hostile_cooldown_timer = self.hostile_cooldown end diff --git a/mods/ENTITIES/mobs_mc/creeper.lua b/mods/ENTITIES/mobs_mc/creeper.lua index 559f2e703..b94a61dea 100644 --- a/mods/ENTITIES/mobs_mc/creeper.lua +++ b/mods/ENTITIES/mobs_mc/creeper.lua @@ -13,7 +13,6 @@ mobs:register_mob("mobs_mc:creeper", { type = "monster", spawn_class = "hostile", hostile = true, - neutral = false, rotate = 270, hp_min = 20, hp_max = 20, diff --git a/mods/ENTITIES/mobs_mc/zombiepig.lua b/mods/ENTITIES/mobs_mc/zombiepig.lua index 4777cd7cb..af1da2962 100644 --- a/mods/ENTITIES/mobs_mc/zombiepig.lua +++ b/mods/ENTITIES/mobs_mc/zombiepig.lua @@ -17,6 +17,7 @@ local pigman = { neutral = true, rotate = 270, spawn_class = "passive", + hostile_cooldown = 15, --seconds hp_min = 20, hp_max = 20, xp_min = 6,