diff options
| author | daoge_cmd <3523206925@qq.com> | 2026-03-01 12:16:08 +0800 |
|---|---|---|
| committer | daoge_cmd <3523206925@qq.com> | 2026-03-01 12:16:08 +0800 |
| commit | b691c43c44ff180d10e7d4a9afc83b98551ff586 (patch) | |
| tree | 3e9849222cbc6ba49f2f1fc6e5fe7179632c7390 /Minecraft.World/LeapAtTargetGoal.cpp | |
| parent | def8cb415354ac390b7e89052a50605285f1aca9 (diff) | |
Initial commit
Diffstat (limited to 'Minecraft.World/LeapAtTargetGoal.cpp')
| -rw-r--r-- | Minecraft.World/LeapAtTargetGoal.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/Minecraft.World/LeapAtTargetGoal.cpp b/Minecraft.World/LeapAtTargetGoal.cpp new file mode 100644 index 00000000..ea4a1c0e --- /dev/null +++ b/Minecraft.World/LeapAtTargetGoal.cpp @@ -0,0 +1,40 @@ +#include "stdafx.h" +#include "net.minecraft.world.entity.ai.control.h" +#include "net.minecraft.world.entity.h" +#include "LeapAtTargetGoal.h" + +LeapAtTargetGoal::LeapAtTargetGoal(Mob *mob, float yd) +{ + target = weak_ptr<Mob>(); + + this->mob = mob; + this->yd = yd; + setRequiredControlFlags(Control::JumpControlFlag | Control::MoveControlFlag); +} + +bool LeapAtTargetGoal::canUse() +{ + target = weak_ptr<Mob>(mob->getTarget()); + if (target.lock() == NULL) return false; + double d = mob->distanceToSqr(target.lock()); + if (d < 2 * 2 || d > 4 * 4) return false; + if (!mob->onGround) return false; + if (mob->getRandom()->nextInt(5) != 0) return false; + return true; +} + +bool LeapAtTargetGoal::canContinueToUse() +{ + return target.lock() != NULL && !mob->onGround; +} + +void LeapAtTargetGoal::start() +{ + // TODO: move to control? + double xdd = target.lock()->x - mob->x; + double zdd = target.lock()->z - mob->z; + float dd = sqrt(xdd * xdd + zdd * zdd); + mob->xd += (xdd / dd * 0.5f) * 0.8f + mob->xd * 0.2f; + mob->zd += (zdd / dd * 0.5f) * 0.8f + mob->zd * 0.2f; + mob->yd = yd; +}
\ No newline at end of file |
