the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 40 lines 1.1 kB view raw
1#include "stdafx.h" 2#include "net.minecraft.world.entity.ai.control.h" 3#include "net.minecraft.world.entity.h" 4#include "LeapAtTargetGoal.h" 5 6LeapAtTargetGoal::LeapAtTargetGoal(Mob *mob, float yd) 7{ 8 target = weak_ptr<LivingEntity>(); 9 10 this->mob = mob; 11 this->yd = yd; 12 setRequiredControlFlags(Control::JumpControlFlag | Control::MoveControlFlag); 13} 14 15bool LeapAtTargetGoal::canUse() 16{ 17 target = weak_ptr<LivingEntity>(mob->getTarget()); 18 if (target.lock() == NULL) return false; 19 double d = mob->distanceToSqr(target.lock()); 20 if (d < 2 * 2 || d > 4 * 4) return false; 21 if (!mob->onGround) return false; 22 if (mob->getRandom()->nextInt(5) != 0) return false; 23 return true; 24} 25 26bool LeapAtTargetGoal::canContinueToUse() 27{ 28 return target.lock() != NULL && !mob->onGround; 29} 30 31void LeapAtTargetGoal::start() 32{ 33 // TODO: move to control? 34 double xdd = target.lock()->x - mob->x; 35 double zdd = target.lock()->z - mob->z; 36 float dd = sqrt(xdd * xdd + zdd * zdd); 37 mob->xd += (xdd / dd * 0.5f) * 0.8f + mob->xd * 0.2f; 38 mob->zd += (zdd / dd * 0.5f) * 0.8f + mob->zd * 0.2f; 39 mob->yd = yd; 40}