the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 91 lines 2.4 kB view raw
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.player.h" 5#include "net.minecraft.world.entity.h" 6#include "net.minecraft.world.level.h" 7#include "TemptGoal.h" 8 9TemptGoal::TemptGoal(PathfinderMob *mob, double speedModifier, int itemId, bool canScare) 10{ 11 px = py = pz = pRotX = pRotY = 0.0; 12 player = weak_ptr<Player>(); 13 calmDown = 0; 14 _isRunning = false; 15 oldAvoidWater = false; 16 17 this->mob = mob; 18 this->speedModifier = speedModifier; 19 this->itemId = itemId; 20 this->canScare = canScare; 21 setRequiredControlFlags(Control::MoveControlFlag | Control::LookControlFlag); 22} 23 24bool TemptGoal::canUse() 25{ 26 if (calmDown > 0) 27 { 28 --calmDown; 29 return false; 30 } 31 player = weak_ptr<Player>(mob->level->getNearestPlayer(mob->shared_from_this(), 10)); 32 if (player.lock() == NULL) return false; 33 mob->setDespawnProtected(); // If we've got a nearby player, then consider this mob as something we'd miss if it despawned 34 shared_ptr<ItemInstance> item = player.lock()->getSelectedItem(); 35 if (item == NULL) return false; 36 if (item->id != itemId) return false; 37 return true; 38} 39 40bool TemptGoal::canContinueToUse() 41{ 42 if (canScare) 43 { 44 if(player.lock() == NULL) return false; 45 if (mob->distanceToSqr(player.lock()) < 6 * 6) 46 { 47 if (player.lock()->distanceToSqr(px, py, pz) > 0.1 * 0.1) return false; 48 if (abs(player.lock()->xRot - pRotX) > 5 || abs(player.lock()->yRot - pRotY) > 5) return false; 49 } 50 else 51 { 52 px = player.lock()->x; 53 py = player.lock()->y; 54 pz = player.lock()->z; 55 } 56 pRotX = player.lock()->xRot; 57 pRotY = player.lock()->yRot; 58 } 59 return canUse(); 60} 61 62void TemptGoal::start() 63{ 64 px = player.lock()->x; 65 py = player.lock()->y; 66 pz = player.lock()->z; 67 _isRunning = true; 68 oldAvoidWater = mob->getNavigation()->getAvoidWater(); 69 mob->getNavigation()->setAvoidWater(false); 70} 71 72void TemptGoal::stop() 73{ 74 player = weak_ptr<Player>(); 75 mob->getNavigation()->stop(); 76 calmDown = 100; 77 _isRunning = false; 78 mob->getNavigation()->setAvoidWater(oldAvoidWater); 79} 80 81void TemptGoal::tick() 82{ 83 mob->getLookControl()->setLookAt(player.lock(), 30, mob->getMaxHeadXRot()); 84 if (mob->distanceToSqr(player.lock()) < 2.5 * 2.5) mob->getNavigation()->stop(); 85 else mob->getNavigation()->moveTo(player.lock(), speedModifier); 86} 87 88bool TemptGoal::isRunning() 89{ 90 return _isRunning; 91}