the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
1#include "stdafx.h"
2#include "net.minecraft.world.entity.h"
3#include "net.minecraft.world.phys.h"
4#include "net.minecraft.world.level.h"
5#include "HurtByTargetGoal.h"
6
7HurtByTargetGoal::HurtByTargetGoal(PathfinderMob *mob, bool alertSameType) : TargetGoal(mob, false)
8{
9 this->alertSameType = alertSameType;
10 setRequiredControlFlags(TargetGoal::TargetFlag);
11 timestamp = 0;
12}
13
14bool HurtByTargetGoal::canUse()
15{
16 int ts = mob->getLastHurtByMobTimestamp();
17 return ts != timestamp && canAttack(mob->getLastHurtByMob(), false);
18}
19
20void HurtByTargetGoal::start()
21{
22 mob->setTarget(mob->getLastHurtByMob());
23 timestamp = mob->getLastHurtByMobTimestamp();
24
25 if (alertSameType)
26 {
27 double within = getFollowDistance();
28 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));
29 for(AUTO_VAR(it, nearby->begin()); it != nearby->end(); ++it)
30 {
31 shared_ptr<PathfinderMob> other = dynamic_pointer_cast<PathfinderMob>(*it);
32 if (this->mob->shared_from_this() == other) continue;
33 if (other->getTarget() != NULL) continue;
34 if (other->isAlliedTo(mob->getLastHurtByMob())) continue; // don't target allies
35 other->setTarget(mob->getLastHurtByMob());
36 }
37 delete nearby;
38 }
39
40 TargetGoal::start();
41}