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.ai.village.h"
3#include "net.minecraft.world.entity.animal.h"
4#include "DefendVillageTargetGoal.h"
5
6DefendVillageTargetGoal::DefendVillageTargetGoal(VillagerGolem *golem) : TargetGoal(golem, false, true)
7{
8 this->golem = golem;
9 setRequiredControlFlags(TargetGoal::TargetFlag);
10}
11
12bool DefendVillageTargetGoal::canUse()
13{
14 shared_ptr<Village> village = golem->getVillage();
15 if (village == NULL) return false;
16 potentialTarget = weak_ptr<LivingEntity>(village->getClosestAggressor(dynamic_pointer_cast<LivingEntity>(golem->shared_from_this())));
17 shared_ptr<LivingEntity> potTarget = potentialTarget.lock();
18 if (!canAttack(potTarget, false))
19 {
20 // look for bad players
21 if (mob->getRandom()->nextInt(20) == 0)
22 {
23 potentialTarget = village->getClosestBadStandingPlayer(dynamic_pointer_cast<LivingEntity>(golem->shared_from_this() ));
24 return canAttack(potTarget, false);
25 }
26 return false;
27 }
28 else
29 {
30 return true;
31 }
32}
33
34void DefendVillageTargetGoal::start()
35{
36 golem->setTarget(potentialTarget.lock());
37 TargetGoal::start();
38}