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/SitGoal.cpp | |
| parent | def8cb415354ac390b7e89052a50605285f1aca9 (diff) | |
Initial commit
Diffstat (limited to 'Minecraft.World/SitGoal.cpp')
| -rw-r--r-- | Minecraft.World/SitGoal.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/Minecraft.World/SitGoal.cpp b/Minecraft.World/SitGoal.cpp new file mode 100644 index 00000000..90180201 --- /dev/null +++ b/Minecraft.World/SitGoal.cpp @@ -0,0 +1,45 @@ +#include "stdafx.h" +#include "net.minecraft.world.entity.ai.control.h" +#include "net.minecraft.world.entity.ai.goal.h" +#include "net.minecraft.world.entity.ai.navigation.h" +#include "net.minecraft.world.entity.h" +#include "net.minecraft.world.entity.animal.h" +#include "SitGoal.h" + +SitGoal::SitGoal(TamableAnimal *mob) +{ + _wantToSit = false; + + this->mob = mob; + setRequiredControlFlags(Control::JumpControlFlag | Control::MoveControlFlag); +} + +bool SitGoal::canUse() +{ + if (!mob->isTame()) return false; + if (mob->isInWater()) return false; + if (!mob->onGround) return false; + + shared_ptr<Mob> owner = mob->getOwner(); + if (owner == NULL) return true; // owner not on level + + if (mob->distanceToSqr(owner) < FollowOwnerGoal::TeleportDistance * FollowOwnerGoal::TeleportDistance && owner->getLastHurtByMob() != NULL) return false; + + return _wantToSit; +} + +void SitGoal::start() +{ + mob->getNavigation()->stop(); + mob->setSitting(true); +} + +void SitGoal::stop() +{ + mob->setSitting(false); +} + +void SitGoal::wantToSit(bool _wantToSit) +{ + this->_wantToSit = _wantToSit; +}
\ No newline at end of file |
