mirror of
https://github.com/4jcraft/4jcraft.git
synced 2026-04-25 08:43:59 +00:00
40 lines
1.4 KiB
C++
40 lines
1.4 KiB
C++
#include "../../Platform/stdafx.h"
|
|
#include "../../Headers/net.minecraft.world.entity.ai.control.h"
|
|
#include "../../Headers/net.minecraft.world.entity.ai.navigation.h"
|
|
#include "../../Headers/net.minecraft.world.entity.ai.util.h"
|
|
#include "../../Headers/net.minecraft.world.entity.h"
|
|
#include "../../Headers/net.minecraft.world.phys.h"
|
|
#include "PanicGoal.h"
|
|
|
|
PanicGoal::PanicGoal(PathfinderMob* mob, double speedModifier) {
|
|
this->mob = mob;
|
|
this->speedModifier = speedModifier;
|
|
setRequiredControlFlags(Control::MoveControlFlag);
|
|
}
|
|
|
|
bool PanicGoal::canUse() {
|
|
if (mob->getLastHurtByMob() == nullptr && !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;
|
|
|
|
auto pos = RandomPos::getPos(
|
|
std::dynamic_pointer_cast<PathfinderMob>(mob->shared_from_this()), 5,
|
|
4);
|
|
if (!pos.has_value()) return false;
|
|
posX = pos->x;
|
|
posY = pos->y;
|
|
posZ = pos->z;
|
|
return true;
|
|
}
|
|
|
|
void PanicGoal::start() {
|
|
mob->getNavigation()->moveTo(posX, posY, posZ, speedModifier);
|
|
}
|
|
|
|
bool PanicGoal::canContinueToUse() { return !mob->getNavigation()->isDone(); }
|