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.control.h"
3#include "net.minecraft.world.entity.ai.navigation.h"
4#include "net.minecraft.world.entity.h"
5#include "net.minecraft.world.entity.animal.h"
6#include "net.minecraft.world.phys.h"
7#include "OcelotAttackGoal.h"
8
9OcelotAttackGoal::OcelotAttackGoal(Mob *mob)
10{
11 target = weak_ptr<LivingEntity>();
12 attackTime = 0;
13 speed = 0;
14 trackTarget = false;
15
16 this->mob = mob;
17 this->level = mob->level;
18 setRequiredControlFlags(Control::MoveControlFlag | Control::LookControlFlag);
19}
20
21bool OcelotAttackGoal::canUse()
22{
23 shared_ptr<LivingEntity> bestTarget = mob->getTarget();
24 if (bestTarget == NULL) return false;
25 target = weak_ptr<LivingEntity>(bestTarget);
26 return true;
27}
28
29bool OcelotAttackGoal::canContinueToUse()
30{
31 if (target.lock() == NULL || !target.lock()->isAlive()) return false;
32 if (mob->distanceToSqr(target.lock()) > 15 * 15) return false;
33 return !mob->getNavigation()->isDone() || canUse();
34}
35
36void OcelotAttackGoal::stop()
37{
38 target = weak_ptr<Mob>();
39 mob->getNavigation()->stop();
40}
41
42void OcelotAttackGoal::tick()
43{
44 mob->getLookControl()->setLookAt(target.lock(), 30, 30);
45
46 double meleeRadiusSqr = (mob->bbWidth * 2) * (mob->bbWidth * 2);
47 double distSqr = mob->distanceToSqr(target.lock()->x, target.lock()->bb->y0, target.lock()->z);
48
49 double speedModifier = Ocelot::WALK_SPEED_MOD;
50 if (distSqr > meleeRadiusSqr && distSqr < 4 * 4) speedModifier = Ocelot::SPRINT_SPEED_MOD;
51 else if (distSqr < 15 * 15) speedModifier = Ocelot::SNEAK_SPEED_MOD;
52
53 mob->getNavigation()->moveTo(target.lock(), speedModifier);
54
55 attackTime = max(attackTime - 1, 0);
56
57 if (distSqr > meleeRadiusSqr) return;
58 if (attackTime > 0) return;
59 attackTime = 20;
60 mob->doHurtTarget(target.lock());
61}