Files
MinecraftConsoles/Minecraft.World/HurtByTargetGoal.cpp
ModMaker101 a9be52c41a Project modernization (#630)
* Fixed boats falling and a TP glitch #266

* Replaced every C-style cast with C++ ones

* Replaced every C-style cast with C++ ones

* Fixed boats falling and a TP glitch #266

* Updated NULL to nullptr and fixing some type issues

* Modernized and fixed a few bugs

- Replaced most instances of `NULL` with `nullptr`.
- Replaced most `shared_ptr(new ...)` with `make_shared`.
- Removed the `nullptr` macro as it was interfering with the actual nullptr keyword in some instances.

* Fixing more conflicts

* Replace int loops with size_t and start work on overrides
2026-03-08 09:56:03 +07:00

41 lines
1.3 KiB
C++

#include "stdafx.h"
#include "net.minecraft.world.entity.h"
#include "net.minecraft.world.phys.h"
#include "net.minecraft.world.level.h"
#include "HurtByTargetGoal.h"
HurtByTargetGoal::HurtByTargetGoal(PathfinderMob *mob, bool alertSameType) : TargetGoal(mob, false)
{
this->alertSameType = alertSameType;
setRequiredControlFlags(TargetGoal::TargetFlag);
timestamp = 0;
}
bool HurtByTargetGoal::canUse()
{
int ts = mob->getLastHurtByMobTimestamp();
return ts != timestamp && canAttack(mob->getLastHurtByMob(), false);
}
void HurtByTargetGoal::start()
{
mob->setTarget(mob->getLastHurtByMob());
timestamp = mob->getLastHurtByMobTimestamp();
if (alertSameType)
{
double within = getFollowDistance();
vector<shared_ptr<Entity> > *nearby = mob->level->getEntitiesOfClass(typeid(*mob), AABB::newTemp(mob->x, mob->y, mob->z, mob->x + 1, mob->y + 1, mob->z + 1)->grow(within, 4, within));
for(auto& it : *nearby)
{
shared_ptr<PathfinderMob> other = dynamic_pointer_cast<PathfinderMob>(it);
if (this->mob->shared_from_this() == other) continue;
if (other->getTarget() != nullptr) continue;
if (other->isAlliedTo(mob->getLastHurtByMob())) continue; // don't target allies
other->setTarget(mob->getLastHurtByMob());
}
delete nearby;
}
TargetGoal::start();
}