Fix animals stuck in panic state #514 (#519)

This commit is contained in:
ModMaker101
2026-03-05 02:23:56 -05:00
committed by GitHub
parent 981c87732c
commit 91e50aa346
2 changed files with 13 additions and 4 deletions

View File

@@ -10,17 +10,24 @@ PanicGoal::PanicGoal(PathfinderMob *mob, double speedModifier)
{
this->mob = mob;
this->speedModifier = speedModifier;
setRequiredControlFlags(Control::MoveControlFlag);
Goal::setRequiredControlFlags(Control::MoveControlFlag);
}
bool PanicGoal::canUse()
{
if (mob->getLastHurtByMob() == NULL && !mob->isOnFire()) return false;
Vec3 *pos = RandomPos::getPos(dynamic_pointer_cast<PathfinderMob>(mob->shared_from_this()), 5, 4);
if (pos == NULL) return false;
if (mob->getLastHurtByMob() == nullptr && !mob->isOnFire()) return false;
const int hurtTimeout = mob->getLastHurtByMobTimestamp();
if (hurtTimeout == 0) return false;
static thread_local std::mt19937 rng(std::random_device{}());
std::uniform_int_distribution<int> dist(60, 100);
const int panicDuration = dist(rng);
if (mob->tickCount - hurtTimeout > panicDuration) return false;
const Vec3* pos = RandomPos::getPos(dynamic_pointer_cast<PathfinderMob>(mob->shared_from_this()), 5, 4);
if (pos == nullptr) return false;
posX = pos->x;
posY = pos->y;
posZ = pos->z;
return true;
}
@@ -31,5 +38,6 @@ void PanicGoal::start()
bool PanicGoal::canContinueToUse()
{
if (mob->getLastHurtByMob() == nullptr && !mob->isOnFire()) return false;
return !mob->getNavigation()->isDone();
}

View File

@@ -1,6 +1,7 @@
#pragma once
#include "Goal.h"
#include <random>
class PathfinderMob;