fix(goal): add a duration to panics

This commit is contained in:
Sally Knight 2026-03-28 02:18:23 +03:00
parent 7db2fe0318
commit 23ab4de9ac

View file

@ -14,6 +14,14 @@ PanicGoal::PanicGoal(PathfinderMob* mob, double speedModifier) {
bool PanicGoal::canUse() {
if (mob->getLastHurtByMob() == NULL && !mob->isOnFire()) return false;
// 4jcraft: stop entities from being eternally scared (referenced from
// smartcmd/MinecraftConsoles #519)
const int hurtTimeout = mob->getLastHurtByMobTimestamp();
static thread_local Random random;
const int panicDuration = random.nextInt(41) + 60;
if (mob->tickCount - hurtTimeout > panicDuration) return false;
Vec3* pos = RandomPos::getPos(
std::dynamic_pointer_cast<PathfinderMob>(mob->shared_from_this()), 5,
4);