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.util.h"
4#include "net.minecraft.world.entity.ai.navigation.h"
5#include "net.minecraft.world.entity.npc.h"
6#include "net.minecraft.world.entity.h"
7#include "net.minecraft.world.level.h"
8#include "net.minecraft.world.phys.h"
9#include "BasicTypeContainers.h"
10#include "PlayGoal.h"
11
12PlayGoal::PlayGoal(Villager *mob, double speedModifier)
13{
14 followFriend = weak_ptr<LivingEntity>();
15 wantedX = wantedY = wantedZ = 0.0;
16 playTime = 0;
17
18 this->mob = mob;
19 this->speedModifier = speedModifier;
20 setRequiredControlFlags(Control::MoveControlFlag);
21}
22
23bool PlayGoal::canUse()
24{
25 if (mob->getAge() >= 0) return false;
26 if (mob->getRandom()->nextInt(400) != 0) return false;
27
28 vector<shared_ptr<Entity> > *children = mob->level->getEntitiesOfClass(typeid(Villager), mob->bb->grow(6, 3, 6));
29 double closestDistSqr = Double::MAX_VALUE;
30 //for (Entity c : children)
31 for(AUTO_VAR(it, children->begin()); it != children->end(); ++it)
32 {
33 shared_ptr<Entity> c = *it;
34 if (c.get() == mob) continue;
35 shared_ptr<Villager> friendV = dynamic_pointer_cast<Villager>(c);
36 if (friendV->isChasing()) continue;
37 if (friendV->getAge() >= 0) continue;
38 double distSqr = friendV->distanceToSqr(mob->shared_from_this());
39 if (distSqr > closestDistSqr) continue;
40 closestDistSqr = distSqr;
41 followFriend = weak_ptr<LivingEntity>(friendV);
42 }
43 delete children;
44
45 if (followFriend.lock() == NULL)
46 {
47 Vec3 *pos = RandomPos::getPos(dynamic_pointer_cast<PathfinderMob>(mob->shared_from_this()), 16, 3);
48 if (pos == NULL) return false;
49 }
50 return true;
51}
52
53bool PlayGoal::canContinueToUse()
54{
55 return playTime > 0 && followFriend.lock() != NULL;
56}
57
58void PlayGoal::start()
59{
60 if (followFriend.lock() != NULL) mob->setChasing(true);
61 playTime = 1000;
62}
63
64void PlayGoal::stop()
65{
66 mob->setChasing(false);
67 followFriend = weak_ptr<LivingEntity>();
68}
69
70void PlayGoal::tick()
71{
72 --playTime;
73 if (followFriend.lock() != NULL)
74 {
75 if (mob->distanceToSqr(followFriend.lock()) > 2 * 2) mob->getNavigation()->moveTo(followFriend.lock(), speedModifier);
76 }
77 else
78 {
79 if (mob->getNavigation()->isDone())
80 {
81 Vec3 *pos = RandomPos::getPos(dynamic_pointer_cast<PathfinderMob>(mob->shared_from_this()), 16, 3);
82 if (pos == NULL) return;
83 mob->getNavigation()->moveTo(pos->x, pos->y, pos->z, speedModifier);
84 }
85 }
86}