Files
MinecraftConsoles/Minecraft.World/FollowParentGoal.cpp
daoge b3feddfef3 feat: TU19 (Dec 2014) Features & Content (#155)
* try to resolve merge conflict

* feat: TU19 (Dec 2014) Features & Content (#32)

* December 2014 files

* Working release build

* Fix compilation issues

* Add sound to Windows64Media

* Add DLC content and force Tutorial DLC

* Revert "Add DLC content and force Tutorial DLC"

This reverts commit 97a4399472.

* Disable broken light packing

* Disable breakpoint during DLC texture map load

Allows DLC loading but the DLC textures are still broken

* Fix post build not working

* ...

* fix vs2022 build

* fix cmake build

---------

Co-authored-by: Loki <lokirautio@gmail.com>
2026-03-03 03:04:10 +08:00

65 lines
1.7 KiB
C++

#include "stdafx.h"
#include "net.minecraft.world.entity.animal.h"
#include "net.minecraft.world.entity.ai.navigation.h"
#include "net.minecraft.world.level.h"
#include "net.minecraft.world.phys.h"
#include "BasicTypeContainers.h"
#include "FollowParentGoal.h"
FollowParentGoal::FollowParentGoal(Animal *animal, double speedModifier)
{
timeToRecalcPath = 0;
this->animal = animal;
this->speedModifier = speedModifier;
}
bool FollowParentGoal::canUse()
{
if (animal->getAge() >= 0) return false;
vector<shared_ptr<Entity> > *parents = animal->level->getEntitiesOfClass(typeid(*animal), animal->bb->grow(8, 4, 8));
shared_ptr<Animal> closest = nullptr;
double closestDistSqr = Double::MAX_VALUE;
for(AUTO_VAR(it, parents->begin()); it != parents->end(); ++it)
{
shared_ptr<Animal> parent = dynamic_pointer_cast<Animal>(*it);
if (parent->getAge() < 0) continue;
double distSqr = animal->distanceToSqr(parent);
if (distSqr > closestDistSqr) continue;
closestDistSqr = distSqr;
closest = parent;
}
delete parents;
if (closest == NULL) return false;
if (closestDistSqr < 3 * 3) return false;
parent = weak_ptr<Animal>(closest);
return true;
}
bool FollowParentGoal::canContinueToUse()
{
if (parent.lock() == NULL || !parent.lock()->isAlive()) return false;
double distSqr = animal->distanceToSqr(parent.lock());
if (distSqr < 3 * 3 || distSqr > 16 * 16) return false;
return true;
}
void FollowParentGoal::start()
{
timeToRecalcPath = 0;
}
void FollowParentGoal::stop()
{
parent = weak_ptr<Animal>();
}
void FollowParentGoal::tick()
{
if (--timeToRecalcPath > 0) return;
timeToRecalcPath = 10;
animal->getNavigation()->moveTo(parent.lock(), speedModifier);
}