diff --git a/mods/ENTITIES/mcl_mobs/api/api.lua b/mods/ENTITIES/mcl_mobs/api/api.lua index 81c88a0641..d1e5a081ce 100644 --- a/mods/ENTITIES/mcl_mobs/api/api.lua +++ b/mods/ENTITIES/mcl_mobs/api/api.lua @@ -328,6 +328,9 @@ function mobs:register_mob(name, def) minimum_follow_distance = def.minimum_follow_distance or 0.5, --make mobs not freak out when underneath + memory = 0, -- memory timer if chasing/following + fly_random_while_attack = def.fly_random_while_attack, + --for spiders always_climb = def.always_climb, diff --git a/mods/ENTITIES/mcl_mobs/api/mob_functions/ai.lua b/mods/ENTITIES/mcl_mobs/api/mob_functions/ai.lua index ee7ca0ecc4..0fe18c3f20 100644 --- a/mods/ENTITIES/mcl_mobs/api/mob_functions/ai.lua +++ b/mods/ENTITIES/mcl_mobs/api/mob_functions/ai.lua @@ -481,7 +481,7 @@ local swim_state_execution = function(self,dtime) self.yaw = (math_random() * (math.pi * 2)) --create a truly random pitch, since there is no easy access to pitch math that I can find - self.pitch = math_random() * random_pitch_multiplier[math_random(1,2)] + self.pitch = math_random() * math.random(1,3) * random_pitch_multiplier[math_random(1,2)] end --do animation @@ -626,7 +626,7 @@ local fly_state_execution = function(self,dtime) self.yaw = (math_random() * (math.pi * 2)) --create a truly random pitch, since there is no easy access to pitch math that I can find - self.pitch = math_random() * random_pitch_multiplier[math_random(1,2)] + self.pitch = math_random() * math.random(1,3) * random_pitch_multiplier[math_random(1,2)] end --do animation @@ -899,23 +899,41 @@ mobs.mob_step = function(self, dtime) --go get the closest player if attacking then + self.memory = 6 --6 seconds of memory + --set initial punch timer if self.attacking == nil then if self.attack_type == "punch" then self.punch_timer = -1 end end - self.attacking = attacking - --no player in area - else - --reset states when coming out of hostile state - if self.attacking ~= nil then - self.state_timer = -1 + --no player in area + elseif self.memory > 0 then + --try to remember + self.memory = self.memory - dtime + --get if memory player is within viewing range + if self.attacking and self.attacking:is_player() then + local distance = vector_distance(self.object:get_pos(), self.attacking:get_pos()) + if distance > self.view_range then + self.memory = 0 + end + --out of viewing range, forget em + else + self.memory = 0 end - self.attacking = nil + if self.memory <= 0 then + + --reset states when coming out of hostile state + if self.attacking ~= nil then + self.state_timer = -1 + end + + self.attacking = nil + self.memory = 0 + end end end diff --git a/mods/ENTITIES/mcl_mobs/api/mob_functions/attack_type_instructions.lua b/mods/ENTITIES/mcl_mobs/api/mob_functions/attack_type_instructions.lua index 20de36c409..0df4a42f9b 100644 --- a/mods/ENTITIES/mcl_mobs/api/mob_functions/attack_type_instructions.lua +++ b/mods/ENTITIES/mcl_mobs/api/mob_functions/attack_type_instructions.lua @@ -279,6 +279,8 @@ ______ _ _ _ _ |__/ ]]-- +local random_pitch_multiplier = {-1,1} + mobs.projectile_attack_fly = function(self, dtime) --this needs an exception @@ -287,18 +289,41 @@ mobs.projectile_attack_fly = function(self, dtime) return end - local distance_from_attacking = vector_distance(self.object:get_pos(), self.attacking:get_pos()) + --this is specifically for random ghast movement + if self.fly_random_while_attack then + + --enable rotation locking + mobs.movement_rotation_lock(self) + + self.walk_timer = self.walk_timer - dtime + + --reset the walk timer + if self.walk_timer <= 0 then + --re-randomize the walk timer + self.walk_timer = math.random(1,6) + math.random() + --set the mob into a random direction + self.yaw = (math_random() * (math.pi * 2)) + --create a truly random pitch, since there is no easy access to pitch math that I can find + self.pitch = math_random() * math.random(1,3) * random_pitch_multiplier[math_random(1,2)] + end - if distance_from_attacking >= self.reach then - mobs.set_yaw_while_attacking(self) - mobs.set_pitch_while_attacking(self) mobs.set_fly_velocity(self, self.run_velocity) - mobs.set_mob_animation(self,"run") + else + mobs.set_yaw_while_attacking(self) - mobs.set_pitch_while_attacking(self) - mobs.set_fly_velocity(self, 0) - mobs.set_mob_animation(self,"stand") + + local distance_from_attacking = vector_distance(self.object:get_pos(), self.attacking:get_pos()) + + if distance_from_attacking >= self.reach then + mobs.set_pitch_while_attacking(self) + mobs.set_fly_velocity(self, self.run_velocity) + mobs.set_mob_animation(self,"run") + else + mobs.set_pitch_while_attacking(self) + mobs.set_fly_velocity(self, 0) + mobs.set_mob_animation(self,"stand") + end end @@ -313,6 +338,11 @@ mobs.projectile_attack_fly = function(self, dtime) --shoot if self.projectile_timer <= 0 then + + if self.fly_random_while_attack then + mobs.set_yaw_while_attacking(self) + self.walk_timer = 0 + end --reset timer self.projectile_timer = math_random(self.projectile_cooldown_min, self.projectile_cooldown_max) mobs.shoot_projectile(self) diff --git a/mods/ENTITIES/mobs_mc/ghast.lua b/mods/ENTITIES/mobs_mc/ghast.lua index c1434f2010..7fa8f7da87 100644 --- a/mods/ENTITIES/mobs_mc/ghast.lua +++ b/mods/ENTITIES/mobs_mc/ghast.lua @@ -15,6 +15,7 @@ mobs:register_mob("mobs_mc:ghast", { spawn_class = "hostile", group_attack = true, hostile = true, + fly_random_while_attack = true, hp_min = 10, hp_max = 10, rotate = 270,