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.animal.h"
5#include "net.minecraft.world.level.h"
6#include "net.minecraft.world.phys.h"
7#include "BasicTypeContainers.h"
8#include "BreedGoal.h"
9#include "ExperienceOrb.h"
10
11#include "GenericStats.h"
12
13BreedGoal::BreedGoal(Animal *animal, double speedModifier)
14{
15 partner = weak_ptr<Animal>();
16 loveTime = 0;
17
18 this->animal = animal;
19 this->level = animal->level;
20 this->speedModifier = speedModifier;
21 setRequiredControlFlags(Control::MoveControlFlag | Control::LookControlFlag);
22}
23
24bool BreedGoal::canUse()
25{
26 if (!animal->isInLove()) return false;
27 partner = weak_ptr<Animal>(getFreePartner());
28 return partner.lock() != NULL;
29}
30
31bool BreedGoal::canContinueToUse()
32{
33 return partner.lock() != NULL && partner.lock()->isAlive() && partner.lock()->isInLove() && loveTime < 20 * 3;
34}
35
36void BreedGoal::stop()
37{
38 partner = weak_ptr<Animal>();
39 loveTime = 0;
40}
41
42void BreedGoal::tick()
43{
44 animal->getLookControl()->setLookAt(partner.lock(), 10, animal->getMaxHeadXRot());
45 animal->getNavigation()->moveTo(partner.lock(), speedModifier);
46 ++loveTime;
47 if (loveTime >= 20 * 3 && animal->distanceToSqr(partner.lock()) < 3*3) breed();
48}
49
50shared_ptr<Animal> BreedGoal::getFreePartner()
51{
52 float r = 8;
53 vector<shared_ptr<Entity> > *others = level->getEntitiesOfClass(typeid(*animal), animal->bb->grow(r, r, r));
54 double dist = Double::MAX_VALUE;
55 shared_ptr<Animal> partner = nullptr;
56 for(AUTO_VAR(it, others->begin()); it != others->end(); ++it)
57 {
58 shared_ptr<Animal> p = dynamic_pointer_cast<Animal>(*it);
59 if (animal->canMate(p) && animal->distanceToSqr(p) < dist)
60 {
61 partner = p;
62 dist = animal->distanceToSqr(p);
63 }
64 }
65 delete others;
66 return partner;
67}
68
69void BreedGoal::breed()
70{
71 shared_ptr<AgableMob> offspring = animal->getBreedOffspring(partner.lock());
72 animal->setDespawnProtected();
73 partner.lock()->setDespawnProtected();
74 if (offspring == NULL)
75 {
76 // This will be NULL if we've hit our limits for spawning any particular type of animal... reset things as normally as we can, without actually producing any offspring
77 animal->resetLove();
78 partner.lock()->resetLove();
79 return;
80 }
81
82 shared_ptr<Player> loveCause = animal->getLoveCause();
83 if (loveCause == NULL && partner.lock()->getLoveCause() != NULL)
84 {
85 loveCause = partner.lock()->getLoveCause();
86 }
87
88 if (loveCause != NULL)
89 {
90 // Record mob bred stat.
91 loveCause->awardStat(GenericStats::breedEntity(offspring->GetType()),GenericStats::param_breedEntity(offspring->GetType()));
92
93 if (animal->GetType() == eTYPE_COW)
94 {
95 //loveCause->awardStat(Achievements.breedCow);
96 }
97 }
98
99 animal->setAge(5 * 60 * 20);
100 partner.lock()->setAge(5 * 60 * 20);
101 animal->resetLove();
102 partner.lock()->resetLove();
103 offspring->setAge(AgableMob::BABY_START_AGE);
104 offspring->moveTo(animal->x, animal->y, animal->z, 0, 0);
105 offspring->setDespawnProtected();
106 level->addEntity(offspring);
107
108 Random *random = animal->getRandom();
109 for (int i = 0; i < 7; i++)
110 {
111 double xa = random->nextGaussian() * 0.02;
112 double ya = random->nextGaussian() * 0.02;
113 double za = random->nextGaussian() * 0.02;
114 level->addParticle(eParticleType_heart, animal->x + random->nextFloat() * animal->bbWidth * 2 - animal->bbWidth, animal->y + .5f + random->nextFloat() * animal->bbHeight, animal->z + random->nextFloat()
115 * animal->bbWidth * 2 - animal->bbWidth, xa, ya, za);
116 }
117 // 4J-PB - Fix for 106869- Customer Encountered: TU12: Content: Gameplay: Breeding animals does not give any Experience Orbs.
118 level->addEntity( shared_ptr<ExperienceOrb>( new ExperienceOrb(level, animal->x, animal->y, animal->z, random->nextInt(7) + 1) ) );
119}