the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 65 lines 1.7 kB view raw
1#include "stdafx.h" 2#include "net.minecraft.world.entity.animal.h" 3#include "net.minecraft.world.entity.ai.navigation.h" 4#include "net.minecraft.world.level.h" 5#include "net.minecraft.world.phys.h" 6#include "BasicTypeContainers.h" 7#include "FollowParentGoal.h" 8 9FollowParentGoal::FollowParentGoal(Animal *animal, double speedModifier) 10{ 11 timeToRecalcPath = 0; 12 13 this->animal = animal; 14 this->speedModifier = speedModifier; 15} 16 17bool FollowParentGoal::canUse() 18{ 19 if (animal->getAge() >= 0) return false; 20 21 vector<shared_ptr<Entity> > *parents = animal->level->getEntitiesOfClass(typeid(*animal), animal->bb->grow(8, 4, 8)); 22 23 shared_ptr<Animal> closest = nullptr; 24 double closestDistSqr = Double::MAX_VALUE; 25 for(AUTO_VAR(it, parents->begin()); it != parents->end(); ++it) 26 { 27 shared_ptr<Animal> parent = dynamic_pointer_cast<Animal>(*it); 28 if (parent->getAge() < 0) continue; 29 double distSqr = animal->distanceToSqr(parent); 30 if (distSqr > closestDistSqr) continue; 31 closestDistSqr = distSqr; 32 closest = parent; 33 } 34 delete parents; 35 36 if (closest == NULL) return false; 37 if (closestDistSqr < 3 * 3) return false; 38 parent = weak_ptr<Animal>(closest); 39 return true; 40} 41 42bool FollowParentGoal::canContinueToUse() 43{ 44 if (parent.lock() == NULL || !parent.lock()->isAlive()) return false; 45 double distSqr = animal->distanceToSqr(parent.lock()); 46 if (distSqr < 3 * 3 || distSqr > 16 * 16) return false; 47 return true; 48} 49 50void FollowParentGoal::start() 51{ 52 timeToRecalcPath = 0; 53} 54 55void FollowParentGoal::stop() 56{ 57 parent = weak_ptr<Animal>(); 58} 59 60void FollowParentGoal::tick() 61{ 62 if (--timeToRecalcPath > 0) return; 63 timeToRecalcPath = 10; 64 animal->getNavigation()->moveTo(parent.lock(), speedModifier); 65}